Skip to content

Commit 0012fa1

Browse files
committed
make the opacity logic slightly more user-friendly by applying leaf.opacity instead of branch.opacity which also help having an API similar to sunburst
1 parent ca4b385 commit 0012fa1

14 files changed

+80
-48
lines changed

src/traces/treemap/attributes.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,9 @@ module.exports = {
145145
role: 'style',
146146
min: 0,
147147
max: 1,
148-
dflt: 1,
149148
description: [
150-
'Sets the opacity for the sectors. With colorscale',
151-
'it is defaulted to 1; otherwise it is defaulted to 0.5'
149+
'Sets the opacity of the branches i.e. based on the hierarchy height.',
150+
'With colorscale it is defaulted to 1; otherwise it is defaulted to 0.7'
152151
].join(' ')
153152
},
154153

@@ -162,16 +161,16 @@ module.exports = {
162161
})
163162
),
164163

165-
branch: {
164+
leaf: {
166165
opacity: {
167166
valType: 'number',
168167
editType: 'style',
169168
role: 'style',
170169
min: 0,
171170
max: 1,
171+
dflt: 1,
172172
description: [
173-
'Sets the opacity of the leaves i.e. based on the hierarchy height.',
174-
'With colorscale it is defaulted to 1; otherwise it is defaulted to 0.7'
173+
'Sets the opacity of the leaves.'
175174
].join(' ')
176175
},
177176
editType: 'plot'

src/traces/treemap/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8585
if(withColorscale) {
8686
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
8787
}
88-
coerce('marker.opacity');
89-
coerce('branch.opacity', withColorscale ? 1 : 0.7);
88+
coerce('marker.opacity', withColorscale ? 1 : 0.7);
89+
coerce('leaf.opacity');
9090

9191
traceOut._hovered = {
9292
marker: {

src/traces/treemap/style.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var d3 = require('d3');
1212
var Color = require('../../components/color');
1313
var Lib = require('../../lib');
14+
var helpers = require('../sunburst/helpers');
1415

1516
function style(gd) {
1617
gd._fullLayout._treemaplayer.selectAll('.trace').each(function(cd) {
@@ -42,7 +43,7 @@ function styleOne(s, pt, trace, opts) {
4243
} else {
4344
lineColor = Lib.castOption(trace, ptNumber, 'marker.line.color') || Color.defaultLine;
4445
lineWidth = Lib.castOption(trace, ptNumber, 'marker.line.width') || 0;
45-
opacity = trace.marker.opacity * Math.pow(trace.branch.opacity, pt.height);
46+
opacity = helpers.isLeaf(pt) ? trace.leaf.opacity : Math.pow(trace.marker.opacity, pt.height);
4647
}
4748

4849
s.style('stroke-width', lineWidth)
Loading
-174 Bytes
Loading
-3.52 KB
Loading
261 Bytes
Loading
355 Bytes
Loading

test/image/mocks/treemap_packages_colorscale_allone.json

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
{
22
"data": [
33
{
4-
"type": "treemap",
5-
"count": "leaves+branches",
4+
"type": "treemap",
5+
"count": "leaves+branches",
66
"maxdepth": 3,
7-
"textinfo": "label+percent parent",
8-
"tiling": {
7+
"textinfo": "label+percent parent",
8+
"tiling": {
99
"packing": "slice-dice"
1010
},
1111
"pathbar": {
1212
"side": "bottom"
13-
},
13+
},
1414
"marker": {
15-
"opacity": 0.8,
15+
"opacity": 0.9,
1616
"line": {
1717
"color": "#777"
1818
},
19-
"colorscale": [[0, "#FFF"], [0.01, "#FF0"], [0.1, "#F00"], [1, "#000"]],
19+
"colorscale": [
20+
[
21+
0,
22+
"#FFF"
23+
],
24+
[
25+
0.01,
26+
"#FF0"
27+
],
28+
[
29+
0.1,
30+
"#F00"
31+
],
32+
[
33+
1,
34+
"#000"
35+
]
36+
],
2037
"showscale": true
2138
},
2239
"level": "1. gl-mesh3d",

test/image/mocks/treemap_packings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"Uniform",
7373
"Uniform"
7474
],
75-
"branch": {
75+
"leaf": {
7676
"opacity": 0.85
7777
},
7878
"marker": {
@@ -162,7 +162,7 @@
162162
"Uniform",
163163
"Uniform"
164164
],
165-
"branch": {
165+
"leaf": {
166166
"opacity": 0.85
167167
},
168168
"marker": {
@@ -252,7 +252,7 @@
252252
"Uniform",
253253
"Uniform"
254254
],
255-
"branch": {
255+
"leaf": {
256256
"opacity": 0.85
257257
},
258258
"marker": {
@@ -342,7 +342,7 @@
342342
"Uniform",
343343
"Uniform"
344344
],
345-
"branch": {
345+
"leaf": {
346346
"opacity": 0.85
347347
},
348348
"marker": {
@@ -432,7 +432,7 @@
432432
"Uniform",
433433
"Uniform"
434434
],
435-
"branch": {
435+
"leaf": {
436436
"opacity": 0.85
437437
},
438438
"marker": {
@@ -522,7 +522,7 @@
522522
"Uniform",
523523
"Uniform"
524524
],
525-
"branch": {
525+
"leaf": {
526526
"opacity": 0.85
527527
},
528528
"marker": {

0 commit comments

Comments
 (0)