visi_core/core/chart.rs
1use serde::{Deserialize, Serialize};
2
3/// The chart shapes visi can read and write.
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5pub enum ChartType {
6 /// Vertical bars.
7 Column,
8 /// Horizontal bars.
9 Bar,
10 /// Points joined by lines.
11 Line,
12 /// A pie, from a single series.
13 Pie,
14 /// X/Y points, taking the first column as the x values.
15 Scatter,
16 /// A line chart with the area beneath it filled.
17 Area,
18}
19
20/// A chart over a range of cells.
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
22pub struct Chart {
23 /// Workbook-unique identifier, stable across renames.
24 pub id: u64,
25 /// Display name.
26 pub name: String,
27 /// What shape to draw.
28 pub chart_type: ChartType,
29 /// The source cells, in A1 notation with a sheet prefix
30 /// (`"Sheet1!A1:B10"`)
31 pub data_range: String,
32 /// Chart title, if it has one.
33 pub title: Option<String>,
34 /// X-axis label, if it has one.
35 pub xlabel: Option<String>,
36 /// Y-axis label, if it has one.
37 pub ylabel: Option<String>,
38 /// Whether to draw a legend.
39 pub show_legend: bool,
40 /// 0-based row/col of the cell the chart's top-left corner
41 /// is anchored to
42 #[serde(default)]
43 pub anchor_row: usize,
44 /// Column half of that anchor; see [`Chart::anchor_row`].
45 #[serde(default)]
46 pub anchor_col: usize,
47}