Skip to content

Commit 66c6730

Browse files
committed
can reuse treemp/draw_ancestors and sunburt/style
1 parent b3c9c08 commit 66c6730

File tree

3 files changed

+8
-221
lines changed

3 files changed

+8
-221
lines changed

src/traces/icicle/draw_ancestors.js

Lines changed: 0 additions & 162 deletions
This file was deleted.

src/traces/icicle/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var clearMinTextSize = uniformText.clearMinTextSize;
1414
var resizeText = require('../bar/style').resizeText;
1515
var constants = require('./constants');
1616
var drawDescendants = require('./draw_descendants');
17-
var drawAncestors = require('./draw_ancestors');
17+
var drawAncestors = require('../treemap/draw_ancestors');
1818

1919
module.exports = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {
2020
var fullLayout = gd._fullLayout;

src/traces/icicle/style.js

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
var d3 = require('@plotly/d3');
44
var Color = require('../../components/color');
55
var Lib = require('../../lib');
6-
var helpers = require('../sunburst/helpers');
76
var resizeText = require('../bar/uniform_text').resizeText;
87

98
function style(gd) {
@@ -18,72 +17,22 @@ function style(gd) {
1817
gTrace.style('opacity', trace.opacity);
1918

2019
gTrace.selectAll('path.surface').each(function(pt) {
21-
d3.select(this).call(styleOne, pt, trace, {
22-
hovered: false
23-
});
20+
d3.select(this).call(styleOne, pt, trace);
2421
});
2522
});
2623
}
2724

28-
function styleOne(s, pt, trace, opts) {
29-
var hovered = (opts || {}).hovered;
25+
function styleOne(s, pt, trace) {
3026
var cdi = pt.data.data;
27+
var isLeaf = !pt.children;
3128
var ptNumber = cdi.i;
32-
var lineColor;
33-
var lineWidth;
34-
var fillColor = cdi.color;
35-
var isRoot = helpers.isHierarchyRoot(pt);
36-
var opacity = 1;
37-
38-
if(hovered) {
39-
lineColor = trace._hovered.marker.line.color;
40-
lineWidth = trace._hovered.marker.line.width;
41-
} else {
42-
if(isRoot && fillColor === trace.root.color) {
43-
opacity = 100;
44-
lineColor = 'rgba(0,0,0,0)';
45-
lineWidth = 0;
46-
} else {
47-
lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
48-
lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;
49-
50-
if(!trace._hasColorscale && !pt.onPathbar) {
51-
var depthfade = trace.marker.depthfade;
52-
if(depthfade) {
53-
var fadedColor = Color.combine(Color.addOpacity(trace._backgroundColor, 0.75), fillColor);
54-
var n;
55-
56-
if(depthfade === true) {
57-
var maxDepth = helpers.getMaxDepth(trace);
58-
if(isFinite(maxDepth)) {
59-
if(helpers.isLeaf(pt)) {
60-
n = 0;
61-
} else {
62-
n = (trace._maxVisibleLayers) - (pt.data.depth - trace._entryDepth);
63-
}
64-
} else {
65-
n = pt.data.height + 1;
66-
}
67-
} else { // i.e. case of depthfade === 'reversed'
68-
n = pt.data.depth - trace._entryDepth;
69-
if(!trace._atRootLevel) n++;
70-
}
71-
72-
if(n > 0) {
73-
for(var i = 0; i < n; i++) {
74-
var ratio = 0.5 * i / n;
75-
fillColor = Color.combine(Color.addOpacity(fadedColor, ratio), fillColor);
76-
}
77-
}
78-
}
79-
}
80-
}
81-
}
29+
var lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
30+
var lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;
8231

8332
s.style('stroke-width', lineWidth)
84-
.call(Color.fill, fillColor)
33+
.call(Color.fill, cdi.color)
8534
.call(Color.stroke, lineColor)
86-
.style('opacity', opacity);
35+
.style('opacity', isLeaf ? trace.leaf.opacity : null);
8736
}
8837

8938
module.exports = {

0 commit comments

Comments
 (0)