Skip to main content

shape_viz_core/
style.rs

1//! Chart styling parameters to tune layout and layer appearance.
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct LayoutStyle {
7    pub price_axis_width: f32,
8    pub time_axis_height: f32,
9    pub chart_padding_x: f32,
10    pub chart_padding_y: f32,
11    pub volume_height_ratio: f32,
12    pub volume_gap: f32,
13}
14
15impl Default for LayoutStyle {
16    fn default() -> Self {
17        Self {
18            price_axis_width: 82.0,
19            time_axis_height: 48.0,
20            chart_padding_x: 12.0,
21            chart_padding_y: 14.0,
22            volume_height_ratio: 0.24,
23            volume_gap: 4.0,
24        }
25    }
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct CandleStyle {
30    pub body_width_factor: f32,
31    pub wick_width: f32,
32    pub min_body_width: f32,
33    pub max_body_width: f32,
34    pub min_body_height: f32,
35}
36
37impl Default for CandleStyle {
38    fn default() -> Self {
39        Self {
40            body_width_factor: 0.82,
41            wick_width: 1.3,
42            min_body_width: 3.0,
43            max_body_width: 32.0,
44            min_body_height: 1.2,
45        }
46    }
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct VolumeStyle {
51    pub background_darken: f32,
52    pub baseline_alpha: f32,
53}
54
55impl Default for VolumeStyle {
56    fn default() -> Self {
57        Self {
58            background_darken: 0.22,
59            baseline_alpha: 0.25,
60        }
61    }
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct CurrentPriceStyle {
66    pub line_width: f32,
67    pub dash_length: f32,
68    pub dash_gap: f32,
69    pub label_padding: f32,
70}
71
72impl Default for CurrentPriceStyle {
73    fn default() -> Self {
74        Self {
75            line_width: 1.2,
76            dash_length: 8.0,
77            dash_gap: 4.0,
78            label_padding: 6.0,
79        }
80    }
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize, Default)]
84pub struct ChartStyle {
85    pub layout: LayoutStyle,
86    pub candles: CandleStyle,
87    pub volume: VolumeStyle,
88    pub current_price: CurrentPriceStyle,
89}