apexsankey 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,13 @@ A JavaScript library to create Sankey diagrams built on SVG
4
4
 
5
5
  <img width="752" alt="apex-sankey-chart" src="https://github.com/apexcharts/projects/assets/17950663/51e00ff0-79d1-45eb-8815-f8d11e2dd981">
6
6
 
7
+ ## Dependency
8
+
9
+ Include svg.js
10
+
11
+ ```bash
12
+ <script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js"></script>
13
+ ```
7
14
 
8
15
  ## Installation
9
16
 
@@ -16,7 +23,7 @@ npm install apexsankey
16
23
  ## Usage
17
24
 
18
25
  ```js
19
- import ApexSankey from 'apexsankey';
26
+ import ApexSankey from "apexsankey";
20
27
  ```
21
28
 
22
29
  To create a basic sankey with minimal configuration, write as follows:
@@ -44,26 +51,26 @@ To create a basic sankey with minimal configuration, write as follows:
44
51
 
45
52
  The layout can be configured by either setting the properties in the table below by passing a second arg to ApexSankey with these properties set. The latter takes precedence.
46
53
 
47
- Options | Default | Description
48
- --- |------------------------------| ---
49
- width | 800 | The width of graph container
50
- height | 800 | The height of graph container
51
- canvasStyle | None | The css styles for canvas root container
52
- spacing | 100 | The spacing from top and left of graph container
53
- nodeWidth | 20 | The width of graph nodes
54
- nodeBorderWidth | 1 | The border width of the nodes in pixels
55
- nodeBorderColor | none | The border color of the nodes
56
- onNodeClick | empty function | The callback function for node click. Node object will be parameter for callback.
57
- edgeOpacity | 0.4 | The opacity value for edges. Values must be between 0 to 1 and in fraction.
58
- enableTooltip | false | Enable tooltip on hover of nodes
59
- tooltipId | `sankey-tooltip-container` | The tooltip HTML element id
60
- tooltipTemplate | tooltipTemplate | The HTML template for tooltip
61
- tooltipBorderColor | `#BCBCBC` | The border color of tooltip
62
- tooltipBGColor | `#FFFFFF` | The background color of tooltip
63
- fontSize | `14px` | The size of font of nodes
64
- fontFamily | None | The font family of nodes
65
- fontWeight | 400 | The font weight of nodes
66
- fontColor | `#000000` | The font color of nodes
54
+ | Options | Default | Description |
55
+ | ------------------ | -------------------------- | --------------------------------------------------------------------------------- |
56
+ | width | 800 | The width of graph container |
57
+ | height | 800 | The height of graph container |
58
+ | canvasStyle | None | The css styles for canvas root container |
59
+ | spacing | 100 | The spacing from top and left of graph container |
60
+ | nodeWidth | 20 | The width of graph nodes |
61
+ | nodeBorderWidth | 1 | The border width of the nodes in pixels |
62
+ | nodeBorderColor | none | The border color of the nodes |
63
+ | onNodeClick | empty function | The callback function for node click. Node object will be parameter for callback. |
64
+ | edgeOpacity | 0.4 | The opacity value for edges. Values must be between 0 to 1 and in fraction. |
65
+ | enableTooltip | false | Enable tooltip on hover of nodes |
66
+ | tooltipId | `sankey-tooltip-container` | The tooltip HTML element id |
67
+ | tooltipTemplate | tooltipTemplate | The HTML template for tooltip |
68
+ | tooltipBorderColor | `#BCBCBC` | The border color of tooltip |
69
+ | tooltipBGColor | `#FFFFFF` | The background color of tooltip |
70
+ | fontSize | `14px` | The size of font of nodes |
71
+ | fontFamily | None | The font family of nodes |
72
+ | fontWeight | 400 | The font weight of nodes |
73
+ | fontColor | `#000000` | The font color of nodes |
67
74
 
68
75
  Default tooltip template
69
76
 
