1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! Layout settings for the chart families that are not plain lines.
use egui::Color32;
/// Settings for the direction arrow drawn beside the newest point of a line.
///
/// The arrow uses the last `points` finite samples (5 by default), so a noisy stream
/// still shows the direction the buffer is growing. Only cartesian lines, areas, steps,
/// and candlesticks draw it; pie, radar, gauge, heatmap, and reference series do not.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct DirectionArrowConfig {
/// Draw the arrow.
pub enabled: bool,
/// Samples used to measure the direction; 5 by default.
pub points: usize,
/// Shaft length in points.
pub length: f32,
/// Shaft width in points.
pub width: f32,
/// Head length in points.
pub head: f32,
/// Arrow color; the series color when `None`.
pub color: Option<Color32>,
}
impl Default for DirectionArrowConfig {
fn default() -> Self {
Self {
enabled: false,
points: 5,
length: 26.0,
width: 2.0,
head: 8.0,
color: None,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Layout of pie and donut charts.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct PieConfig {
/// Inner radius as a fraction of the outer radius, 0 for a pie.
pub inner_radius: f32,
/// Where the first slice starts, in radians; -π/2 is 12 o'clock.
pub start_angle: f32,
/// Draw the value or percentage on slices with room for it.
pub labels: bool,
/// Show percentages instead of raw values.
pub percentages: bool,
/// Write the total in the middle of a donut.
pub total: bool,
}
impl Default for PieConfig {
fn default() -> Self {
Self {
inner_radius: 0.0,
start_angle: -std::f32::consts::FRAC_PI_2,
labels: true,
percentages: true,
total: true,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Layout of radar charts. One series draws one closed polygon; several series overlay.
#[derive(Clone, Debug, PartialEq)]
pub struct RadarConfig {
/// Names around the ring; indexed by each point's x. Numbers are used when empty.
pub labels: Vec<String>,
/// Fixed maximum; automatic when `None`.
pub max: Option<f64>,
/// Grid rings.
pub rings: u8,
/// Fill opacity of each series, 0–1.
pub fill_opacity: f32,
}
impl Default for RadarConfig {
fn default() -> Self {
Self {
labels: Vec::new(),
max: None,
rings: 4,
fill_opacity: 0.16,
}
}
}
impl RadarConfig {
/// A radar with `labels` around the ring.
pub fn new(labels: impl IntoIterator<Item = impl Into<String>>) -> Self {
Self {
labels: labels.into_iter().map(Into::into).collect(),
..Self::default()
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Layout of gauge charts.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GaugeConfig {
/// Start of the arc in radians.
pub start_angle: f32,
/// End of the arc in radians.
pub end_angle: f32,
/// Arc thickness in points.
pub thickness: f32,
/// Draw the value under the center.
pub show_value: bool,
/// Draw the range ends.
pub show_range: bool,
}
impl Default for GaugeConfig {
fn default() -> Self {
Self {
start_angle: 0.75 * std::f32::consts::PI,
end_angle: 2.25 * std::f32::consts::PI,
thickness: 10.0,
show_value: true,
show_range: true,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Layout of heatmaps.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct HeatmapConfig {
/// Fill opacity, 0–1.
pub opacity: f32,
/// Draw a value scale at the right edge.
pub colorbar: bool,
/// Color scale.
pub colormap: super::Colormap,
}
impl Default for HeatmapConfig {
fn default() -> Self {
Self {
opacity: 1.0,
colorbar: true,
colormap: super::Colormap::Theme,
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Layout of waterfall charts.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WaterfallConfig {
/// Bar width in data units; 80 % of the smallest x spacing when `None`.
pub bar_width: Option<f64>,
/// Dashed connectors between consecutive bars.
pub connectors: bool,
}
impl Default for WaterfallConfig {
fn default() -> Self {
Self {
bar_width: None,
connectors: true,
}
}
}