Skip to main content

visi_core/core/
chart.rs

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