Skip to main content

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