openpine_vm/visuals/
plotshape.rs1use openpine_compiler::instructions::Color;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5 series::Series,
6 visuals::{Location, PlotDisplay, PlotFormat, Shape, Size},
7};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct PlotShape {
12 pub title: Option<String>,
14 pub(crate) series: Series<Option<f64>>,
15 pub style: Shape,
17 pub location: Location,
19 pub colors: Series<Option<Color>>,
21 pub offset: i32,
23 pub text: Option<String>,
25 pub text_colors: Series<Option<Color>>,
27 pub editable: bool,
29 pub size: Size,
31 pub show_last: Option<usize>,
33 pub display: PlotDisplay,
35 pub format: Option<PlotFormat>,
37 pub precision: Option<i32>,
39 pub force_overlay: bool,
41}
42
43impl PlotShape {
44 #[inline]
46 pub fn bool_value(&self, index: usize) -> Option<bool> {
47 self.series[index].as_ref().map(|v| *v != 0.0)
48 }
49
50 #[inline]
52 pub fn float_value(&self, index: usize) -> Option<f64> {
53 self.series[index]
54 }
55
56 pub(crate) fn append_new(&mut self) {
57 self.series.append_new();
58 self.colors.append_new();
59 self.text_colors.append_new();
60 }
61}