question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

plotly.js theme / style extraction and application

See original GitHub issue

initial requirements

  1. Generic style only. Items that apply to any data setup such as trace color, size, background, and fonts are applied.
  2. 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.
  3. The template shall be applied to an existing graph (a new graph is not generated).
  4. 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:23 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
alexcjohnsoncommented, Mar 13, 2018

Plotly.extractStyle looks great - I’m assuming config is potential config for the extraction operation itself, as opposed to the plot config as in newPlot? I might change the name to extractTemplate or makeTemplate, which would accommodate future expansion beyond style information.

I don’t think mutation itself (of data and layout) is a requirement, just the ability to update an existing plot (replacing gd.data and gd.layout)… so if we use:

// or Plotly.applyTemplate
const {info, figureWithStyle} = Plotly.applyStyle(gd || {data, layout}, {figureStyle [, config]} [, config])

then we can follow it up with:

Plotly.react(gd, figureWithStyle);

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.

The config can control whether the data arrays are cloned or referenced.

I would assume referenced is better and omit cloning until someone explicitly asks.

1reaction
etpinardcommented, Jul 23, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found