chartjs-chart-sankey 0.14.0 → 0.14.2
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/LICENSE +1 -1
- package/README.md +21 -0
- package/dist/{chartjs-chart-sankey.js → chartjs-chart-sankey.cjs} +85 -81
- package/dist/chartjs-chart-sankey.esm.js +78 -77
- package/dist/chartjs-chart-sankey.min.js +4 -4
- package/dist/controller.d.ts +119 -0
- package/dist/flow.d.ts +65 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.d.ts +3 -0
- package/dist/lib/core.d.ts +4 -0
- package/dist/lib/helpers.d.ts +3 -0
- package/dist/lib/layout.d.ts +34 -0
- package/dist/types.d.ts +102 -0
- package/package.json +68 -57
- package/types/index.esm.d.ts +0 -148
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -36,6 +36,27 @@ import {SankeyController, Flow} from 'chartjs-chart-sankey';
|
|
|
36
36
|
Chart.register(SankeyController, Flow);
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
For script tag usage, load the browser bundle after Chart.js. The browser bundle registers the sankey controller
|
|
40
|
+
and flow element automatically.
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-chart-sankey"></script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The same bundle can be loaded from UNPKG:
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script src="https://unpkg.com/chart.js"></script>
|
|
51
|
+
<script src="https://unpkg.com/chartjs-chart-sankey"></script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
If a CDN does not use the package metadata for its default file, reference the browser bundle directly:
|
|
55
|
+
|
|
56
|
+
```html
|
|
57
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-chart-sankey/dist/chartjs-chart-sankey.min.js"></script>
|
|
58
|
+
```
|
|
59
|
+
|
|
39
60
|
To create a sankey chart, include chartjs-chart-sankey.js after chart.js and then create the chart by setting the `type`
|
|
40
61
|
attribute to `'sankey'`
|
|
41
62
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* chartjs-chart-sankey v0.
|
|
3
|
-
* https://
|
|
4
|
-
* (c)
|
|
2
|
+
* chartjs-chart-sankey v0.0.0-development
|
|
3
|
+
* https://chartjs-chart-sankey.pages.dev/
|
|
4
|
+
* (c) 2026 Jukka Kurkela
|
|
5
5
|
* Released under the MIT license
|
|
6
6
|
*/
|
|
7
7
|
(function (global, factory) {
|
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('chart.js'), require('chart.js/helpers')) :
|
|
9
|
-
typeof define === 'function' && define.amd ? define(['chart.js', 'chart.js/helpers'], factory) :
|
|
10
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Chart, global.Chart.helpers));
|
|
11
|
-
})(this, (function (chart_js, helpers) { 'use strict';
|
|
8
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('chart.js'), require('chart.js/helpers')) :
|
|
9
|
+
typeof define === 'function' && define.amd ? define(['exports', 'chart.js', 'chart.js/helpers'], factory) :
|
|
10
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["chartjs-chart-sankey"] = {}, global.Chart, global.Chart.helpers));
|
|
11
|
+
})(this, (function (exports, chart_js, helpers) { 'use strict';
|
|
12
12
|
|
|
13
13
|
const defined = (x)=>x !== undefined;
|
|
14
14
|
function toTextLines(raw) {
|
|
@@ -71,9 +71,9 @@ const setColumns = (nodes, column)=>{
|
|
|
71
71
|
const getParsedData = (data, parsing)=>{
|
|
72
72
|
const { from: fromKey = 'from', to: toKey = 'to', flow: flowKey = 'flow' } = parsing;
|
|
73
73
|
return data.map(({ [fromKey]: from, [toKey]: to, [flowKey]: flow })=>({
|
|
74
|
+
flow,
|
|
74
75
|
from,
|
|
75
|
-
to
|
|
76
|
-
flow
|
|
76
|
+
to
|
|
77
77
|
}));
|
|
78
78
|
};
|
|
79
79
|
function buildNodesFromData(data, { size, priority, column }) {
|
|
@@ -81,39 +81,39 @@ function buildNodesFromData(data, { size, priority, column }) {
|
|
|
81
81
|
for(let i = 0; i < data.length; i++){
|
|
82
82
|
const { from, to, flow } = data[i];
|
|
83
83
|
const fromNode = nodes.get(from) ?? {
|
|
84
|
-
|
|
84
|
+
from: [],
|
|
85
85
|
in: 0,
|
|
86
|
+
key: from,
|
|
86
87
|
out: 0,
|
|
87
88
|
size: 0,
|
|
88
|
-
from: [],
|
|
89
89
|
to: []
|
|
90
90
|
};
|
|
91
91
|
const toNode = (from === to ? fromNode : nodes.get(to)) ?? {
|
|
92
|
-
|
|
92
|
+
from: [],
|
|
93
93
|
in: 0,
|
|
94
|
+
key: to,
|
|
94
95
|
out: 0,
|
|
95
96
|
size: 0,
|
|
96
|
-
from: [],
|
|
97
97
|
to: []
|
|
98
98
|
};
|
|
99
99
|
fromNode.out += flow;
|
|
100
100
|
fromNode.to.push({
|
|
101
|
-
|
|
101
|
+
addY: 0,
|
|
102
102
|
flow: flow,
|
|
103
103
|
index: i,
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
key: to,
|
|
105
|
+
node: toNode
|
|
106
106
|
});
|
|
107
107
|
if (fromNode.to.length === 1) {
|
|
108
108
|
nodes.set(from, fromNode);
|
|
109
109
|
}
|
|
110
110
|
toNode.in += flow;
|
|
111
111
|
toNode.from.push({
|
|
112
|
-
|
|
112
|
+
addY: 0,
|
|
113
113
|
flow: flow,
|
|
114
114
|
index: i,
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
key: from,
|
|
116
|
+
node: fromNode
|
|
117
117
|
});
|
|
118
118
|
if (toNode.from.length === 1) {
|
|
119
119
|
nodes.set(to, toNode);
|
|
@@ -424,12 +424,13 @@ class SankeyController extends chart_js.DatasetController {
|
|
|
424
424
|
const sankeyData = getParsedData(data, this.options.parsing);
|
|
425
425
|
const { xScale, yScale } = meta;
|
|
426
426
|
const parsed = [];
|
|
427
|
-
const nodes =
|
|
427
|
+
const nodes = buildNodesFromData(sankeyData, this.options);
|
|
428
|
+
this._nodes = nodes;
|
|
428
429
|
const { maxX, maxY } = layout(nodes, sankeyData, {
|
|
429
|
-
priority: !!this.options.priority,
|
|
430
430
|
height: this.chart.canvas.height,
|
|
431
|
+
modeX: this.options.modeX,
|
|
431
432
|
nodePadding: this.options.nodePadding,
|
|
432
|
-
|
|
433
|
+
priority: !!this.options.priority
|
|
433
434
|
});
|
|
434
435
|
this._maxX = maxX;
|
|
435
436
|
this._maxY = maxY;
|
|
@@ -442,24 +443,24 @@ class SankeyController extends chart_js.DatasetController {
|
|
|
442
443
|
const fromY = (from.y ?? 0) + getAddY(from.to, dataPoint.to, i);
|
|
443
444
|
const toY = (to.y ?? 0) + getAddY(to.from, dataPoint.from, i);
|
|
444
445
|
parsed.push({
|
|
445
|
-
x: xScale.parse(from.x, i),
|
|
446
|
-
y: yScale.parse(fromY, i),
|
|
447
446
|
_custom: {
|
|
447
|
+
flow: dataPoint.flow,
|
|
448
448
|
from,
|
|
449
|
+
height: yScale.parse(dataPoint.flow, i),
|
|
449
450
|
to,
|
|
450
451
|
x: xScale.parse(to.x, i),
|
|
451
|
-
y: yScale.parse(toY, i)
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
452
|
+
y: yScale.parse(toY, i)
|
|
453
|
+
},
|
|
454
|
+
x: xScale.parse(from.x, i),
|
|
455
|
+
y: yScale.parse(fromY, i)
|
|
455
456
|
});
|
|
456
457
|
}
|
|
457
458
|
return parsed.slice(start, start + count);
|
|
458
459
|
}
|
|
459
460
|
getMinMax(scale) {
|
|
460
461
|
return {
|
|
461
|
-
|
|
462
|
-
|
|
462
|
+
max: scale === this._cachedMeta.xScale ? this._maxX : this._maxY,
|
|
463
|
+
min: 0
|
|
463
464
|
};
|
|
464
465
|
}
|
|
465
466
|
update(mode) {
|
|
@@ -478,15 +479,15 @@ class SankeyController extends chart_js.DatasetController {
|
|
|
478
479
|
const custom = parsed._custom;
|
|
479
480
|
const y = yScale.getPixelForValue(parsed.y);
|
|
480
481
|
this.updateElement(elems[i], i, {
|
|
481
|
-
x: xScale.getPixelForValue(parsed.x) + nodeWidth + borderSpace,
|
|
482
|
-
y,
|
|
483
|
-
x2: xScale.getPixelForValue(custom.x) - borderSpace,
|
|
484
|
-
y2: yScale.getPixelForValue(custom.y),
|
|
485
482
|
from: custom.from,
|
|
486
|
-
to: custom.to,
|
|
487
|
-
progress: mode === 'reset' ? 0 : 1,
|
|
488
483
|
height: Math.abs(yScale.getPixelForValue(parsed.y + custom.height) - y),
|
|
489
|
-
options: this.resolveDataElementOptions(i, mode)
|
|
484
|
+
options: this.resolveDataElementOptions(i, mode),
|
|
485
|
+
progress: mode === 'reset' ? 0 : 1,
|
|
486
|
+
to: custom.to,
|
|
487
|
+
x: xScale.getPixelForValue(parsed.x) + nodeWidth + borderSpace,
|
|
488
|
+
x2: xScale.getPixelForValue(custom.x) - borderSpace,
|
|
489
|
+
y,
|
|
490
|
+
y2: yScale.getPixelForValue(custom.y)
|
|
490
491
|
}, mode);
|
|
491
492
|
}
|
|
492
493
|
this.updateSharedOptions(sharedOptions, mode, firstOpts);
|
|
@@ -589,116 +590,116 @@ class SankeyController extends chart_js.DatasetController {
|
|
|
589
590
|
}
|
|
590
591
|
SankeyController.id = 'sankey';
|
|
591
592
|
SankeyController.defaults = {
|
|
592
|
-
dataElementType: 'flow',
|
|
593
593
|
animations: {
|
|
594
|
+
colors: {
|
|
595
|
+
properties: [
|
|
596
|
+
'colorFrom',
|
|
597
|
+
'colorTo'
|
|
598
|
+
],
|
|
599
|
+
type: 'color'
|
|
600
|
+
},
|
|
594
601
|
numbers: {
|
|
595
|
-
type: 'number',
|
|
596
602
|
properties: [
|
|
597
603
|
'x',
|
|
598
604
|
'y',
|
|
599
605
|
'x2',
|
|
600
606
|
'y2',
|
|
601
607
|
'height'
|
|
602
|
-
]
|
|
608
|
+
],
|
|
609
|
+
type: 'number'
|
|
603
610
|
},
|
|
604
611
|
progress: {
|
|
605
|
-
|
|
612
|
+
delay: (ctx)=>ctx.type === 'data' ? ctx.parsed.x * 500 + ctx.dataIndex * 20 : undefined,
|
|
606
613
|
duration: (ctx)=>ctx.type === 'data' ? (ctx.parsed._custom.x - ctx.parsed.x) * 200 : undefined,
|
|
607
|
-
|
|
608
|
-
},
|
|
609
|
-
colors: {
|
|
610
|
-
type: 'color',
|
|
611
|
-
properties: [
|
|
612
|
-
'colorFrom',
|
|
613
|
-
'colorTo'
|
|
614
|
-
]
|
|
614
|
+
easing: 'linear'
|
|
615
615
|
}
|
|
616
616
|
},
|
|
617
|
-
color: 'black',
|
|
618
617
|
borderColor: 'black',
|
|
619
618
|
borderWidth: 1,
|
|
619
|
+
color: 'black',
|
|
620
|
+
dataElementType: 'flow',
|
|
620
621
|
modeX: 'edge',
|
|
621
|
-
nodeWidth: 10,
|
|
622
622
|
nodePadding: 10,
|
|
623
|
+
nodeWidth: 10,
|
|
623
624
|
transitions: {
|
|
624
625
|
hide: {
|
|
625
626
|
animations: {
|
|
626
627
|
colors: {
|
|
627
|
-
type: 'color',
|
|
628
628
|
properties: [
|
|
629
629
|
'colorFrom',
|
|
630
630
|
'colorTo'
|
|
631
631
|
],
|
|
632
|
-
to: 'transparent'
|
|
632
|
+
to: 'transparent',
|
|
633
|
+
type: 'color'
|
|
633
634
|
}
|
|
634
635
|
}
|
|
635
636
|
},
|
|
636
637
|
show: {
|
|
637
638
|
animations: {
|
|
638
639
|
colors: {
|
|
639
|
-
|
|
640
|
+
from: 'transparent',
|
|
640
641
|
properties: [
|
|
641
642
|
'colorFrom',
|
|
642
643
|
'colorTo'
|
|
643
644
|
],
|
|
644
|
-
|
|
645
|
+
type: 'color'
|
|
645
646
|
}
|
|
646
647
|
}
|
|
647
648
|
}
|
|
648
649
|
}
|
|
649
650
|
};
|
|
650
651
|
SankeyController.overrides = {
|
|
651
|
-
interaction: {
|
|
652
|
-
mode: 'nearest',
|
|
653
|
-
intersect: true
|
|
654
|
-
},
|
|
655
652
|
datasets: {
|
|
656
653
|
clip: false,
|
|
657
654
|
parsing: {
|
|
655
|
+
flow: 'flow',
|
|
658
656
|
from: 'from',
|
|
659
|
-
to: 'to'
|
|
660
|
-
|
|
657
|
+
to: 'to'
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
interaction: {
|
|
661
|
+
intersect: true,
|
|
662
|
+
mode: 'nearest'
|
|
663
|
+
},
|
|
664
|
+
layout: {
|
|
665
|
+
padding: {
|
|
666
|
+
bottom: 3,
|
|
667
|
+
left: 3,
|
|
668
|
+
right: 13,
|
|
669
|
+
top: 3
|
|
661
670
|
}
|
|
662
671
|
},
|
|
663
672
|
plugins: {
|
|
673
|
+
legend: {
|
|
674
|
+
display: false
|
|
675
|
+
},
|
|
664
676
|
tooltip: {
|
|
665
677
|
callbacks: {
|
|
666
|
-
title () {
|
|
667
|
-
return '';
|
|
668
|
-
},
|
|
669
678
|
label (context) {
|
|
670
679
|
const parsedCustom = context.parsed._custom;
|
|
671
680
|
return parsedCustom.from.key + ' -> ' + parsedCustom.to.key + ': ' + parsedCustom.flow;
|
|
681
|
+
},
|
|
682
|
+
title () {
|
|
683
|
+
return '';
|
|
672
684
|
}
|
|
673
685
|
}
|
|
674
|
-
},
|
|
675
|
-
legend: {
|
|
676
|
-
display: false
|
|
677
686
|
}
|
|
678
687
|
},
|
|
679
688
|
scales: {
|
|
680
689
|
x: {
|
|
681
|
-
type: 'linear',
|
|
682
690
|
bounds: 'data',
|
|
683
691
|
display: false,
|
|
684
692
|
min: 0,
|
|
685
|
-
offset: false
|
|
693
|
+
offset: false,
|
|
694
|
+
type: 'linear'
|
|
686
695
|
},
|
|
687
696
|
y: {
|
|
688
|
-
type: 'linear',
|
|
689
697
|
bounds: 'data',
|
|
690
698
|
display: false,
|
|
691
699
|
min: 0,
|
|
700
|
+
offset: false,
|
|
692
701
|
reverse: true,
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
},
|
|
696
|
-
layout: {
|
|
697
|
-
padding: {
|
|
698
|
-
top: 3,
|
|
699
|
-
left: 3,
|
|
700
|
-
right: 13,
|
|
701
|
-
bottom: 3
|
|
702
|
+
type: 'linear'
|
|
702
703
|
}
|
|
703
704
|
}
|
|
704
705
|
};
|
|
@@ -842,10 +843,10 @@ class Flow extends chart_js.Element {
|
|
|
842
843
|
}
|
|
843
844
|
Flow.id = 'flow';
|
|
844
845
|
Flow.defaults = {
|
|
846
|
+
alpha: 0.5,
|
|
845
847
|
colorFrom: 'red',
|
|
846
|
-
colorTo: 'green',
|
|
847
848
|
colorMode: 'gradient',
|
|
848
|
-
|
|
849
|
+
colorTo: 'green',
|
|
849
850
|
hoverColorFrom: (_ctx, options)=>helpers.getHoverColor(options.colorFrom),
|
|
850
851
|
hoverColorTo: (_ctx, options)=>helpers.getHoverColor(options.colorTo)
|
|
851
852
|
};
|
|
@@ -855,4 +856,7 @@ Flow.descriptors = {
|
|
|
855
856
|
|
|
856
857
|
chart_js.Chart.register(SankeyController, Flow);
|
|
857
858
|
|
|
859
|
+
exports.Flow = Flow;
|
|
860
|
+
exports.SankeyController = SankeyController;
|
|
861
|
+
|
|
858
862
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* chartjs-chart-sankey v0.
|
|
3
|
-
* https://
|
|
4
|
-
* (c)
|
|
2
|
+
* chartjs-chart-sankey v0.0.0-development
|
|
3
|
+
* https://chartjs-chart-sankey.pages.dev/
|
|
4
|
+
* (c) 2026 Jukka Kurkela
|
|
5
5
|
* Released under the MIT license
|
|
6
6
|
*/
|
|
7
7
|
import { DatasetController, Element } from 'chart.js';
|
|
@@ -68,9 +68,9 @@ const setColumns = (nodes, column)=>{
|
|
|
68
68
|
const getParsedData = (data, parsing)=>{
|
|
69
69
|
const { from: fromKey = 'from', to: toKey = 'to', flow: flowKey = 'flow' } = parsing;
|
|
70
70
|
return data.map(({ [fromKey]: from, [toKey]: to, [flowKey]: flow })=>({
|
|
71
|
+
flow,
|
|
71
72
|
from,
|
|
72
|
-
to
|
|
73
|
-
flow
|
|
73
|
+
to
|
|
74
74
|
}));
|
|
75
75
|
};
|
|
76
76
|
function buildNodesFromData(data, { size, priority, column }) {
|
|
@@ -78,39 +78,39 @@ function buildNodesFromData(data, { size, priority, column }) {
|
|
|
78
78
|
for(let i = 0; i < data.length; i++){
|
|
79
79
|
const { from, to, flow } = data[i];
|
|
80
80
|
const fromNode = nodes.get(from) ?? {
|
|
81
|
-
|
|
81
|
+
from: [],
|
|
82
82
|
in: 0,
|
|
83
|
+
key: from,
|
|
83
84
|
out: 0,
|
|
84
85
|
size: 0,
|
|
85
|
-
from: [],
|
|
86
86
|
to: []
|
|
87
87
|
};
|
|
88
88
|
const toNode = (from === to ? fromNode : nodes.get(to)) ?? {
|
|
89
|
-
|
|
89
|
+
from: [],
|
|
90
90
|
in: 0,
|
|
91
|
+
key: to,
|
|
91
92
|
out: 0,
|
|
92
93
|
size: 0,
|
|
93
|
-
from: [],
|
|
94
94
|
to: []
|
|
95
95
|
};
|
|
96
96
|
fromNode.out += flow;
|
|
97
97
|
fromNode.to.push({
|
|
98
|
-
|
|
98
|
+
addY: 0,
|
|
99
99
|
flow: flow,
|
|
100
100
|
index: i,
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
key: to,
|
|
102
|
+
node: toNode
|
|
103
103
|
});
|
|
104
104
|
if (fromNode.to.length === 1) {
|
|
105
105
|
nodes.set(from, fromNode);
|
|
106
106
|
}
|
|
107
107
|
toNode.in += flow;
|
|
108
108
|
toNode.from.push({
|
|
109
|
-
|
|
109
|
+
addY: 0,
|
|
110
110
|
flow: flow,
|
|
111
111
|
index: i,
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
key: from,
|
|
113
|
+
node: fromNode
|
|
114
114
|
});
|
|
115
115
|
if (toNode.from.length === 1) {
|
|
116
116
|
nodes.set(to, toNode);
|
|
@@ -421,12 +421,13 @@ class SankeyController extends DatasetController {
|
|
|
421
421
|
const sankeyData = getParsedData(data, this.options.parsing);
|
|
422
422
|
const { xScale, yScale } = meta;
|
|
423
423
|
const parsed = [];
|
|
424
|
-
const nodes =
|
|
424
|
+
const nodes = buildNodesFromData(sankeyData, this.options);
|
|
425
|
+
this._nodes = nodes;
|
|
425
426
|
const { maxX, maxY } = layout(nodes, sankeyData, {
|
|
426
|
-
priority: !!this.options.priority,
|
|
427
427
|
height: this.chart.canvas.height,
|
|
428
|
+
modeX: this.options.modeX,
|
|
428
429
|
nodePadding: this.options.nodePadding,
|
|
429
|
-
|
|
430
|
+
priority: !!this.options.priority
|
|
430
431
|
});
|
|
431
432
|
this._maxX = maxX;
|
|
432
433
|
this._maxY = maxY;
|
|
@@ -439,24 +440,24 @@ class SankeyController extends DatasetController {
|
|
|
439
440
|
const fromY = (from.y ?? 0) + getAddY(from.to, dataPoint.to, i);
|
|
440
441
|
const toY = (to.y ?? 0) + getAddY(to.from, dataPoint.from, i);
|
|
441
442
|
parsed.push({
|
|
442
|
-
x: xScale.parse(from.x, i),
|
|
443
|
-
y: yScale.parse(fromY, i),
|
|
444
443
|
_custom: {
|
|
444
|
+
flow: dataPoint.flow,
|
|
445
445
|
from,
|
|
446
|
+
height: yScale.parse(dataPoint.flow, i),
|
|
446
447
|
to,
|
|
447
448
|
x: xScale.parse(to.x, i),
|
|
448
|
-
y: yScale.parse(toY, i)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
449
|
+
y: yScale.parse(toY, i)
|
|
450
|
+
},
|
|
451
|
+
x: xScale.parse(from.x, i),
|
|
452
|
+
y: yScale.parse(fromY, i)
|
|
452
453
|
});
|
|
453
454
|
}
|
|
454
455
|
return parsed.slice(start, start + count);
|
|
455
456
|
}
|
|
456
457
|
getMinMax(scale) {
|
|
457
458
|
return {
|
|
458
|
-
|
|
459
|
-
|
|
459
|
+
max: scale === this._cachedMeta.xScale ? this._maxX : this._maxY,
|
|
460
|
+
min: 0
|
|
460
461
|
};
|
|
461
462
|
}
|
|
462
463
|
update(mode) {
|
|
@@ -475,15 +476,15 @@ class SankeyController extends DatasetController {
|
|
|
475
476
|
const custom = parsed._custom;
|
|
476
477
|
const y = yScale.getPixelForValue(parsed.y);
|
|
477
478
|
this.updateElement(elems[i], i, {
|
|
478
|
-
x: xScale.getPixelForValue(parsed.x) + nodeWidth + borderSpace,
|
|
479
|
-
y,
|
|
480
|
-
x2: xScale.getPixelForValue(custom.x) - borderSpace,
|
|
481
|
-
y2: yScale.getPixelForValue(custom.y),
|
|
482
479
|
from: custom.from,
|
|
483
|
-
to: custom.to,
|
|
484
|
-
progress: mode === 'reset' ? 0 : 1,
|
|
485
480
|
height: Math.abs(yScale.getPixelForValue(parsed.y + custom.height) - y),
|
|
486
|
-
options: this.resolveDataElementOptions(i, mode)
|
|
481
|
+
options: this.resolveDataElementOptions(i, mode),
|
|
482
|
+
progress: mode === 'reset' ? 0 : 1,
|
|
483
|
+
to: custom.to,
|
|
484
|
+
x: xScale.getPixelForValue(parsed.x) + nodeWidth + borderSpace,
|
|
485
|
+
x2: xScale.getPixelForValue(custom.x) - borderSpace,
|
|
486
|
+
y,
|
|
487
|
+
y2: yScale.getPixelForValue(custom.y)
|
|
487
488
|
}, mode);
|
|
488
489
|
}
|
|
489
490
|
this.updateSharedOptions(sharedOptions, mode, firstOpts);
|
|
@@ -586,116 +587,116 @@ class SankeyController extends DatasetController {
|
|
|
586
587
|
}
|
|
587
588
|
SankeyController.id = 'sankey';
|
|
588
589
|
SankeyController.defaults = {
|
|
589
|
-
dataElementType: 'flow',
|
|
590
590
|
animations: {
|
|
591
|
+
colors: {
|
|
592
|
+
properties: [
|
|
593
|
+
'colorFrom',
|
|
594
|
+
'colorTo'
|
|
595
|
+
],
|
|
596
|
+
type: 'color'
|
|
597
|
+
},
|
|
591
598
|
numbers: {
|
|
592
|
-
type: 'number',
|
|
593
599
|
properties: [
|
|
594
600
|
'x',
|
|
595
601
|
'y',
|
|
596
602
|
'x2',
|
|
597
603
|
'y2',
|
|
598
604
|
'height'
|
|
599
|
-
]
|
|
605
|
+
],
|
|
606
|
+
type: 'number'
|
|
600
607
|
},
|
|
601
608
|
progress: {
|
|
602
|
-
|
|
609
|
+
delay: (ctx)=>ctx.type === 'data' ? ctx.parsed.x * 500 + ctx.dataIndex * 20 : undefined,
|
|
603
610
|
duration: (ctx)=>ctx.type === 'data' ? (ctx.parsed._custom.x - ctx.parsed.x) * 200 : undefined,
|
|
604
|
-
|
|
605
|
-
},
|
|
606
|
-
colors: {
|
|
607
|
-
type: 'color',
|
|
608
|
-
properties: [
|
|
609
|
-
'colorFrom',
|
|
610
|
-
'colorTo'
|
|
611
|
-
]
|
|
611
|
+
easing: 'linear'
|
|
612
612
|
}
|
|
613
613
|
},
|
|
614
|
-
color: 'black',
|
|
615
614
|
borderColor: 'black',
|
|
616
615
|
borderWidth: 1,
|
|
616
|
+
color: 'black',
|
|
617
|
+
dataElementType: 'flow',
|
|
617
618
|
modeX: 'edge',
|
|
618
|
-
nodeWidth: 10,
|
|
619
619
|
nodePadding: 10,
|
|
620
|
+
nodeWidth: 10,
|
|
620
621
|
transitions: {
|
|
621
622
|
hide: {
|
|
622
623
|
animations: {
|
|
623
624
|
colors: {
|
|
624
|
-
type: 'color',
|
|
625
625
|
properties: [
|
|
626
626
|
'colorFrom',
|
|
627
627
|
'colorTo'
|
|
628
628
|
],
|
|
629
|
-
to: 'transparent'
|
|
629
|
+
to: 'transparent',
|
|
630
|
+
type: 'color'
|
|
630
631
|
}
|
|
631
632
|
}
|
|
632
633
|
},
|
|
633
634
|
show: {
|
|
634
635
|
animations: {
|
|
635
636
|
colors: {
|
|
636
|
-
|
|
637
|
+
from: 'transparent',
|
|
637
638
|
properties: [
|
|
638
639
|
'colorFrom',
|
|
639
640
|
'colorTo'
|
|
640
641
|
],
|
|
641
|
-
|
|
642
|
+
type: 'color'
|
|
642
643
|
}
|
|
643
644
|
}
|
|
644
645
|
}
|
|
645
646
|
}
|
|
646
647
|
};
|
|
647
648
|
SankeyController.overrides = {
|
|
648
|
-
interaction: {
|
|
649
|
-
mode: 'nearest',
|
|
650
|
-
intersect: true
|
|
651
|
-
},
|
|
652
649
|
datasets: {
|
|
653
650
|
clip: false,
|
|
654
651
|
parsing: {
|
|
652
|
+
flow: 'flow',
|
|
655
653
|
from: 'from',
|
|
656
|
-
to: 'to'
|
|
657
|
-
|
|
654
|
+
to: 'to'
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
interaction: {
|
|
658
|
+
intersect: true,
|
|
659
|
+
mode: 'nearest'
|
|
660
|
+
},
|
|
661
|
+
layout: {
|
|
662
|
+
padding: {
|
|
663
|
+
bottom: 3,
|
|
664
|
+
left: 3,
|
|
665
|
+
right: 13,
|
|
666
|
+
top: 3
|
|
658
667
|
}
|
|
659
668
|
},
|
|
660
669
|
plugins: {
|
|
670
|
+
legend: {
|
|
671
|
+
display: false
|
|
672
|
+
},
|
|
661
673
|
tooltip: {
|
|
662
674
|
callbacks: {
|
|
663
|
-
title () {
|
|
664
|
-
return '';
|
|
665
|
-
},
|
|
666
675
|
label (context) {
|
|
667
676
|
const parsedCustom = context.parsed._custom;
|
|
668
677
|
return parsedCustom.from.key + ' -> ' + parsedCustom.to.key + ': ' + parsedCustom.flow;
|
|
678
|
+
},
|
|
679
|
+
title () {
|
|
680
|
+
return '';
|
|
669
681
|
}
|
|
670
682
|
}
|
|
671
|
-
},
|
|
672
|
-
legend: {
|
|
673
|
-
display: false
|
|
674
683
|
}
|
|
675
684
|
},
|
|
676
685
|
scales: {
|
|
677
686
|
x: {
|
|
678
|
-
type: 'linear',
|
|
679
687
|
bounds: 'data',
|
|
680
688
|
display: false,
|
|
681
689
|
min: 0,
|
|
682
|
-
offset: false
|
|
690
|
+
offset: false,
|
|
691
|
+
type: 'linear'
|
|
683
692
|
},
|
|
684
693
|
y: {
|
|
685
|
-
type: 'linear',
|
|
686
694
|
bounds: 'data',
|
|
687
695
|
display: false,
|
|
688
696
|
min: 0,
|
|
697
|
+
offset: false,
|
|
689
698
|
reverse: true,
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
},
|
|
693
|
-
layout: {
|
|
694
|
-
padding: {
|
|
695
|
-
top: 3,
|
|
696
|
-
left: 3,
|
|
697
|
-
right: 13,
|
|
698
|
-
bottom: 3
|
|
699
|
+
type: 'linear'
|
|
699
700
|
}
|
|
700
701
|
}
|
|
701
702
|
};
|
|
@@ -839,10 +840,10 @@ class Flow extends Element {
|
|
|
839
840
|
}
|
|
840
841
|
Flow.id = 'flow';
|
|
841
842
|
Flow.defaults = {
|
|
843
|
+
alpha: 0.5,
|
|
842
844
|
colorFrom: 'red',
|
|
843
|
-
colorTo: 'green',
|
|
844
845
|
colorMode: 'gradient',
|
|
845
|
-
|
|
846
|
+
colorTo: 'green',
|
|
846
847
|
hoverColorFrom: (_ctx, options)=>getHoverColor(options.colorFrom),
|
|
847
848
|
hoverColorTo: (_ctx, options)=>getHoverColor(options.colorTo)
|
|
848
849
|
};
|