Skip to main content

plot_redactor/model/
types.rs

1//! Core reusable types for plot configuration and styling.
2//!
3//! These types are intentionally renderer-agnostic and form the stable contract
4//! between UI/controller logic and rendering backends.
5
6/// Stable identifier of a plotted series.
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub struct SeriesId(pub u64);
9
10/// Pair of x/y axis configurations.
11#[derive(Clone, Debug)]
12pub struct AxesConfig {
13    pub x: AxisConfig,
14    pub y: AxisConfig,
15}
16
17/// Full axis setup edited by axis controls.
18#[derive(Clone, Debug)]
19pub struct AxisConfig {
20    pub label: String,
21    pub label_font_size: u32,
22    pub scale: ScaleType,
23    pub range: RangePolicy,
24    pub ticks: TickConfig,
25}
26
27/// Axis transformation mode.
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub enum ScaleType {
30    Linear,
31    Log10,
32    LogE,
33}
34
35/// Axis range policy (`Auto` from data or fixed manual bounds).
36#[derive(Clone, Debug)]
37pub enum RangePolicy {
38    Auto,
39    Manual { min: f64, max: f64 },
40}
41
42/// Tick density controls used by mesh configuration.
43#[derive(Clone, Debug)]
44pub struct TickConfig {
45    pub major_step: Option<f64>,
46    pub minor_per_major: u16,
47}
48
49/// Chart legend configuration.
50#[derive(Clone, Debug)]
51pub struct LegendConfig {
52    pub visible: bool,
53    pub title: Option<String>,
54    pub position: LegendPosition,
55    pub font_size: u32,
56    pub font_color: Color,
57}
58
59/// Legend position inside plot area.
60#[derive(Clone, Copy, Debug, PartialEq, Eq)]
61pub enum LegendPosition {
62    TopLeft,
63    TopRight,
64    BottomLeft,
65    BottomRight,
66}
67
68/// Layout-level settings of the plot area and title style.
69#[derive(Clone, Debug)]
70pub struct LayoutConfig {
71    pub title: String,
72    pub x_label_area_size: u32,
73    pub y_label_area_size: u32,
74    pub margin: u32,
75    pub title_font_size: u32,
76    pub title_font_color: Color,
77}
78
79/// RGBA color in 8-bit channels.
80#[derive(Clone, Copy, Debug)]
81pub struct Color {
82    pub r: u8,
83    pub g: u8,
84    pub b: u8,
85    pub a: u8,
86}
87
88/// Visual style of one plotted series.
89#[derive(Clone, Debug)]
90pub struct SeriesStyle {
91    pub color: Color,
92    pub line_width: f32,
93    pub line_style: LineStyle,
94    pub marker: Option<MarkerStyle>,
95}
96
97/// Line pattern used for a series.
98#[derive(Clone, Copy, Debug, PartialEq, Eq)]
99pub enum LineStyle {
100    Solid,
101    Dashed,
102    Dotted,
103}
104
105/// Marker configuration for point rendering.
106#[derive(Clone, Debug)]
107pub struct MarkerStyle {
108    pub shape: MarkerShape,
109    pub size: f32,
110}
111
112/// Marker shape variants.
113#[derive(Clone, Copy, Debug, PartialEq, Eq)]
114pub enum MarkerShape {
115    Circle,
116    Square,
117    Triangle,
118    Cross,
119}
120
121/// Axis selector for generic axis actions.
122#[derive(Clone, Copy, Debug, PartialEq, Eq)]
123pub enum AxisKind {
124    X,
125    Y,
126}
127
128/// Supported export image formats.
129#[derive(Clone, Copy, Debug)]
130pub enum ImageFormat {
131    Png,
132    Svg,
133}
134
135/// Export output pixel dimensions.
136#[derive(Clone, Copy, Debug)]
137pub struct ImageSize {
138    pub width: u32,
139    pub height: u32,
140}