mdbook_plotly/code_handler/plot_obj_parser/
image_parser.rs1use super::until::{Map, must_translate};
2use crate::{translate, translate_enum};
3use anyhow::Result;
4use plotly::{Image, color::Rgba};
5
6pub fn parse_image_data(image_obj: &mut serde_json::Value, map: &Map) -> Result<Box<Image>> {
7 let z: Vec<Vec<Rgba>> = must_translate(image_obj, map, "z")?;
8 let image = Image::new(z);
9 let image = translate! {
10 image,
11 image_obj,
12 map,
13 (opacity, f64),
14 (name, String),
15 (legend_rank, usize),
16 (text, String),
17 (text_array, Vec<String>),
18 (hover_text, String),
19 (hover_text_array, Vec<String>),
20 (hover_template, String),
21 (hover_template_array, Vec<String>),
22 (source, String),
23 (x0, f64),
24 (dx, f64),
25 (y0, f64),
26 (dy, f64),
27 (x_axis, String),
28 (y_axis, String),
29 (ids, Vec<String>),
30 (meta, String),
31 }?;
32
33 use plotly::image::ZSmooth;
34 let image = translate_enum! {
35 image,
36 image_obj,
37 map,
38 (z_smooth, {
39 "fast" => ZSmooth::Fast,
40 "false" => ZSmooth::False,
41 }),
42 }?;
43
44 Ok(image)
45}