Skip to content

Commit 4e3b7f3

Browse files
committed
address various treemap transition case e.g. maxdepth, tweening and pathbar position
- i.e. with the help of etpinard - make treemap transition NOT depend on "clicked" stash - during exit transitions, look for previous coords of current entry node, which corresponds to the last "clicked" node when zooming in - during update transition of new pts, look for "next" coords of previous entry node, corresponding to a zoom out interaction - extract "find closest edge" logic from `getOrgin` into own function - compute nextOfPrevEntry after partition is computed - display pathbar outside trace domain - dont draw empty rectangles as lines
1 parent 19c7a61 commit 4e3b7f3

22 files changed

+220
-253
lines changed

src/traces/sunburst/fx.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,7 @@ module.exports = function attachFxHandlers(sliceTop, entry, gd, cd, opts) {
263263
});
264264

265265
var id = helpers.getPtId(pt);
266-
var isEntry = helpers.isEntry(pt);
267-
268-
if(isTreemap) {
269-
var zoomOut = true;
270-
var redirectId = pt._redirect;
271-
if(redirectId === undefined) {
272-
redirectId = id;
273-
if(!isEntry) zoomOut = false;
274-
}
275-
276-
traceNow._clickedInfo = {
277-
id: redirectId,
278-
zoomOut: zoomOut
279-
};
280-
}
281-
282-
var nextEntry = isEntry ?
266+
var nextEntry = helpers.isEntry(pt) ?
283267
helpers.findEntryWithChild(hierarchy, id) :
284268
helpers.findEntryWithLevel(hierarchy, id);
285269

src/traces/sunburst/helpers.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,6 @@ exports.findEntryWithChild = function(hierarchy, childId) {
4242
return out || hierarchy;
4343
};
4444

45-
exports.findChildPt = function(hierarchy, childId) {
46-
var out = {};
47-
hierarchy.eachAfter(function(pt) {
48-
var children = pt.children || [];
49-
for(var i = 0; i < children.length; i++) {
50-
var child = children[i];
51-
if(exports.getPtId(child) === childId) {
52-
out = {
53-
x0: child.x0,
54-
x1: child.x1,
55-
y0: child.y0,
56-
y1: child.y1,
57-
};
58-
}
59-
}
60-
});
61-
return out;
62-
};
63-
6445
exports.isEntry = function(pt) {
6546
return !pt.parent;
6647
};

src/traces/treemap/draw_ancestors.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {
6969
pt.y0 = barDifY + 0;
7070
pt.y1 = barDifY + height;
7171

72-
pt._redirect = entry.data.id;
73-
7472
return true;
7573
});
7674

src/traces/treemap/draw_descendants.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
3434
var handleSlicesExit = opts.handleSlicesExit;
3535
var makeUpdateSliceInterpolator = opts.makeUpdateSliceInterpolator;
3636
var makeUpdateTextInterpolator = opts.makeUpdateTextInterpolator;
37+
var prevEntry = opts.prevEntry;
3738
var refRect = {};
3839

3940
var fullLayout = gd._fullLayout;
@@ -62,17 +63,17 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
6263
}
6364
});
6465

65-
var getRefRect = function() {
66-
if(!trace._clickedInfo) return refRect;
67-
return helpers.findChildPt(allData, trace._clickedInfo.id);
68-
};
69-
7066
var sliceData = allData.descendants();
7167

72-
// filter out slices that won't show up on graph
73-
sliceData = sliceData.filter(function(pt) { return pt.depth < trace._maxDepth; });
68+
slices = slices.data(sliceData, function(pt) {
69+
// hide slices that won't show up on graph
70+
if(pt.depth >= trace._maxDepth) {
71+
pt.x0 = pt.x1 = (pt.x0 + pt.x1) / 2;
72+
pt.y0 = pt.y1 = (pt.y0 + pt.y1) / 2;
73+
}
7474

75-
slices = slices.data(sliceData, function(pt) { return helpers.getPtId(pt); });
75+
return helpers.getPtId(pt);
76+
});
7677

7778
slices.enter().append('g')
7879
.classed('slice', true);
@@ -81,6 +82,31 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
8182

8283
slices.order();
8384

85+
// next coords of previous entry
86+
var nextOfPrevEntry = null;
87+
if(hasTransition && prevEntry) {
88+
var prevEntryId = helpers.getPtId(prevEntry);
89+
slices.each(function(pt) {
90+
if(nextOfPrevEntry === null && (helpers.getPtId(pt) === prevEntryId)) {
91+
nextOfPrevEntry = {
92+
x0: pt.x0,
93+
x1: pt.x1,
94+
y0: pt.y0,
95+
y1: pt.y1
96+
};
97+
}
98+
});
99+
}
100+
101+
var getRefRect = function() {
102+
return nextOfPrevEntry || {
103+
x0: 0,
104+
x1: width,
105+
y0: 0,
106+
y1: height
107+
};
108+
};
109+
84110
var updateSlices = slices;
85111
if(hasTransition) {
86112
updateSlices = updateSlices.transition().each('end', function() {
@@ -177,4 +203,6 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
177203
sliceText.attr('transform', strTransform(pt));
178204
}
179205
});
206+
207+
return nextOfPrevEntry;
180208
};

0 commit comments

Comments
 (0)