@@ -76,7 +83,7 @@ const tooltipTemplate = ({source, target, value}) => {
76
83
  <div>=></div>
77
84
  <div style='width:12px;height:12px;background-color:${target.color}'></div>
78
85
  <div>${target.title}</div>
79
- <div>: ${value}</div>
86
+ <div>: ${value}</div>
80
87
  </div>
81
88
  `;
82
89
  },
@@ -86,82 +93,80 @@ const tooltipTemplate = ({source, target, value}) => {
86
93
 
87
94
  Passed data should be an object containing nodes, edges and options. Nodes, edges and options should be in below format.
88
95
 
89
- - *nodes* : Passed node object should contain id and title. *Id* is for uniquely identifying nodes and *title* is for node titles. It will be also used for showing tooltips for node-to-node connections.
96
+ - _nodes_ : Passed node object should contain id and title. _Id_ is for uniquely identifying nodes and _title_ is for node titles. It will be also used for showing tooltips for node-to-node connections.
90
97
 
91
98
  ```json
92
99
  {
93
- "id": "1", // required
94
- "title": "A", // required
95
-
100
+ "id": "1", // required
101
+ "title": "A" // required
96
102
  }
97
103
  ```
98
104
 
99
- - *edges* : Passed edge object should contain source, target, value and type. *source* is id value of source node for edge, *target* is id value of target node for edge, *value* indicates edge size and *type* is for grouping nodes.
105
+ - _edges_ : Passed edge object should contain source, target, value and type. _source_ is id value of source node for edge, _target_ is id value of target node for edge, _value_ indicates edge size and _type_ is for grouping nodes.
100
106
 
101
107
  ```json
102
108
  {
103
- "source": "a", // required
109
+ "source": "a", // required
104
110
  "target": "b", // required
105
111
  "value": 1, // required
106
112
  "type": "x", // optional
107
113
  },
108
114
  ```
109
115
 
110
- - *options* : ApexSankey supports two options order and alightLinkTypes.
116
+ - _options_ : ApexSankey supports two options order and alightLinkTypes.
111
117
 
112
- - *order*: optional list of layers
113
-
114
- If order is not specified, the nodes are automatically assigned to layers. If order is specified, it is used directly and no rank assignment or ordering algorithm takes place.
118
+ - _order_: optional list of layers
115
119
 
116
- The order structure has three nested lists: order is a list of layers, each of which is a list of bands, each of which is a list of node ids.
117
- For example,
120
+ If order is not specified, the nodes are automatically assigned to layers. If order is specified, it is used directly and no rank assignment or ordering algorithm takes place.
118
121
 
119
- ```json
120
- {
121
- "order": [
122
- [["a", "b"]],
123
- [["c"]],
124
- ],
125
- },
126
- ```
127
- - *alignLinkTypes*: boolean (default false). Whether to align link types across nodes, or order links to minimise crossings.
122
+ The order structure has three nested lists: order is a list of layers, each of which is a list of bands, each of which is a list of node ids.
123
+ For example,
128
124
 
129
- **Example**
130
- ```js
131
- const data = {
132
- "nodes": [
133
- {
134
- "id": "a",
135
- "title": "AAA",
136
- },
137
- {
138
- "id": "b",
139
- "title": "BBB",
140
- },
141
- {
142
- "id": "c",
143
- "title": "CCC",
144
- },
145
- ],
146
- "edges": [
147
- {
148
- "source": "a",
149
- "target": "c",
150
- "value": 1,
151
- "type": "A",
152
- },
153
- {
154
- "source": "b",
155
- "target": "c",
156
- "value": 2,
157
- "type": "A",
158
- }
159
- ],
160
- "options": {
125
+ ```json
126
+ {
161
127
  "order": [
162
128
  [["a", "b"]],
163
129
  [["c"]],
164
130
  ],
165
131
  },
132
+ ```
133
+
134
+ - _alignLinkTypes_: boolean (default false). Whether to align link types across nodes, or order links to minimise crossings.
135
+
136
+ **Example**
137
+
138
+ ```js
139
+ const data = {
140
+ nodes: [
141
+ {
142
+ id: "a",
143
+ title: "AAA",
144
+ },
145
+ {
146
+ id: "b",
147
+ title: "BBB",
148
+ },
149
+ {
150
+ id: "c",
151
+ title: "CCC",
152
+ },
153
+ ],
154
+ edges: [
155
+ {
156
+ source: "a",
157
+ target: "c",
158
+ value: 1,
159
+ type: "A",
160
+ },
161
+ {
162
+ source: "b",
163
+ target: "c",
164
+ value: 2,
165
+ type: "A",
166
+ },
167
+ ],
168
+ options: {
169
+ order: [[["a", "b"]], [["c"]]],
170
+ },
166
171
  };
167
172
  ```