Skip to content

Commit 1dff468

Browse files
committed
handle special root color case
1 parent 3b104b1 commit 1dff468

15 files changed

+33
-31
lines changed

src/traces/treemap/style.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -36,56 +36,58 @@ function styleOne(s, pt, trace, opts) {
3636
var lineColor;
3737
var lineWidth;
3838
var fillColor = cdi.color;
39+
var isRoot = helpers.isHierarchyRoot(pt);
40+
var opacity = 1;
3941

4042
if(hovered) {
4143
lineColor = trace._hovered.marker.line.color;
4244
lineWidth = trace._hovered.marker.line.width;
4345
} else {
44-
var isRoot = helpers.isHierarchyRoot(pt);
46+
if(isRoot && fillColor === 'rgba(0,0,0,0)') {
47+
opacity = 0;
48+
lineColor = 'rgba(0,0,0,0)';
49+
lineWidth = 0;
50+
} else {
51+
lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
52+
lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;
4553

46-
if(!trace._hasColorscale && !pt.onPathbar) {
47-
var depthfade = trace.marker.depthfade;
48-
if(depthfade) {
49-
var fadedColor = Color.combine(Color.addOpacity(trace._backgroundColor, 0.75), fillColor);
50-
var n;
54+
if(!trace._hasColorscale && !pt.onPathbar) {
55+
var depthfade = trace.marker.depthfade;
56+
if(depthfade) {
57+
var fadedColor = Color.combine(Color.addOpacity(trace._backgroundColor, 0.75), fillColor);
58+
var n;
5159

52-
if(depthfade === true) {
53-
var maxDepth = helpers.getMaxDepth(trace);
54-
if(isFinite(maxDepth)) {
55-
if(helpers.isLeaf(pt)) {
56-
n = 0;
60+
if(depthfade === true) {
61+
var maxDepth = helpers.getMaxDepth(trace);
62+
if(isFinite(maxDepth)) {
63+
if(helpers.isLeaf(pt)) {
64+
n = 0;
65+
} else {
66+
n = (trace._maxVisibleLayers) - (pt.data.depth - trace._entryDepth);
67+
}
5768
} else {
58-
n = (trace._maxVisibleLayers) - (pt.data.depth - trace._entryDepth);
69+
n = pt.data.height + 1;
5970
}
60-
} else {
61-
n = pt.data.height + 1;
71+
} else { // i.e. case of depthfade === 'reversed'
72+
n = pt.data.depth - trace._entryDepth;
73+
if(!trace._atRootLevel) n++;
6274
}
63-
} else { // i.e. case of depthfade === 'reversed'
64-
n = pt.data.depth - trace._entryDepth;
65-
if(!trace._atRootLevel) n++;
66-
}
6775

68-
if(n > 0) {
69-
for(var i = 0; i < n; i++) {
70-
var ratio = 0.5 * i / n;
71-
fillColor = Color.combine(Color.addOpacity(fadedColor, ratio), fillColor);
76+
if(n > 0) {
77+
for(var i = 0; i < n; i++) {
78+
var ratio = 0.5 * i / n;
79+
fillColor = Color.combine(Color.addOpacity(fadedColor, ratio), fillColor);
80+
}
7281
}
7382
}
7483
}
7584
}
76-
77-
if(isRoot) {
78-
lineColor = 'rgba(0,0,0,0)';
79-
lineWidth = 0;
80-
} else {
81-
lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
82-
lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;
83-
}
8485
}
8586

8687
s.style('stroke-width', lineWidth)
8788
.call(Color.fill, fillColor)
88-
.call(Color.stroke, lineColor);
89+
.call(Color.stroke, lineColor)
90+
.style('opacity', opacity);
8991
}
9092

9193
module.exports = {
54 Bytes
Loading
71 Bytes
Loading
Loading
Loading
-15 Bytes
Loading
2.68 KB
Loading
1.24 KB
Loading
Loading
-21 Bytes
Loading
202 Bytes
Loading
-1.43 KB
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)