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