Skip to content

Handle invalid entry during treemap plot #4312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/traces/treemap/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ function plotOne(gd, cd, element, transitionOpts) {
var cd0 = cd[0];
var trace = cd0.trace;
var hierarchy = cd0.hierarchy;
var hasTransition = helpers.hasTransition(transitionOpts);
var entry = helpers.findEntryWithLevel(hierarchy, trace.level);

var gTrace = d3.select(element);
var selAncestors = gTrace.selectAll('g.pathbar');
var selDescendants = gTrace.selectAll('g.slice');

if(!entry) {
selAncestors.remove();
selDescendants.remove();
return;
}

var isRoot = helpers.isHierarchyRoot(entry);
var hasTransition = helpers.hasTransition(transitionOpts);

var maxDepth = helpers.getMaxDepth(trace);
var hasVisibleDepth = function(pt) {
Expand Down Expand Up @@ -517,16 +528,6 @@ function plotOne(gd, cd, element, transitionOpts) {
});
};

var gTrace = d3.select(element);
var selAncestors = gTrace.selectAll('g.pathbar');
var selDescendants = gTrace.selectAll('g.slice');

if(!entry) {
selAncestors.remove();
selDescendants.remove();
return;
}

if(hasTransition) {
// Important: do this before binding new sliceData!

Expand Down
23 changes: 23 additions & 0 deletions test/jasmine/tests/treemap_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,29 @@ describe('Test treemap calc:', function() {
});
});

describe('Test treemap plot:', function() {
var gd;

beforeEach(function() { gd = createGraphDiv(); });

afterEach(destroyGraphDiv);

it('should return early from the plot when there is no entry', function(done) {
Plotly.plot(gd, [{
labels: ['a', 'b'],
parents: ['A', 'B'],
type: 'treemap'
}])
.then(function() {
var gd3 = d3.select(gd);
var element = gd3.select('.treemap trace').node();
expect(element).toBe(null);
})
.catch(failTest)
.then(done);
});
});

describe('Test treemap hover:', function() {
var gd;

Expand Down