New call signature for Plotly.plot
See original GitHub issueProblem: Frames cannot be passed to the initial call to Plotly.plot
. I don’t think breaking changes are required to change that fact, so this might be nice before it’s integrated in a bunch of different places. You also have to unpack plotly JSON data that almost certainly has the format:
{
"data": [],
"layout": {},
"config": {},
"frames": []
}
(Note: config is not fully serializable)
Currently to create a plot, you must run
Plotly.plot(gd, d.data, d.layout, d.config).then(function() {
return Plotly.addFrames(gd, d.frames);
});
Possible solutions
It’s not bad, but the extra step seems unnecessary. Alternate proposed forms that could be implemented without breaking changes by overloading Plotly.plot
:
Plotly.plot(gd, d.data, d.layout, d.config, d.frames);
Frames could simply be appended, though config seems nice as a final argument. Switching the last two arguments:
Plotly.plot(gd, d.data, d.layout, d.frames, d.config);
This case could be distinguished from the current form by the presence of an Array-typed fourth argument.
Taking a different approach and passing a single object:
Plotly.plot({
container: gd,
data: [],
layout: {},
config: {},
frames: []
});
Except neither gd
nor config
are serializable, in general. Extracting the gd
part, we get:
Plotly.plot(gd, {
data: [],
layout: {},
config: {},
frames: []
});
I rather like this final form since with some non-serializable exceptions in config
(specifics?), you could simply pass fetched data toPlotly.plot
in one go, i.e.:
fetch('path/to/my/data.json').then(function(d) {
Plotly.plot(gd, d);
});
Which is nice and short, but then at the end of all of this, the conclusion is that this all exists only to save a bit of typing. I think it’s still worth discussing though since it seems sub-ideal that you can’t fully pass data (missing: frames) to a plot in a single command.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:12 (12 by maintainers)
Top GitHub Comments
closed by https://github.com/plotly/plotly.js/pull/1054
@monfera yeah, was at least thinking it would auto-append a
div
todocument.body
and then only operate on the div.