Skip to content

Commit e69e3a2

Browse files
committed
attribute work:
- link line styling - more consistent node line var names
1 parent 1cbc2f2 commit e69e3a2

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

src/traces/sankey/attributes.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ module.exports = {
102102
},
103103
color: extendFlat({}, shapeAttrs.fillcolor, {
104104
arrayOk: true,
105-
dflt: 'rgb(0,255,0,0.5)'
105+
description: [
106+
'Sets the `node` color. It can be a single value, or an array for specifying color for each `node`.',
107+
'If `node.color` is omitted, then the default `Plotly` color palette will be cycled through',
108+
'to have a variety of colors. These defaults are not fully opaque, to allow some visibility of',
109+
'what is beneath the node.'
110+
].join(' ')
106111
}),
107112
line: {
108113
color: {
@@ -111,7 +116,7 @@ module.exports = {
111116
dflt: colorAttrs.defaultLine,
112117
arrayOk: true,
113118
description: [
114-
'Sets the color of the line enclosing each sector.'
119+
'Sets the color of the `line` around each `node`.'
115120
].join(' ')
116121
},
117122
width: {
@@ -121,7 +126,7 @@ module.exports = {
121126
dflt: 0.5,
122127
arrayOk: true,
123128
description: [
124-
'Sets the width (in px) of the line enclosing each sector.'
129+
'Sets the width (in px) of the `line` around each `node`.'
125130
].join(' ')
126131
}
127132
},
@@ -151,7 +156,34 @@ module.exports = {
151156
role: 'info',
152157
description: 'The shown name of the link.'
153158
},
154-
color: extendFlat({}, shapeAttrs.fillcolor, {arrayOk: true, dflt: 'rgba(0,0,0,0.2)'}),
159+
color: extendFlat({}, shapeAttrs.fillcolor, {
160+
arrayOk: true,
161+
description: [
162+
'Sets the `link` color. It can be a single value, or an array for specifying color for each `link`.',
163+
'If `link.color` is omitted, then by default, a translucent grey link will be used.'
164+
].join(' ')
165+
}),
166+
line: {
167+
color: {
168+
valType: 'color',
169+
role: 'style',
170+
dflt: colorAttrs.defaultLine,
171+
arrayOk: true,
172+
description: [
173+
'Sets the color of the `line` around each `link`.'
174+
].join(' ')
175+
},
176+
width: {
177+
valType: 'number',
178+
role: 'style',
179+
min: 0,
180+
dflt: 0,
181+
arrayOk: true,
182+
description: [
183+
'Sets the width (in px) of the `line` around each `link`.'
184+
].join(' ')
185+
}
186+
},
155187
source: {
156188
valType: 'data_array',
157189
role: 'info',

src/traces/sankey/defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5757
coerce('link.source');
5858
coerce('link.target');
5959
coerce('link.value');
60+
coerce('link.line.color');
61+
coerce('link.line.width');
6062

6163
coerce('link.color', traceIn.link.value.map(function() {
6264
return tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ?

src/traces/sankey/render.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ function sankeyModel(layout, d, i) {
7474
horizontal = trace.orientation === 'h',
7575
nodePad = trace.node.pad,
7676
nodeThickness = trace.node.thickness,
77-
nodelineColor = trace.node.line.color,
78-
nodelineWidth = trace.node.line.width,
77+
nodeLineColor = trace.node.line.color,
78+
nodeLineWidth = trace.node.line.width,
79+
linkLineColor = trace.link.line.color,
80+
linkLineWidth = trace.link.line.width,
7981
valueFormat = trace.valueformat,
8082
valueSuffix = trace.valuesuffix,
8183
textFont = trace.textfont;
@@ -126,8 +128,10 @@ function sankeyModel(layout, d, i) {
126128
width: width,
127129
height: height,
128130
nodePad: nodePad,
129-
nodelineColor: nodelineColor,
130-
nodelineWidth: nodelineWidth,
131+
nodeLineColor: nodeLineColor,
132+
nodeLineWidth: nodeLineWidth,
133+
linkLineColor: linkLineColor,
134+
linkLineWidth: linkLineWidth,
131135
valueFormat: valueFormat,
132136
valueSuffix: valueSuffix,
133137
textFont: textFont,
@@ -161,6 +165,8 @@ function linkModel(uniqueKeys, d, l) {
161165
link: l,
162166
tinyColorHue: Color.tinyRGB(tc),
163167
tinyColorAlpha: tc.getAlpha(),
168+
linkLineColor: d.linkLineColor,
169+
linkLineWidth: d.linkLineWidth,
164170
valueFormat: d.valueFormat,
165171
valueSuffix: d.valueSuffix,
166172
sankey: d.sankey,
@@ -188,8 +194,8 @@ function nodeModel(uniqueKeys, d, n) {
188194
traceId: d.key,
189195
node: n,
190196
nodePad: d.nodePad,
191-
nodelineColor: d.nodelineColor,
192-
nodelineWidth: d.nodelineWidth,
197+
nodeLineColor: d.nodeLineColor,
198+
nodeLineWidth: d.nodeLineWidth,
193199
textFont: d.textFont,
194200
size: d.horizontal ? d.height : d.width,
195201
visibleWidth: Math.ceil(d.horizontal ? visibleThickness : visibleLength),
@@ -253,6 +259,10 @@ function sizeNode(rect) {
253259
.attr('height', function(d) {return d.visibleHeight;});
254260
}
255261

262+
function salientEnough(d) {
263+
return d.link.dy > 1 || d.linkLineWidth > 0;
264+
}
265+
256266
function linksTransform(d) {
257267
return d.horizontal ? 'matrix(1,0,0,1,0,0)' : 'matrix(0,1,1,0,0,0)';
258268
}
@@ -455,9 +465,13 @@ module.exports = function(svg, styledData, layout, callbacks) {
455465
.call(attachPointerEvents, sankey, callbacks.linkEvents);
456466

457467
sankeyLink
458-
.style('stroke', function(d) {return d.link.dy > 1 ? 'rgba(0,0,0,0)' : d.tinyColorHue;})
459-
.style('stroke-width', function(d) {return d.link.dy > 1 ? 2 : 1;})
460-
.style('stroke-opacity', function(d) {return d.tinyColorAlpha;})
468+
.style('stroke', function(d) {
469+
return salientEnough(d) ? Color.tinyRGB(tinycolor(d.linkLineColor)) : d.tinyColorHue;
470+
})
471+
.style('stroke-opacity', function(d) {
472+
return salientEnough(d) ? Color.opacity(d.linkLineColor) : d.tinyColorAlpha;
473+
})
474+
.style('stroke-width', function(d) {return salientEnough(d) ? d.linkLineWidth : 1;})
461475
.style('fill', function(d) {return d.tinyColorHue;})
462476
.style('fill-opacity', function(d) {return d.tinyColorAlpha;});
463477

@@ -524,9 +538,9 @@ module.exports = function(svg, styledData, layout, callbacks) {
524538
.call(sizeNode);
525539

526540
nodeRect
527-
.style('stroke-width', function(d) {return d.nodelineWidth;})
528-
.style('stroke', function(d) {return Color.tinyRGB(tinycolor(d.nodelineColor));})
529-
.style('stroke-opacity', function(d) {return Color.opacity(d.nodelineColor);})
541+
.style('stroke-width', function(d) {return d.nodeLineWidth;})
542+
.style('stroke', function(d) {return Color.tinyRGB(tinycolor(d.nodeLineColor));})
543+
.style('stroke-opacity', function(d) {return Color.opacity(d.nodeLineColor);})
530544
.style('fill', function(d) {return d.tinyColorHue;})
531545
.style('fill-opacity', function(d) {return d.tinyColorAlpha;});
532546

0 commit comments

Comments
 (0)