Skip to main content

systemprompt_models/artifacts/dashboard/section_data/
chart.rs

1//! Chart section payload.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use crate::artifacts::chart::ChartDataset;
7use crate::artifacts::types::AxisType;
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
12pub struct ChartSectionData {
13    pub chart_type: String,
14    pub labels: Vec<String>,
15    pub datasets: Vec<ChartDataset>,
16    #[serde(default)]
17    pub x_axis_label: String,
18    #[serde(default)]
19    pub y_axis_label: String,
20    #[serde(default)]
21    pub y_axis_type: AxisType,
22}
23
24impl ChartSectionData {
25    pub fn new(
26        chart_type: impl Into<String>,
27        labels: Vec<String>,
28        datasets: Vec<ChartDataset>,
29    ) -> Self {
30        Self {
31            chart_type: chart_type.into(),
32            labels,
33            datasets,
34            x_axis_label: String::new(),
35            y_axis_label: String::new(),
36            y_axis_type: AxisType::default(),
37        }
38    }
39
40    #[must_use]
41    pub fn with_axis_labels(
42        mut self,
43        x_axis_label: impl Into<String>,
44        y_axis_label: impl Into<String>,
45    ) -> Self {
46        self.x_axis_label = x_axis_label.into();
47        self.y_axis_label = y_axis_label.into();
48        self
49    }
50
51    #[must_use]
52    pub const fn with_y_axis_type(mut self, y_axis_type: AxisType) -> Self {
53        self.y_axis_type = y_axis_type;
54        self
55    }
56}