openpine_vm/visuals/
plot.rs

1use num_enum::FromPrimitive;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5    series::Series,
6    visuals::{Color, PlotDisplay},
7};
8
9/// Plot rendering style.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, FromPrimitive, Serialize, Deserialize)]
11#[repr(i32)]
12pub enum PlotStyle {
13    /// Line plot.
14    #[default]
15    Line = 0,
16    /// Step-line plot.
17    StepLine = 8,
18    /// Diamond markers.
19    Diamond = 9,
20    /// Histogram bars.
21    Histogram = 7,
22    /// Cross markers.
23    Cross = 6,
24    /// Area plot.
25    Area = 2,
26    /// Column bars.
27    Columns = 5,
28    /// Circle markers.
29    Circles = 4,
30    /// Line break plot.
31    LineBr = 1,
32    /// Area break plot.
33    AreaBr = 3,
34    /// Step-line break plot.
35    StepLineBr = 10,
36}
37
38/// Line stroke style for line-based plots.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, FromPrimitive, Serialize, Deserialize)]
40#[repr(i32)]
41pub enum PlotLineStyle {
42    /// Solid stroke.
43    #[default]
44    Solid = 0,
45    /// Dotted stroke.
46    Dotted = 2,
47    /// Dashed stroke.
48    Dashed = 1,
49}
50
51/// A per-bar plot series with style and display settings.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct Plot {
54    /// Optional UI title.
55    pub title: Option<String>,
56    /// Per-bar plot value.
57    pub series: Series<Option<f64>>,
58    /// Per-bar plot color.
59    pub colors: Series<Option<Color>>,
60    /// Stroke width.
61    pub line_width: i32,
62    /// Plot style.
63    pub style: PlotStyle,
64    /// Whether to track the last value on the price scale.
65    pub track_price: bool,
66    /// Baseline for histogram/area fills.
67    pub histbase: f64,
68    /// Bar index offset.
69    pub offset: i32,
70    /// Whether to join gaps.
71    pub join: bool,
72    /// Whether the plot is user-editable.
73    pub editable: bool,
74    /// Optional limit for the number of visible bars.
75    pub show_last: Option<usize>,
76    /// Display targets.
77    pub display: PlotDisplay,
78    /// Optional formatting hint.
79    pub format: Option<String>,
80    /// Optional decimal precision.
81    pub precision: Option<i32>,
82    /// Whether to force overlay rendering.
83    pub force_overlay: bool,
84    /// Line style used when drawing line-based plots.
85    pub line_style: PlotLineStyle,
86}
87
88impl Plot {
89    pub(crate) fn append_new(&mut self) {
90        self.series.append_new();
91        self.colors.append_new();
92    }
93}