Skip to content

Commit a307331

Browse files
authored
Merge pull request #2017 from plotly/sankey-minimum-node-size
Sankey: render a thin but visible node even if `value` is very low
2 parents f81ca4d + 91e404c commit a307331

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/traces/sankey/render.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function nodeModel(uniqueKeys, d, n) {
182182
zoneThicknessPad = c.nodePadAcross,
183183
zoneLengthPad = d.nodePad / 2,
184184
visibleThickness = n.dx + 0.5,
185-
visibleLength = n.dy - 0.5;
185+
visibleLength = Math.max(1, n.dy - 0.5);
186186

187187
var basicKey = n.label;
188188
var foundKey = uniqueKeys[basicKey];

test/jasmine/tests/sankey_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,29 @@ describe('sankey tests', function() {
347347
done();
348348
});
349349
});
350+
351+
it('\'node\' remains visible even if \'value\' is very low', function(done) {
352+
353+
var gd = createGraphDiv();
354+
var minimock = [{
355+
type: 'sankey',
356+
node: {
357+
label: ['a', 'b1', 'b2']
358+
},
359+
link: {
360+
source: [0, 0],
361+
target: [1, 2],
362+
value: [1000000, 0.001]
363+
}
364+
}];
365+
Plotly.plot(gd, minimock)
366+
.then(function() {
367+
expect(d3.selectAll('.sankey .nodeRect')[0].reduce(function(prevMin, rect) {
368+
return Math.min(prevMin, d3.select(rect).attr('height'));
369+
}, Infinity)).toEqual(1);
370+
done();
371+
});
372+
});
350373
});
351374

352375
describe('Test hover/click interactions:', function() {

0 commit comments

Comments
 (0)