mdbook_plotly/code_handler/plot_obj_parser/
candlestick_parser.rs1use super::until::{Map, must_translate};
2use crate::{translate, translate_enum};
3use anyhow::Result;
4use plotly::Candlestick;
5
6pub fn parse_candlestick_data(
7 cs_obj: &mut serde_json::Value,
8 map: &Map,
9) -> Result<Box<Candlestick<String, f64>>> {
10 let x: Vec<String> = must_translate(cs_obj, map, "x")?;
11 let open: Vec<f64> = must_translate(cs_obj, map, "open")?;
12 let high: Vec<f64> = must_translate(cs_obj, map, "high")?;
13 let low: Vec<f64> = must_translate(cs_obj, map, "low")?;
14 let close: Vec<f64> = must_translate(cs_obj, map, "close")?;
15 let cs = Candlestick::new(x, open, high, low, close);
16 let cs = translate! {
17 *cs,
19 cs_obj,
20 map,
21 (name, String),
22 (show_legend, bool),
23 (legend_group, String),
24 (opacity, f64),
25 (text, String),
26 (text_array, Vec<String>),
27 (hover_text, String),
28 (hover_text_array, Vec<String>),
29 (whisker_width, f64),
30 (x_axis, String),
31 (y_axis, String),
32 }?;
33
34 use plotly::common::Visible;
35 let cs = translate_enum! {
36 cs,
37 cs_obj,
38 map,
39 (visible, {
40 "true" => Visible::True,
41 "false" => Visible::False,
42 "legendonly" => Visible::LegendOnly,
43 }),
44 }?;
45
46 Ok(Box::new(cs))
48}