Render plot JSON to an inline HTML snippet.
(plot_json: &str, div_id: &str)
| 49 | |
| 50 | /// Render plot JSON to an inline HTML snippet. |
| 51 | pub(crate) fn render_inline_html_from_json(plot_json: &str, div_id: &str) -> String { |
| 52 | format!( |
| 53 | r#"<div id="{div_id}" class="plotly-graph-div" style="height:100%; width:100%;"></div> |
| 54 | <script type="text/javascript"> |
| 55 | var plotData = {plot_json}; |
| 56 | Plotly.newPlot("{div_id}", plotData.traces, plotData.layout, {{}}); |
| 57 | </script>"#, |
| 58 | div_id = div_id, |
| 59 | plot_json = plot_json |
| 60 | ) |
| 61 | } |
| 62 | |
| 63 | pub(crate) fn ir_to_json(data: &impl Plot) -> Result<String, serde_json::Error> { |
| 64 | let (layout, layout_overrides) = crate::converters::layout::convert_layout_ir(data.ir_layout()); |