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

Function ir_to_json

crates/plotlars-plotly/src/render/mod.rs:63–97  ·  view source on GitHub ↗
(data: &impl Plot)

Source from the content-addressed store, hash-verified

61}
62
63pub(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());
65 let traces: Vec<Box<dyn Trace + 'static>> = data
66 .ir_traces()
67 .iter()
68 .map(crate::converters::trace::convert)
69 .collect();
70
71 let mut layout_json = serde_json::to_value(&layout)?;
72
73 // Merge layout overrides (scene/polar domain entries) into the layout JSON
74 if let Some(ref overrides) = layout_overrides {
75 if let (Some(layout_map), Some(overrides_obj)) =
76 (layout_json.as_object_mut(), overrides.as_object())
77 {
78 for (key, value) in overrides_obj {
79 layout_map.insert(key.clone(), value.clone());
80 }
81 }
82 }
83
84 let traces_json: Vec<Value> = traces
85 .iter()
86 .map(|t| {
87 let serialized = t.to_json();
88 serde_json::from_str(&serialized).unwrap_or(Value::Null)
89 })
90 .collect();
91
92 let output = serde_json::json!({
93 "traces": traces_json,
94 "layout": layout_json,
95 });
96 serde_json::to_string(&output)
97}
98
99/// Helper function to open an HTML file in the default browser
100pub(crate) fn open_html_file(path: &std::path::Path) {

Callers 6

plotMethod · 0.85
write_htmlMethod · 0.85
to_jsonMethod · 0.85
to_htmlMethod · 0.85
to_inline_htmlMethod · 0.85
to_json_valueFunction · 0.85

Calls 4

convert_layout_irFunction · 0.85
ir_layoutMethod · 0.45
ir_tracesMethod · 0.45
to_jsonMethod · 0.45

Tested by

no test coverage detected