Skip to content
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