Skip to content

Commit 364b429

Browse files
committed
sankey: warn user if node.pad is reduced to fit figure's size
1 parent 221d664 commit 364b429

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/traces/sankey/render.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ function sankeyModel(layout, d, traceIndex) {
148148
.links(links)
149149
.layout(c.sankeyIterations);
150150

151+
if(sankey.nodePadding() < nodePad) Lib.warn('node.pad was reduced to ', sankey.nodePadding(), ' to fit within the figure.')
152+
151153
var node, sankeyNodes = sankey.nodes();
152154
for(var n = 0; n < sankeyNodes.length; n++) {
153155
node = sankeyNodes[n];

test/jasmine/tests/sankey_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,27 @@ describe('sankey tests', function() {
771771
.then(done);
772772
});
773773
});
774+
775+
it('emits a warning if node.pad is too large', function(done) {
776+
var gd = createGraphDiv();
777+
var mockCopy = Lib.extendDeep({}, mock);
778+
779+
var warnings = [];
780+
spyOn(Lib, 'warn').and.callFake(function(msg) {
781+
warnings.push(msg);
782+
});
783+
Plotly.plot(gd, mockCopy).then(function() {
784+
expect(warnings.length).toEqual(0);
785+
786+
return Plotly.restyle(gd, 'node.pad', 50);
787+
})
788+
.then(function() {
789+
expect(warnings.length).toEqual(1);
790+
})
791+
.catch(failTest)
792+
.finally(destroyGraphDiv)
793+
.then(done);
794+
});
774795
});
775796

776797
function assertLabel(content, style) {

0 commit comments

Comments
 (0)