Skip to content

Commit 84680ce

Browse files
committed
treemap fix 4308 - handle invalid entry in plot
1 parent 6c3646a commit 84680ce

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

Diff for: src/traces/treemap/plot.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,20 @@ function plotOne(gd, cd, element, transitionOpts) {
8282
var cd0 = cd[0];
8383
var trace = cd0.trace;
8484
var hierarchy = cd0.hierarchy;
85-
var hasTransition = helpers.hasTransition(transitionOpts);
8685
var entry = helpers.findEntryWithLevel(hierarchy, trace.level);
86+
87+
var gTrace = d3.select(element);
88+
var selAncestors = gTrace.selectAll('g.pathbar');
89+
var selDescendants = gTrace.selectAll('g.slice');
90+
91+
if(!entry) {
92+
selAncestors.remove();
93+
selDescendants.remove();
94+
return;
95+
}
96+
8797
var isRoot = helpers.isHierarchyRoot(entry);
98+
var hasTransition = helpers.hasTransition(transitionOpts);
8899

89100
var maxDepth = helpers.getMaxDepth(trace);
90101
var hasVisibleDepth = function(pt) {
@@ -517,16 +528,6 @@ function plotOne(gd, cd, element, transitionOpts) {
517528
});
518529
};
519530

520-
var gTrace = d3.select(element);
521-
var selAncestors = gTrace.selectAll('g.pathbar');
522-
var selDescendants = gTrace.selectAll('g.slice');
523-
524-
if(!entry) {
525-
selAncestors.remove();
526-
selDescendants.remove();
527-
return;
528-
}
529-
530531
if(hasTransition) {
531532
// Important: do this before binding new sliceData!
532533

Diff for: test/jasmine/tests/treemap_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,29 @@ describe('Test treemap calc:', function() {
561561
});
562562
});
563563

564+
describe('Test treemap plot:', function() {
565+
var gd;
566+
567+
beforeEach(function() { gd = createGraphDiv(); });
568+
569+
afterEach(destroyGraphDiv);
570+
571+
it('should return early from the plot when there is no entry', function(done) {
572+
Plotly.plot(gd, [{
573+
labels: ['a', 'b'],
574+
parents: ['A', 'B'],
575+
type: 'treemap'
576+
}])
577+
.then(function() {
578+
var gd3 = d3.select(gd);
579+
var element = gd3.select('.treemap trace').node();
580+
expect(element).toBe(null);
581+
})
582+
.catch(failTest)
583+
.then(done);
584+
});
585+
});
586+
564587
describe('Test treemap hover:', function() {
565588
var gd;
566589

0 commit comments

Comments
 (0)