MCPcopy Create free account
hub / github.com/alceal/plotlars / to_json

Method to_json

crates/plotlars-plotly/src/subplot_grid/mod.rs:155–174  ·  view source on GitHub ↗

Serialize the subplot grid to a JSON string.

(&self)

Source from the content-addressed store, hash-verified

153
154 /// Serialize the subplot grid to a JSON string.
155 pub fn to_json(&self) -> Result<String, serde_json::Error> {
156 let layout_val = self
157 .layout_json
158 .as_ref()
159 .cloned()
160 .unwrap_or_else(|| serde_json::to_value(&self.layout).unwrap_or(Value::Null));
161 let traces_json: Vec<Value> = self
162 .traces
163 .iter()
164 .map(|t| {
165 let s = t.to_json();
166 serde_json::from_str(&s).unwrap_or(Value::Null)
167 })
168 .collect();
169 let output = serde_json::json!({
170 "traces": traces_json,
171 "layout": layout_val,
172 });
173 serde_json::to_string(&output)
174 }
175
176 /// Render the subplot grid as a standalone HTML string.
177 pub fn to_html(&self) -> String {

Callers 3

to_htmlMethod · 0.45
to_inline_htmlMethod · 0.45
ir_to_jsonFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected