Impl Serialize for Plot
mfreeborn opened this issue · comments
Currently, Plot::to_json()
produces the Plot JSON object partly by hand. I suggest that Plot
derives serde::Serialize
, which is possible if we constrain Trace
with erased_serde::Serialize
.
In doing so, I've renamed the helped method serialize
on Trace
to to_json()
so that it doens't clash with the serde::Serialize
trait. I've also removed the impl of Trace
for Layout
because it a) it isn't really used apart from a very thin wrapper over serde_json::to_string()
, and b) it doesn't quite make sense for Layout
to be a Trace
.
I'll add a quick PR to show how it looks.
In the same PR, I've also submitted a suggestion for being able to access and serialize the traces
and layout
fields separately. The reason for this is because it is useful to be able to access them separately when calling certain plotly functions or, in plot.rs
, the render_plot_data
method.
I've called the method data
, rather than traces
, because the plotly.js library uses the term data
itself.