Serialize the subplot grid to a JSON string.
(&self)
| 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 { |
no outgoing calls
no test coverage detected