plotly.js theme / style extraction and application
See original GitHub issueinitial requirements
- Generic style only. Items that apply to any data setup such as trace color, size, background, and fonts are applied.
- The template data shall be stored without any design point data. For example, the x and y source data shall not be included. If an attribute such as color, size, or opacity is bound to a variable (has individual values), then the individual values will not be stored.
- The template shall be applied to an existing graph (a new graph is not generated).
- A mechanism shall be enabled through the API to report items from the template that do not apply. Example 1) The template has a different number of traces than the plot to which it is being applied. Example 2) The template is from a line plot and being applied to a heat map, therefore the point glyph cannot be applied.
cc @alexcjohnson @etpinard for implementation discussions
cc @chriddyp @sglyon for possible applications to and requirements of plotly.[py|jl]
and Dash
cc @nicolaskruchten @VeraZab for general input.
To get the conversation rolling how about I take a stab at an API:
const figureStyle = plotly.extractStyle(gd || {data, layout}, config)
const info = plotly.applyStyle(gd || {data, layout}, {figureStyle [, config]} [, config])
where info
is an object containing a subset of the structure in figureTheme
documenting each item that was not applied and possibly an optional reason
why it was not applied.
note: It would be great if this operation was immutable however point 3. requires mutation. Perhaps someone has suggestions for an API that allows both immutable application and mutation.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:23 (22 by maintainers)
Top Results From Across the Web
Adding CSS & JS and Overriding the Page-Load Template
Learn how to add custom CSS and JS to your app as well as how to customize the HTML title, meta tags, and...
Read more >Introducing plotly.py Theming - Medium
Create your own theme or use one of seven out-of-the-box themes that ship with plotly.py 3.4 (released today!). Mix, match, and merge themes...
Read more >React Plotly JS apply dark (plotly_dark) theme - Stack Overflow
The extracted template can then be used in a Javascript / React Plotly chart by assigning it to the layout.template property.
Read more >Plotting With Plotly in Python: Data Exploration Made Easy
In terms of abstraction, Cufflinks > Plotly > plotly.js > d3.js which means ... themes we can use to apply different styling with...
Read more >Tricks for Data visualization using Plotly Library
If you just want to embed charts in your blogs you don't need to have prior knowledge of coding or javascript you can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Plotly.extractStyle
looks great - I’m assumingconfig
is potential config for the extraction operation itself, as opposed to the plot config as innewPlot
? I might change the name toextractTemplate
ormakeTemplate
, which would accommodate future expansion beyond style information.I don’t think mutation itself (of
data
andlayout
) is a requirement, just the ability to update an existing plot (replacinggd.data
andgd.layout
)… so if we use:then we can follow it up with:
It’s less compact to apply the style this way, but it feels to me like it may be preferable as it would give the dev a chance to look at
info
and decide if the templating worked as intended before going ahead and plugging the result into the plot.I would assume referenced is better and omit cloning until someone explicitly asks.
Most of it was merged in https://github.com/plotly/plotly.js/pull/2761 and release in 1.39.0, but I suspect there’s a few open items remaining and @alexcjohnson wanted to keep this ticket open to track them.