Skip to content

Commit eaad10d

Browse files
committed
reuse treemap draw in icicle
1 parent fdff0e7 commit eaad10d

File tree

3 files changed

+79
-124
lines changed

3 files changed

+79
-124
lines changed

src/traces/icicle/plot.js

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,11 @@
11
'use strict';
22

3-
var d3 = require('@plotly/d3');
4-
5-
var helpers = require('../sunburst/helpers');
6-
7-
var uniformText = require('../bar/uniform_text');
8-
var clearMinTextSize = uniformText.clearMinTextSize;
9-
var resizeText = require('../bar/style').resizeText;
3+
var draw = require('../treemap/draw');
104
var drawDescendants = require('./draw_descendants');
11-
var plotOne = require('../treemap/plot_one');
12-
var type = 'icicle';
135

146
module.exports = function _plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {
15-
var fullLayout = gd._fullLayout;
16-
var layer = fullLayout['_' + type + 'layer'];
17-
var join, onComplete;
18-
19-
// If transition config is provided, then it is only a partial replot and traces not
20-
// updated are removed.
21-
var isFullReplot = !transitionOpts;
22-
23-
clearMinTextSize(type, fullLayout);
24-
25-
join = layer.selectAll('g.trace.' + type)
26-
.data(cdmodule, function(cd) { return cd[0].trace.uid; });
27-
28-
join.enter().append('g')
29-
.classed('trace', true)
30-
.classed(type, true);
31-
32-
join.order();
33-
34-
if(!fullLayout.uniformtext.mode && helpers.hasTransition(transitionOpts)) {
35-
if(makeOnCompleteCallback) {
36-
// If it was passed a callback to register completion, make a callback. If
37-
// this is created, then it must be executed on completion, otherwise the
38-
// pos-transition redraw will not execute:
39-
onComplete = makeOnCompleteCallback();
40-
}
41-
42-
var transition = d3.transition()
43-
.duration(transitionOpts.duration)
44-
.ease(transitionOpts.easing)
45-
.each('end', function() { onComplete && onComplete(); })
46-
.each('interrupt', function() { onComplete && onComplete(); });
47-
48-
transition.each(function() {
49-
// Must run the selection again since otherwise enters/updates get grouped together
50-
// and these get executed out of order. Except we need them in order!
51-
layer.selectAll('g.trace').each(function(cd) {
52-
plotOne(gd, cd, this, transitionOpts, drawDescendants);
53-
});
54-
});
55-
} else {
56-
join.each(function(cd) {
57-
plotOne(gd, cd, this, transitionOpts, drawDescendants);
58-
});
59-
60-
if(fullLayout.uniformtext.mode) {
61-
resizeText(gd, layer.selectAll('.trace'), type);
62-
}
63-
}
64-
65-
if(isFullReplot) {
66-
join.exit().remove();
67-
}
7+
return draw(gd, cdmodule, transitionOpts, makeOnCompleteCallback, {
8+
type: 'icicle',
9+
drawDescendants: drawDescendants
10+
});
6811
};

