euv_chart/model/struct.rs
1use super::*;
2
3/// A mapping from data values to pixel positions.
4///
5/// One scale serves one axis. The scale knows the data domain (the range
6/// of values the data cover) and the pixel range (the extent of the grid
7/// along the axis), and maps between them.
8#[derive(Clone, Debug, lombok_macros::Data, PartialEq)]
9pub struct Scale {
10 /// The kind of the scale.
11 #[get(type(copy))]
12 pub kind: ScaleKind,
13 /// The lower end of the data domain.
14 #[get(type(copy))]
15 pub domain_min: f64,
16 /// The upper end of the data domain.
17 #[get(type(copy))]
18 pub domain_max: f64,
19 /// The lower end of the pixel range.
20 #[get(type(copy))]
21 pub range_min: f64,
22 /// The upper end of the pixel range.
23 #[get(type(copy))]
24 pub range_max: f64,
25 /// The categories of an ordinal scale.
26 pub categories: Vec<String>,
27 /// The base of a logarithmic scale.
28 #[get(type(copy))]
29 pub log_base: f64,
30 /// The width of one band of an ordinal scale, in pixels.
31 ///
32 /// A band is the space one category occupies. It is larger than the
33 /// distance between two category centres by exactly one band, which
34 /// is what lets a bar chart draw a bar that fills its band without
35 /// spilling into the neighbouring one.
36 #[get(type(copy))]
37 pub band: f64,
38 /// The number of categories of an ordinal scale.
39 ///
40 /// The count is kept apart from the names because the two are not
41 /// the same: a chart over a million unnamed points has a million
42 /// categories and not one name.
43 #[get(type(copy))]
44 pub count: usize,
45}
46
47/// One tick of an axis.
48#[derive(Clone, Debug, PartialEq)]
49pub struct AxisTick {
50 /// The data value of the tick.
51 pub value: f64,
52 /// The text of the tick's label.
53 pub label: String,
54 /// The pixel position of the tick along the axis.
55 pub position: f64,
56}
57
58/// The layout of one axis.
59#[derive(Clone, Debug, lombok_macros::Data, PartialEq)]
60pub struct AxisLayout {
61 /// The index of the axis in the option.
62 #[get(type(copy))]
63 pub index: usize,
64 /// The kind of the axis.
65 #[get(type(copy))]
66 pub kind: AxisType,
67 /// The scale the axis maps with.
68 pub scale: Scale,
69 /// The ticks of the axis.
70 pub ticks: Vec<AxisTick>,
71 /// The side of the grid the axis sits on.
72 #[get(type(copy))]
73 pub side: AxisSide,
74 /// The pixel position of the axis' line, perpendicular to the axis.
75 #[get(type(copy))]
76 pub offset: f64,
77 /// The space the axis' labels need, perpendicular to the axis.
78 #[get(type(copy))]
79 pub label_space: f64,
80 /// The name of the axis.
81 #[get(type(clone))]
82 pub name: Option<String>,
83 /// The space the axis' name needs, perpendicular to the axis.
84 #[get(type(copy))]
85 pub name_space: f64,
86 /// Whether the axis is drawn.
87 #[get(type(copy))]
88 pub show: bool,
89 /// The labels of the axis.
90 pub labels: Vec<AxisTick>,
91 /// How many ticks pass between two labelled ones.
92 ///
93 /// A category axis with a thousand categories cannot show a
94 /// thousand labels: they would overlap into a smear. The interval
95 /// is the number of ticks between two labels, so that the labels
96 /// are far enough apart to be read.
97 #[get(type(copy))]
98 pub label_interval: usize,
99}
100
101/// The layout of one cartesian grid.
102#[derive(Clone, Debug, lombok_macros::Data, PartialEq)]
103pub struct GridLayout {
104 /// The index of the grid in the option.
105 #[get(type(copy))]
106 pub index: usize,
107 /// The rectangle the grid occupies, in canvas pixels.
108 #[get(type(copy))]
109 pub rect: BBox,
110 /// The x-axes of the grid.
111 pub x_axes: Vec<AxisLayout>,
112 /// The y-axes of the grid.
113 pub y_axes: Vec<AxisLayout>,
114}
115
116/// One data point of a series, in pixel space.
117#[derive(Clone, Debug, PartialEq)]
118pub struct SeriesPoint {
119 /// The horizontal position, in canvas pixels.
120 pub x: f64,
121 /// The vertical position, in canvas pixels.
122 pub y: f64,
123 /// The value of the point.
124 pub value: f64,
125 /// The name of the point.
126 pub name: String,
127 /// The index of the point in the series' data.
128 pub data_index: usize,
129}
130
131/// The layout of one series.
132#[derive(Clone, Debug, PartialEq)]
133pub struct SeriesLayout {
134 /// The index of the series in the option.
135 pub index: usize,
136 /// The kind of the series.
137 pub kind: SeriesType,
138 /// The name of the series.
139 pub name: String,
140 /// The index of the grid the series is drawn in.
141 pub grid_index: usize,
142 /// The points of the series, in pixel space.
143 pub points: Vec<SeriesPoint>,
144 /// The stack the series is stacked in, if any.
145 pub stack: Option<String>,
146 /// The index of the stack the series belongs to, within its group.
147 pub stack_index: usize,
148 /// The number of series stacked together with this one.
149 pub stack_size: usize,
150 /// The plot area the chart's non-cartesian series are drawn in.
151 pub plot_rect: BBox,
152 /// The width of one category band, in pixels.
153 ///
154 /// Zero for a series whose x-axis is not ordinal.
155 pub band_width: f64,
156}
157
158/// The whole layout of a chart.
159#[derive(Clone, Debug, Default, lombok_macros::Data, PartialEq)]
160pub struct ChartLayout {
161 /// The width of the chart, in canvas pixels.
162 #[get(type(copy))]
163 pub width: f64,
164 /// The height of the chart, in canvas pixels.
165 #[get(type(copy))]
166 pub height: f64,
167 /// The grids of the chart.
168 pub grids: Vec<GridLayout>,
169 /// The series of the chart.
170 pub series: Vec<SeriesLayout>,
171 /// The maps of the chart, projected into the plot area.
172 pub geo: Vec<GeoLayout>,
173 /// The rectangle the title occupies.
174 #[get(type(copy))]
175 pub title_rect: Option<BBox>,
176 /// The rectangle the legend occupies.
177 #[get(type(copy))]
178 pub legend_rect: Option<BBox>,
179 /// The rectangle the chart's plot area occupies.
180 #[get(type(copy))]
181 pub plot_rect: BBox,
182}
183
184/// One band of a piecewise visual map.
185#[derive(Clone, Debug, PartialEq)]
186pub struct VisualPiece {
187 /// The lowest value of the band.
188 pub min: f64,
189 /// The highest value of the band.
190 pub max: f64,
191 /// The colour of the band.
192 pub color: Color,
193}
194
195/// A visual map, resolved for drawing.
196///
197/// A visual map turns a value into a colour. The chart resolves the
198/// option once, and then asks the map for the colour of every value it
199/// draws — which is what keeps a map of a country from walking the
200/// palette for every region.
201#[derive(Clone, Debug, lombok_macros::Data, PartialEq)]
202pub struct VisualMap {
203 /// The kind of the visual map.
204 #[get(type(copy))]
205 pub visual_type: VisualMapType,
206 /// The lowest value the map covers.
207 #[get(type(copy))]
208 pub min: f64,
209 /// The highest value the map covers.
210 #[get(type(copy))]
211 pub max: f64,
212 /// The colours of the map, from the lowest value to the highest.
213 pub colors: Vec<Color>,
214 /// The number of bands a piecewise map is cut into.
215 #[get(type(copy))]
216 pub split_number: usize,
217 /// The bands of a piecewise map, when the option names them.
218 pub pieces: Vec<VisualPiece>,
219 /// The colour of the values outside the range.
220 #[get(type(copy))]
221 pub out_of_range: Option<Color>,
222}