Skip to content

Commit 83f25af

Browse files
committed
sankey: introduce node.customdata
1 parent 80262b5 commit 83f25af

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/traces/sankey/attributes.js

+7
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ var attrs = module.exports = overrideAll({
128128
'what is beneath the node.'
129129
].join(' ')
130130
},
131+
customdata: {
132+
valType: 'data_array',
133+
editType: 'calc',
134+
description: [
135+
'Assigns extra data each node.'
136+
].join(' ')
137+
},
131138
line: {
132139
color: {
133140
valType: 'color',

src/traces/sankey/calc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function convertToD3Sankey(trace) {
116116
// Process nodes
117117
var totalCount = nodeCount + groups.length;
118118
var hasNodeColorArray = isArrayOrTypedArray(nodeSpec.color);
119+
var hasNodeCustomdataArray = isArrayOrTypedArray(nodeSpec.customdata);
119120
var nodes = [];
120121
for(i = 0; i < totalCount; i++) {
121122
if(!linkedNodes[i]) continue;
@@ -126,7 +127,8 @@ function convertToD3Sankey(trace) {
126127
childrenNodes: [],
127128
pointNumber: i,
128129
label: l,
129-
color: hasNodeColorArray ? nodeSpec.color[i] : nodeSpec.color
130+
color: hasNodeColorArray ? nodeSpec.color[i] : nodeSpec.color,
131+
customdata: hasNodeCustomdataArray ? nodeSpec.customdata[i] : nodeSpec.customdata
130132
});
131133
}
132134

src/traces/sankey/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5050
coerceNode('color', nodeOut.label.map(function(d, i) {
5151
return Color.addOpacity(defaultNodePalette(i), 0.8);
5252
}));
53+
coerceNode('customdata');
5354

5455
// link attributes
5556
var linkIn = traceIn.link || {};

test/jasmine/tests/sankey_test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ describe('sankey tests', function() {
816816
it('should show the correct hover labels when hovertemplate is specified', function(done) {
817817
var gd = createGraphDiv();
818818
var mockCopy = Lib.extendDeep({}, mock);
819+
mockCopy.data[0].node.customdata = [0, 0, 0, 0, '15']
819820

820821
Plotly.plot(gd, mockCopy).then(function() {
821822
_hover(404, 302);
@@ -836,15 +837,15 @@ describe('sankey tests', function() {
836837
// Test (node|link).hovertemplate
837838
.then(function() {
838839
return Plotly.restyle(gd, {
839-
'node.hovertemplate': 'hovertemplate<br>%{value}<br>%{value:0.2f}<extra>%{fullData.name}</extra>',
840+
'node.hovertemplate': 'hovertemplate<br>%{value}<br>%{value:0.2f}<br>%{customdata}<extra>%{fullData.name}</extra>',
840841
'link.hovertemplate': 'hovertemplate<br>source: %{source.label}<br>target: %{target.label}<br>size: %{value:0.0f}TWh<extra>%{fullData.name}</extra>'
841842
});
842843
})
843844
.then(function() {
844845
_hover(404, 302);
845846

846847
assertLabel(
847-
[ 'hovertemplate', '447TWh', '447.48', 'trace 0'],
848+
[ 'hovertemplate', '447TWh', '447.48', '15', 'trace 0'],
848849
['rgb(148, 103, 189)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)']
849850
);
850851
})

0 commit comments

Comments
 (0)