src/traces/treemap/draw.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
var d3 = require('@plotly/d3');
4+
5+
var helpers = require('../sunburst/helpers');
6+
var uniformText = require('../bar/uniform_text');
7+
var clearMinTextSize = uniformText.clearMinTextSize;
8+
var resizeText = require('../bar/style').resizeText;
9+
10+
var plotOne = require('./plot_one');
11+
12+
module.exports = function _plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback, opts) {
13+
var type = opts.type;
14+
var drawDescendants = opts.drawDescendants;
15+
16+
var fullLayout = gd._fullLayout;
17+
var layer = fullLayout['_' + type + 'layer'];
18+
var join, onComplete;
19+
20+
// If transition config is provided, then it is only a partial replot and traces not
21+
// updated are removed.
22+
var isFullReplot = !transitionOpts;
23+
24+
clearMinTextSize(type, fullLayout);
25+
26+
join = layer.selectAll('g.trace.' + type)
27+
.data(cdmodule, function(cd) { return cd[0].trace.uid; });
28+
29+
join.enter().append('g')
30+
.classed('trace', true)
31+
.classed(type, true);
32+
33+
join.order();
34+
35+
if(!fullLayout.uniformtext.mode && helpers.hasTransition(transitionOpts)) {
36+
if(makeOnCompleteCallback) {
37+
// If it was passed a callback to register completion, make a callback. If
38+
// this is created, then it must be executed on completion, otherwise the
39+
// pos-transition redraw will not execute:
40+
onComplete = makeOnCompleteCallback();
41+
}
42+
43+
var transition = d3.transition()
44+
.duration(transitionOpts.duration)
45+
.ease(transitionOpts.easing)
46+
.each('end', function() { onComplete && onComplete(); })
47+
.each('interrupt', function() { onComplete && onComplete(); });
48+
49+
transition.each(function() {
50+
// Must run the selection again since otherwise enters/updates get grouped together
51+
// and these get executed out of order. Except we need them in order!
52+
layer.selectAll('g.trace').each(function(cd) {
53+
plotOne(gd, cd, this, transitionOpts, drawDescendants);
54+
});
55+
});
56+
} else {
57+
join.each(function(cd) {
58+
plotOne(gd, cd, this, transitionOpts, drawDescendants);
59+
});
60+
61+
if(fullLayout.uniformtext.mode) {
62+
resizeText(gd, layer.selectAll('.trace'), type);
63+
}
64+
}
65+
66+
if(isFullReplot) {
67+
join.exit().remove();
68+
}
69+
};

src/traces/treemap/plot.js

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,11 @@
11
'use strict';
22

3-
var d3 = require('@plotly/d3');
4-
5-
var helpers = require('../sunburst/helpers');
6-
7-
var uniformText = require('../bar/uniform_text');
8-
var clearMinTextSize = uniformText.clearMinTextSize;
9-
var resizeText = require('../bar/style').resizeText;
3+
var draw = require('./draw');
104
var drawDescendants = require('./draw_descendants');
11-
var plotOne = require('./plot_one');
12-
var type = 'treemap';
135

146
module.exports = function _plot(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {
15-
var fullLayout = gd._fullLayout;
16-
var layer = fullLayout['_' + type + 'layer'];
17-
var join, onComplete;
18-
19-
// If transition config is provided, then it is only a partial replot and traces not
20-
// updated are removed.
21-
var isFullReplot = !transitionOpts;
22-
23-
clearMinTextSize(type, fullLayout);
24-
25-
join = layer.selectAll('g.trace.' + type)
26-
.data(cdmodule, function(cd) { return cd[0].trace.uid; });
27-
28-
join.enter().append('g')
29-
.classed('trace', true)
30-
.classed(type, true);
31-
32-
join.order();
33-
34-
if(!fullLayout.uniformtext.mode && helpers.hasTransition(transitionOpts)) {
35-
if(makeOnCompleteCallback) {
36-
// If it was passed a callback to register completion, make a callback. If
37-
// this is created, then it must be executed on completion, otherwise the
38-
// pos-transition redraw will not execute:
39-
onComplete = makeOnCompleteCallback();
40-
}
41-
42-
var transition = d3.transition()
43-
.duration(transitionOpts.duration)
44-
.ease(transitionOpts.easing)
45-
.each('end', function() { onComplete && onComplete(); })
46-
.each('interrupt', function() { onComplete && onComplete(); });
47-
48-
transition.each(function() {
49-
// Must run the selection again since otherwise enters/updates get grouped together
50-
// and these get executed out of order. Except we need them in order!
51-
layer.selectAll('g.trace').each(function(cd) {
52-
plotOne(gd, cd, this, transitionOpts, drawDescendants);
53-
});
54-
});
55-
} else {
56-
join.each(function(cd) {
57-
plotOne(gd, cd, this, transitionOpts, drawDescendants);
58-
});
59-
60-
if(fullLayout.uniformtext.mode) {
61-
resizeText(gd, layer.selectAll('.trace'), type);
62-
}
63-
}
64-
65-
if(isFullReplot) {
66-
join.exit().remove();
67-
}
7+
return draw(gd, cdmodule, transitionOpts, makeOnCompleteCallback, {
8+
type: 'treemap',
9+
drawDescendants: drawDescendants
10+
});
6811
};

0 commit comments

Comments
 (0)