Skip to main content

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///
22/// Workbook-level rather than sheet-scoped: `WorkbookManager::charts` owns
23/// these, and which worksheet a chart is drawn on comes from `data_range`'s
24/// sheet prefix.
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
26pub struct Chart {
27    /// Workbook-unique identifier, stable across renames.
28    pub id: u64,
29    /// Display name.
30    pub name: String,
31    /// What shape to draw.
32    pub chart_type: ChartType,
33    /// The source cells, in A1 notation with a sheet prefix
34    /// (`"table_1!A1:B10"`). The prefix also decides which worksheet the
35    /// chart is anchored to.
36    pub data_range: String,
37    /// Chart title, if it has one.
38    pub title: Option<String>,
39    /// X-axis label, if it has one.
40    pub xlabel: Option<String>,
41    /// Y-axis label, if it has one.
42    pub ylabel: Option<String>,
43    /// Whether to draw a legend.
44    pub show_legend: bool,
45    /// 0-based row/col of the cell the chart's top-left corner is anchored
46    /// to on its worksheet (which worksheet that is comes from
47    /// `data_range`'s sheet/table prefix, same as today).
48    #[serde(default)]
49    pub anchor_row: usize,
50    /// Column half of that anchor; see [`Chart::anchor_row`].
51    #[serde(default)]
52    pub anchor_col: usize,
53}