Render the subplot grid as a standalone HTML string.
(&self)
| 175 | |
| 176 | /// Render the subplot grid as a standalone HTML string. |
| 177 | pub fn to_html(&self) -> String { |
| 178 | let plot_json = self.to_json().unwrap(); |
| 179 | let escaped_json = plot_json |
| 180 | .replace('\\', "\\\\") |
| 181 | .replace('\'', "\\'") |
| 182 | .replace('\n', "\\n") |
| 183 | .replace('\r', "\\r"); |
| 184 | format!( |
| 185 | r#"<!DOCTYPE html> |
| 186 | <html> |
| 187 | <head> |
| 188 | <meta charset="utf-8" /> |
| 189 | <script src="https://cdn.plot.ly/plotly-3.0.1.min.js"></script> |
| 190 | </head> |
| 191 | <body> |
| 192 | <div id="plotly-div" style="width:100%;height:100%;"></div> |
| 193 | <script type="text/javascript"> |
| 194 | var plotData = JSON.parse('{}'); |
| 195 | Plotly.newPlot('plotly-div', plotData.traces, plotData.layout, {{responsive: true}}); |
| 196 | </script> |
| 197 | </body> |
| 198 | </html>"#, |
| 199 | escaped_json |
| 200 | ) |
| 201 | } |
| 202 | |
| 203 | /// Render the subplot grid as an inline HTML snippet (no DOCTYPE/head). |
| 204 | pub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String { |
no test coverage detected