-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treemap new trace type #4185
Treemap new trace type #4185
Conversation
… option to count branches - revise descriptions and editTypes
now no need to include empty string to hide last label on the barpath
src/traces/treemap/attributes.js
Outdated
].join(' ') | ||
}, | ||
|
||
opacity: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse sunburstAttrs.marker.opacity
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sunburst
does not have a marker.opacity
attribute. But we can reuse marker.line
and marker.colors
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 6dad958.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the info.
Now I see that marker.opacity
can multiply branch.opacity
:
plotly.js/src/traces/treemap/style.js
Line 43 in eb54f24
opacity = trace.marker.opacity * Math.pow(trace.branch.opacity, pt.height); |
That's interesting, but wouldn't having marker.opacity
(when set) override branch.opacity
be more user friendly in your mind? In particular, if we allow marker.opacity
to be arrayOk
, this could allow users to set the opacity of a sector pretty easily.
What do you think @archmoj ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very good call!
It helped me rethink a couple of things in 0012fa1.
Now the API is more similar to sunburst
where both have a leaf.opacity
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marker.depthfade
?
It also occurs to me that opacity might not actually be quite the effect we want - perhaps it would be better to use the opaque color that would result from blending the marker color with the background color in the same proportion? For the bottom-most layer the effect is equivalent, but anything stacked above it currently effectively is more opaque (if the two colors are the same) or blended to a different color (if using a colorscale or explicit colors). Both of these I think are problematic:
- if the color has meaning, a faded version of that color is probably still easy to mentally connect with the original, keeping its interpretation the same, but a version blended with a different color could shift the implied meaning of that color.
- making stacked layers more opaque kind of defeats the purpose - it means that the final effective opacity drops off too slowly at first, then more quickly toward the back of the stack.
Anyway if we extend the analogy I mentioned this morning of "looking at layers of hills in the distance" - those hills are not transparent, they are faded by the air in front of them - which is exactly the same effect as blending with the background color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcjohnson Thanks very much for the feedback. Is there a place in plotly.js code that a similar colour blending is applied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look for color.combine
plotly.js/src/components/color/index.js
Lines 46 to 62 in 56f6983
color.combine = function(front, back) { | |
var fc = tinycolor(front).toRgb(); | |
if(fc.a === 1) return tinycolor(front).toRgbString(); | |
var bc = tinycolor(back || background).toRgb(); | |
var bcflat = bc.a === 1 ? bc : { | |
r: 255 * (1 - bc.a) + bc.r * bc.a, | |
g: 255 * (1 - bc.a) + bc.g * bc.a, | |
b: 255 * (1 - bc.a) + bc.b * bc.a | |
}; | |
var fcflat = { | |
r: bcflat.r * (1 - fc.a) + fc.r * fc.a, | |
g: bcflat.g * (1 - fc.a) + fc.g * fc.a, | |
b: bcflat.b * (1 - fc.a) + fc.b * fc.a | |
}; | |
return tinycolor(fcflat).toRgbString(); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New attempt in 4c7a092 - which I'm a fan of 👌
.catch(failTest) | ||
.then(done); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO:
- add tests for
texttemplate
using @antoinerg 'scheckTextTemplate
wrapper - add tests for tweens either using @antoinerg 's
checkTransition
or using the same hack as insunburst_test.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the texttemplate
part is now done.
- do not display the edges of the empty root unless hovered - replace empty string with space to have better transitions
- add restyle tests for treemap opacities - fix style.js - add texttemplate jasmine test for treemap - add treemap tween interaction tests
test/jasmine/tests/sunburst_test.js
Outdated
@@ -507,7 +507,7 @@ describe('Test sunburst hover:', function() { | |||
curveNumber: 0, | |||
pointNumber: 0, | |||
label: 'Eve', | |||
parent: '' | |||
parent: '"root"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right. parents[0]
is ''
in the input trace, so I think we should honour that in the event data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK if we return an empty string here?
plotly.js/src/traces/sunburst/helpers.js
Line 154 in 217c0f4
return str === '' ? '"root"' : str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the side-effects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply getting blank string (nothing) referring to the dummy root label in hover; which I think is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8416883.
src/traces/sunburst/plot.js
Outdated
}; | ||
|
||
var getVal = function(d) { | ||
if(d.hasOwnProperty('hierarchy')) return d.hierarchy.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does d
get a hierarchy
key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here:
plotly.js/src/traces/treemap/plot.js
Lines 90 to 93 in 217c0f4
entry._parent = (numAncestors ? | |
ancestorNodes[numAncestors - 1] : | |
hierarchy // parent of root is itself | |
).data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 8416883.
src/traces/sunburst/plot.js
Outdated
Registry.call('animate', gd, frame, animOpts); | ||
}); | ||
} | ||
if(trace.type === 'treemap' && helpers.isHeader(pt, trace)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this if
block. Header nodes don't appear to call formatSliceLabel
from:
if(isHeader && noRoomForHeader) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... with the formatSliceLabel
below:
plotly.js/src/traces/treemap/draw_descendants.js
Lines 167 to 169 in 217c0f4
if(isHeader && noRoomForHeader) return; | |
var tx = formatSliceLabel(pt, entry, trace, cd, fullLayout) || ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Moved to treemap/draw_descendants.js
in 8416883.
The diff in Why can we just use plotly.js/src/traces/sunburst/plot.js Lines 495 to 511 in 217c0f4
juggling between We should try to find a better condition than plotly.js/src/traces/sunburst/plot.js Line 514 in 217c0f4
We never set It's probably better to check that the denominator is greater than plotly.js/src/traces/sunburst/plot.js Lines 518 to 521 in 217c0f4
instead of checking if the fraction is finite. I don't understand some of the differences between the logic in plotly.js/src/traces/sunburst/plot.js Line 620 in 217c0f4
vs plotly.js/src/traces/sunburst/fx.js Line 126 in 217c0f4
@archmoj can you explain why the "text" part appears more complicated than the "hover" part? |
- move treemap header checks from sunburst plot to treemap/draw_ancestors - cleanup dirty _parents and hierarchy links for pt - display blank label as blank
Thanks @archmoj - this looks much (much) better 😄 I have a few questions about this block: plotly.js/src/traces/sunburst/fx.js Lines 53 to 64 in 8416883
(and it's equivalent in
|
@etpinard |
Ok, this sounds right. Thanks! I think you could also use |
- add functions to get parents info above entry node - use computed d.value everywhere - add more jasmine tests to test percentgaes and current path at root and desired level
…nstead of pt.data.parent
src/traces/treemap/plot.js
Outdated
return x + ',' + y; | ||
} | ||
|
||
function noNaN(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etpinard it looks we don't need this extra check anymore.
Time to merge this thing. Amazing work @archmoj - sorry for being a little picky there that last two days. 💃 💃 💃 💃 💃 💃 To sum up, this PR:
|
Fix #1038.
This PR adds
treemap
traces toplotly.js
library.This new trace inherits various logic from the
plotly.js
code base and is quite similar to its brothersunburst
.Since
colorscale
and displayingcurrent path
& percentages were within the requirements for ourtreemap
, those features are also added tosunburst
. Also acount
attribute is added to both traces which allows counting the numbers ofleaves
,branches
or both whenvalues
array is not provided.One main extra feature of
treemap
is thebarpath
i.e. for displaying thecurrent path
of thevisible
portion of the hierarchical map. It may also be useful for zooming out of the graph.Codepens in addition to new
JSON
mocks added which could be displayed here!A
B
C
D
Please also note that commit 52ded31 touches on refactoring
base_plot
files of traces namelypie
,funnelarea
,indicator
and 'sunburst`.List of TODOs:
texttemplate
additions appear to be incomplete forpercentages
hovertemplate
may require improvement (or bypassing) when hovered onpathbar
elements.@plotly/plotly_js
@nicolaskruchten
@Mahdis-z