Repository navigation
initial implementation of layout.colorscale - #3274
Conversation
| coerce('colorscale.sequential'); | ||
| coerce('colorscale.sequentialminus'); | ||
| coerce('colorscale.diverging'); | ||
| if(layoutIn.colorscale) { |
There was a problem hiding this comment.
Coercing valType: colorScale will always give it a default colorscale. I initially wanted it to be falsey if not set by the user. There are other ways to do that.
| editType: 'calc', | ||
| description: 'Sets the default trace colors.' | ||
| }, | ||
| colorscale: { |
There was a problem hiding this comment.
Let's put these new attributes and default logic in the Colorscale component module.
Create two new files:
- src/components/colorscale/layout_attributes.js
- src/components/colorscale/layout_defaults.js
and link their exports in src/components/colorscale/index.js as layoutAttributes and supplyLayoutDefaults. The latter will get automatically picked up in Plotly.supplyLayoutModuleDefaults here:
Lines 1512 to 1518 in 695f311
| colorscale: { | ||
| sequential: { | ||
| valType: 'colorscale', | ||
| dflt: false, |
There was a problem hiding this comment.
What would happen if we set dflt: scales.RdBu ?
There was a problem hiding this comment.
That's another way of doing it and I think it's much better than the current approach. We'd have the defaults clearly defined in the attributes where they should be 🎉
| containerOut.sequentialminus = layoutColorscale.sequentialminus; | ||
| var dfltScl = containerOut.diverging; | ||
| var sclOut; | ||
| if(dfltScl) sclOut = coerce(prefix + 'colorscale', dfltScl); |
There was a problem hiding this comment.
Ha I see. We wouldn't need this extra if-else block if you made the layout.colorscale.*.dflt undefined (or removed them entirely) instead of false. The relevant line in coerce.js is:
Line 384 in 695f311
There was a problem hiding this comment.
... But looking at this again, do we really need logic in colorscale/defaults.js and in colorscale/calc.js?
Ideally,
- I would leave colorscale/defaults.js untouched
- make the
layout.colorscale.*.dfltmatchscales.RdBu,scales.Redsandscales.Blues, making thosecontainer.diverging || scales.RdBu;in colorscale/calc.js unnecessary. - handle the autocolorscale logic in colorscale/calc.js
Now, I'm just thinking out-loud. @antoinerg let me know if my proposal has any flaws.
There was a problem hiding this comment.
I think this makes a lot of sense. Let me rework this PR!
|
Commit 93ce241 refactors I still need to improve test coverage to make sure |
|
Commit ee222d5 improves the test coverage! |
| // auto-z and autocolorscale if applicable | ||
| if(hasColorscale(trace, 'marker')) { | ||
| colorscaleCalc(trace, trace.marker.color, 'marker', 'c'); | ||
| colorscaleCalc(gd, trace, { |
| if(min * max < 0) scl = scales.RdBu; | ||
| else if(min >= 0) scl = scales.Reds; | ||
| else scl = scales.Blues; | ||
| if(min * max < 0) scl = gd._fullLayout.colorscale.diverging; |
There was a problem hiding this comment.
minor 🐄 , usually when a method uses fullLayout from gd we put a
var fullLayout = gd._fullLayout;just below the function (
|
Nicely done @antoinerg Since this PR will mostly help out template users, we should add a JSON mock that uses one of the new attribute in a template. |
| "template": { | ||
| "layout": { | ||
| "title": "heatmap template", | ||
| "colorscale": { |
There was a problem hiding this comment.
What if we put autocolorscale: true in the template container, does it still work?
There was a problem hiding this comment.
Good call! I modified the mock in dca4350
|
Nicely done 💃 |
Attempt at closing #2925. As far as I can tell it works well but test coverage is pretty minimal at the moment.
In the process of making this PR, I uncovered issue #3273 .