apexsankey 1.1.3 → 1.2.1
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 +82 -75
- package/apexsankey.es.min.js +3952 -19459
- package/apexsankey.min.js +2 -10
- package/demo/basic-sankey.html +3 -2
- package/demo/sankey-alternate-node.html +48 -47
- package/demo/sankey-custom-fonts.html +3 -2
- package/demo/sankey-edge-options.html +3 -2
- package/demo/sankey-node-customization.html +3 -2
- package/demo/sankey-node-overlapping.html +241 -240
- package/lib/layout/rankAssignment/makeAcyclic.d.ts +1 -1
- package/lib/models/Options.d.ts +1 -1
- package/lib/models/Paper.d.ts +1 -1
- package/package.json +10 -7
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
|
|
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,28 @@ 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
|
|
48
|
-
|
|
49
|
-
width
|
|
50
|
-
height
|
|
51
|
-
canvasStyle
|
|
52
|
-
spacing
|
|
53
|
-
nodeWidth
|
|
54
|
-
nodeBorderWidth
|
|
55
|
-
nodeBorderColor
|
|
56
|
-
onNodeClick
|
|
57
|
-
edgeOpacity
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
| edgeGradientFill | true | Enable gradient fill based on source and target node colors. |
|
|
66
|
+
| enableTooltip | false | Enable tooltip on hover of nodes |
|
|
67
|
+
| enableToolbar | false | Enable/disable graph toolbar
|
|
68
|
+
| tooltipId | `sankey-tooltip-container` | The tooltip HTML element id |
|
|
69
|
+
| tooltipTemplate | tooltipTemplate | The HTML template for tooltip |
|
|
70
|
+
| tooltipBorderColor | `#BCBCBC` | The border color of tooltip |
|
|
71
|
+
| tooltipBGColor | `#FFFFFF` | The background color of tooltip |
|
|
72
|
+
| fontSize | `14px` | The size of font of nodes |
|
|
73
|
+
| fontFamily | None | The font family of nodes |
|
|
74
|
+
| fontWeight | 400 | The font weight of nodes |
|
|
75
|
+
| fontColor | `#000000` | The font color of nodes |
|
|
67
76
|
|
|
68
77
|
Default tooltip template
|
|
69
78
|
|
|
@@ -76,7 +85,7 @@ const tooltipTemplate = ({source, target, value}) => {
|
|
|
76
85
|
<div>=></div>
|
|
77
86
|
<div style='width:12px;height:12px;background-color:${target.color}'></div>
|
|
78
87
|
<div>${target.title}</div>
|
|
79
|
-
<div>: ${value}</div>
|
|
88
|
+
<div>: ${value}</div>
|
|
80
89
|
</div>
|
|
81
90
|
`;
|
|
82
91
|
},
|
|
@@ -86,82 +95,80 @@ const tooltipTemplate = ({source, target, value}) => {
|
|
|
86
95
|
|
|
87
96
|
Passed data should be an object containing nodes, edges and options. Nodes, edges and options should be in below format.
|
|
88
97
|
|
|
89
|
-
-
|
|
98
|
+
- _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
99
|
|
|
91
100
|
```json
|
|
92
101
|
{
|
|
93
|
-
"id": "1",
|
|
94
|
-
"title": "A"
|
|
95
|
-
|
|
102
|
+
"id": "1", // required
|
|
103
|
+
"title": "A" // required
|
|
96
104
|
}
|
|
97
105
|
```
|
|
98
106
|
|
|
99
|
-
-
|
|
107
|
+
- _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
108
|
|
|
101
109
|
```json
|
|
102
110
|
{
|
|
103
|
-
"source": "a", // required
|
|
111
|
+
"source": "a", // required
|
|
104
112
|
"target": "b", // required
|
|
105
113
|
"value": 1, // required
|
|
106
114
|
"type": "x", // optional
|
|
107
115
|
},
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
-
|
|
118
|
+
- _options_ : ApexSankey supports two options order and alightLinkTypes.
|
|
111
119
|
|
|
112
|
-
|
|
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.
|
|
120
|
+
- _order_: optional list of layers
|
|
115
121
|
|
|
116
|
-
|
|
117
|
-
For example,
|
|
122
|
+
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
123
|
|
|
119
|
-
|
|
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.
|
|
124
|
+
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.
|
|
125
|
+
For example,
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
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": {
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
161
129
|
"order": [
|
|
162
130
|
[["a", "b"]],
|
|
163
131
|
[["c"]],
|
|
164
132
|
],
|
|
165
133
|
},
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- _alignLinkTypes_: boolean (default false). Whether to align link types across nodes, or order links to minimise crossings.
|
|
137
|
+
|
|
138
|
+
**Example**
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
const data = {
|
|
142
|
+
nodes: [
|
|
143
|
+
{
|
|
144
|
+
id: "a",
|
|
145
|
+
title: "AAA",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "b",
|
|
149
|
+
title: "BBB",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
id: "c",
|
|
153
|
+
title: "CCC",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
edges: [
|
|
157
|
+
{
|
|
158
|
+
source: "a",
|
|
159
|
+
target: "c",
|
|
160
|
+
value: 1,
|
|
161
|
+
type: "A",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
source: "b",
|
|
165
|
+
target: "c",
|
|
166
|
+
value: 2,
|
|
167
|
+
type: "A",
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
options: {
|
|
171
|
+
order: [[["a", "b"]], [["c"]]],
|
|
172
|
+
},
|
|
166
173
|
};
|
|
167
174
|
```
|