1.1.2 • Published 1 year ago

diagrama-react v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Getting Started

Installation

To install and set up the library, run:

$ npm install diagrama-react

Usage

Importing

Import diagram component with

$ import { Diagram } from "diagrama-react"

Params

A two-dimensional Array. Every array on it represents a column

NameTypeDescription
dataArray Matrix of Nodes
arrowsArray Array of Arrows

Param values

Node

Node object represent every single cell on the diagram.

NameTypeDescription
idstringIdentificator of the node. must be unique
valuestringValue that represents the node (Optional)
labelstringLabel asociated to the node (Optional)
descriptionstringDescription asociated to the node (Optional)
routeArray Array of id's that will be highlighted on hover. If not provided, hover will map every related node (Optional)
iconimageImage that will be displayed as node cover
type'0', '1', '2', '3', '4', '5'Type of node (If type is provided, icon is not displayed) (Optional)
actionsArray Array of Actions

Note: <0, >5, null, undefined or NaN values will display icon (if provided) or id`

Example:

const data = [
    //First column
    [
    { id: "11",
      value: "1",
      label: "John Q. Public",
      description: "john@mail.com",
      type: 0,
      route: ["21", "31", "33"],
      actions = [
        ...actions
      ]
    },
    { id: "12",
      value: "2",
      label: "Jane Doe",
      description: "jane@mail.com",
      type: 0,
      route: ["21", "32"],
      actions = [
        ...actions
      ]
    },
    { id: "13",
      value: "3",
      label: "Petter B. P.",
      description: "petter@mail.com",
      type: 0,
      route: ["21", "31", "32"],
      actions = [
        ...actions
      ]
    },
  ],
  //Second column
  [
    {
      id: "21",
      value: "1",
      label: "Awesome Company",
      type: 1,
      actions: [
        ...actions
      ]
    },
  ]//Third Column
    [
    { id: "31",
      value: "1",
      label: "H.R.",
      description: "5th Floor",
      actions: [
        ...actions
      ]
    },
    { id: "32",
      value: "2",
      label: "I.T.",
      description: "6th Floor",
      actions: [
        ...actions
      ]
    },
    { id: "33",
      value: "3",
      label: "Sales",
      description: "2ndFloor",
      actions: [
        ...actions
      ]
    },
  ],
]

Arrows

Arrow object represent every single relation on the diagram.

NameTypeDescription
startIDstringIdentificator of the node at the left.
endIDstringIdentificator of the node at the left.

Example:

const arrows = [
    {startID: "11", endID: "21"},
    {startID: "12", endID: "21"},
    {startID: "13", endID: "21"},
    {startID: "21", endID: "31"},
    {startID: "21", endID: "32"},
    {startID: "21", endID: "33"},
]

Actions

Actions that will be displayed on node click. returns an <HTMLDivElement>

NameTypeDescription
idstringIdentificator of the action. must be unique
labelstringLabel that will be shown on dropdown menu
onClickReact.MouseEventHandlerAction that will be executed.

Example:

const action = (e: any) => {
  console.log("Action for", e.target.id, "option");
};

const actions = [
  { id: "print-action", label: "More details", onClick: action },
  { id: "print-action-2", label: "Another print details", onClick: action, }
];
1.1.1

1 year ago

1.1.0

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago