Pass more data to sunburst color method to allow greater customization and consistency#1677
Pass more data to sunburst color method to allow greater customization and consistency#1677manbearwiz wants to merge 1 commit intonovus:masterfrom manbearwiz:manbearwiz-sunburst-color
Conversation
This fix passes the entire data object and index into the color function rather than just the name. In addition to to allowing more intelligent color functions, this change makes the API more consistent with the pie chart. BREAKING CHANGE: Any existing sunburst chart that uses a custom color function will need to be updated to the new api; however, the name is still passed to this function as an attribute of the object.
| } | ||
| else { | ||
| return color(d.name); | ||
| return color(d, i); |
There was a problem hiding this comment.
The default color function is nv.utils.defaultColor, which uses nv.utils.getColor which has a definition of just function(color). While it might work, it's going to hash a whole object every time, which is going to end up generating different colors if the data structure is modified.
Why would you be changing/duplicating the name attribute anyway? If you really have to do that, then I suggest putting a unique number on the end of the name and then strip it off with a custom tooltip.headerFormatter option
|
This change make it consistent with the pie chart. Correct me if I'm wrong, but any disadvantage to this implementation would already be evident on the pie chart then. From pie.js: My general use case is to pass in objects like and then use a d3 linear color scale to color segments by the temp field. Any suggestions on a better way to achieve this then passing that object into the color function? |
|
I'll have to think about this one, I don't much care for passing in objects as keys but it would be nice to be able to reference the full object too... |
This fix passes the entire data object and index into the color function rather than just the name. In addition to to allowing more intelligent color functions, this change makes the API more consistent with the pie chart.
The motivation for this change is to be able to use an attribute of the data passed in to generate the fill colors for the sections in order to signify intensity.
BREAKING CHANGE:
Any existing sunburst chart that uses a custom color function will need to be updated to the new API; however, the name is still passed to this function as an attribute of the object. Migration is as simple as changing
to
I would also like to note that in the current state, it seems unlikely anyone would be using a node name to do any sort of color calculation/generation.