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 +80 -75
- package/apexsankey.es.min.js +6101 -15848
- package/apexsankey.min.js +1 -9
- package/demo/basic-sankey.html +40 -29
- package/demo/sankey-alternate-node.html +102 -0
- package/demo/sankey-custom-fonts.html +4 -3
- package/demo/sankey-edge-options.html +4 -3
- package/demo/sankey-node-customization.html +5 -4
- package/demo/sankey-node-overlapping.html +428 -0
- package/lib/layout/edgePositioning/linkLayout.d.ts +1 -5
- package/lib/layout/edgePositioning/utils.d.ts +1 -0
- package/lib/layout/layout.d.ts +12 -17
- package/lib/layout/nodeOrdering/addDummyNodes.d.ts +1 -0
- package/lib/layout/nodeOrdering/index.d.ts +1 -1
- package/lib/layout/nodePositioning/justified.d.ts +2 -2
- package/lib/layout/rankAssignment/groupedGraph.d.ts +1 -0
- package/lib/layout/rankAssignment/makeAcyclic.d.ts +2 -1
- package/lib/layout/utils.d.ts +1 -0
- package/lib/models/Edge.d.ts +2 -1
- package/lib/models/Graph.d.ts +9 -10
- package/lib/models/Node.d.ts +3 -2
- package/lib/models/Options.d.ts +15 -12
- package/lib/models/Paper.d.ts +10 -6
- package/lib/sankey.d.ts +4 -3
- package/package.json +13 -6
- package/lib/models/GraphUtils.d.ts +0 -5
- package/lib/models/svgUtils.d.ts +0 -37
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,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
|
|
48
|
-
|
|
49
|
-
width
|
|
50
|
-
height
|
|
51
|
-
canvasStyle
|
|
52
|
-
spacing
|
|
53
|
-
nodeWidth
|
|
54
|
-
nodeBorderWidth
|
|
55
|
-
nodeBorderColor
|
|
56
|
-
onNodeClick
|
|
57
|
-
edgeOpacity
|
|
58
|
-
enableTooltip
|
|
59
|
-
tooltipId
|
|
60
|
-
tooltipTemplate
|
|
61
|
-
tooltipBorderColor | `#BCBCBC`
|
|
62
|
-
tooltipBGColor
|
|
63
|
-
fontSize
|
|
64
|
-
fontFamily
|
|
65
|
-
fontWeight
|
|
66
|
-
fontColor
|
|
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
|
-
-
|
|
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",
|
|
94
|
-
"title": "A"
|
|
95
|
-
|
|
100
|
+
"id": "1", // required
|
|
101
|
+
"title": "A" // required
|
|
96
102
|
}
|
|
97
103
|
```
|
|
98
104
|
|
|
99
|
-
-
|
|
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
|
-
-
|
|
116
|
+
- _options_ : ApexSankey supports two options order and alightLinkTypes.
|
|
111
117
|
|
|
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.
|
|
118
|
+
- _order_: optional list of layers
|
|
115
119
|
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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": {
|
|
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
|
```
|