apexsankey 1.0.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 +167 -0
- package/apexsankey.es.min.js +17000 -0
- package/apexsankey.min.js +9 -0
- package/demo/demo.html +93 -0
- package/demo/demo2.html +165 -0
- package/demo/demo3.html +82 -0
- package/index.d.ts +1 -0
- package/lib/layout/edgeOrdering/index.d.ts +1 -0
- package/lib/layout/edgeOrdering/linkDirection.d.ts +1 -0
- package/lib/layout/edgeOrdering/linkTypeOrder.d.ts +1 -0
- package/lib/layout/edgeOrdering/orderEdges.d.ts +13 -0
- package/lib/layout/edgePositioning/index.d.ts +1 -0
- package/lib/layout/edgePositioning/linkLayout.d.ts +7 -0
- package/lib/layout/edgePositioning/utils.d.ts +7 -0
- package/lib/layout/layout.d.ts +49 -0
- package/lib/layout/nodeOrdering/addDummyNodes.d.ts +1 -0
- package/lib/layout/nodeOrdering/countCrossings.d.ts +30 -0
- package/lib/layout/nodeOrdering/index.d.ts +2 -0
- package/lib/layout/nodeOrdering/initialOrdering.d.ts +1 -0
- package/lib/layout/nodeOrdering/ordering.d.ts +11 -0
- package/lib/layout/nodeOrdering/swapNodes.d.ts +1 -0
- package/lib/layout/nodeOrdering/weightedMedian.d.ts +7 -0
- package/lib/layout/nodePositioning/horizontal.d.ts +2 -0
- package/lib/layout/nodePositioning/index.d.ts +2 -0
- package/lib/layout/nodePositioning/justified.d.ts +15 -0
- package/lib/layout/rankAssignment/assignRanks.d.ts +4 -0
- package/lib/layout/rankAssignment/groupedGraph.d.ts +9 -0
- package/lib/layout/rankAssignment/index.d.ts +1 -0
- package/lib/layout/rankAssignment/initialRank.d.ts +4 -0
- package/lib/layout/rankAssignment/makeAcyclic.d.ts +11 -0
- package/lib/layout/utils.d.ts +2 -0
- package/lib/models/ColorPalette.d.ts +1 -0
- package/lib/models/Edge.d.ts +1 -0
- package/lib/models/Graph.d.ts +34 -0
- package/lib/models/GraphUtils.d.ts +5 -0
- package/lib/models/Node.d.ts +3 -0
- package/lib/models/Options.d.ts +30 -0
- package/lib/models/Paper.d.ts +13 -0
- package/lib/models/svgUtils.d.ts +36 -0
- package/lib/sankey.d.ts +9 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# ApexSankey - Installation and Getting started
|
|
2
|
+
|
|
3
|
+
The ApexSankey is a javascript library built on SVG that helps to create organizational or hierarchical charts.
|
|
4
|
+
|
|
5
|
+
<img width="811" alt="Screenshot 2023-12-17 at 10 28 04 PM" src="https://github.com/apexcharts/tree/assets/17950663/e09212ec-6322-4c68-ac12-9afc524d2abd">
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
To add the ApexSankey to your project and its dependencies, install the package from npm.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install apexsankey
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import ApexSankey from 'apexsankey';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
To create a basic sankey with minimal configuration, write as follows:
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<div id="sankey-container"></div>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
const data = {
|
|
30
|
+
...(data with format provided below)
|
|
31
|
+
}
|
|
32
|
+
const options = {
|
|
33
|
+
width: 800,
|
|
34
|
+
height: 800,
|
|
35
|
+
canvasStyle: 'border: 1px solid #caced0; background: #f6f6f6;',
|
|
36
|
+
spacing: 100,
|
|
37
|
+
nodeWidth: 20,
|
|
38
|
+
};
|
|
39
|
+
const sankey = new ApexSankey(document.getElementById('sankey-container'), options);
|
|
40
|
+
const graph = sankey.render(data);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ApexSankey Options
|
|
44
|
+
|
|
45
|
+
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
|
+
|
|
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
|
|
67
|
+
|
|
68
|
+
Default tooltip template
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
const tooltipTemplate = ({source, target, value}) => {
|
|
72
|
+
return `
|
|
73
|
+
<div style='display:flex;align-items:center;gap:5px;'>
|
|
74
|
+
<div style='width:12px;height:12px;background-color:${source.color}'></div>
|
|
75
|
+
<div>${source.title}</div>
|
|
76
|
+
<div>=></div>
|
|
77
|
+
<div style='width:12px;height:12px;background-color:${target.color}'></div>
|
|
78
|
+
<div>${target.title}</div>
|
|
79
|
+
<div>: ${value}</div>
|
|
80
|
+
</div>
|
|
81
|
+
`;
|
|
82
|
+
},
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Expected data format
|
|
86
|
+
|
|
87
|
+
Passed data should be an object containing nodes, edges and options. Nodes, edges and options should be in below format.
|
|
88
|
+
|
|
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.
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"id": "1", // required
|
|
94
|
+
"title": "A", // required
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
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.
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"source": "a", // required
|
|
104
|
+
"target": "b", // required
|
|
105
|
+
"value": 1, // required
|
|
106
|
+
"type": "x", // optional
|
|
107
|
+
},
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- *options* : ApexSankey supports two options order and alightLinkTypes.
|
|
111
|
+
|
|
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.
|
|
115
|
+
|
|
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,
|
|
118
|
+
|
|
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.
|
|
128
|
+
|
|
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": {
|
|
161
|
+
"order": [
|
|
162
|
+
[["a", "b"]],
|
|
163
|
+
[["c"]],
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
```
|