use crate::grammar::encoding::Encoding;
use crate::grammar::position::Position;
use crate::grammar::stat::Stat;
#[derive(Clone, Copy, Debug)]
pub enum MarkType {
Point,
Line,
Bar,
Area,
Text,
Arc,
Rule,
Heatmap,
Treemap,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Layer {
pub mark: MarkType,
pub encodings: Vec<Encoding>,
pub stat: Stat,
pub x_data: Option<Vec<f64>>,
pub y_data: Option<Vec<f64>>,
pub categories: Option<Vec<String>>,
pub inner_radius_fraction: f32,
pub position: Position,
pub facet_values: Option<Vec<String>>,
pub heatmap_data: Option<Vec<Vec<f64>>>,
pub row_labels: Option<Vec<String>>,
pub col_labels: Option<Vec<String>>,
pub annotate_cells: bool,
pub label: Option<String>,
pub error_bars: Option<Vec<f64>>,
}
impl Layer {
pub fn new(mark: MarkType) -> Self {
Self {
mark,
encodings: Vec::new(),
stat: Stat::Identity,
x_data: None,
y_data: None,
categories: None,
inner_radius_fraction: 0.0,
position: Position::default(),
facet_values: None,
heatmap_data: None,
row_labels: None,
col_labels: None,
annotate_cells: false,
label: None,
error_bars: None,
}
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
#[deprecated(
note = "Encoding-based API is not yet wired into the compile pipeline. Use with_x/with_y/with_categories instead."
)]
pub fn encode_x(mut self, mut enc: Encoding) -> Self {
enc.channel = crate::grammar::encoding::Channel::X;
self.encodings.push(enc);
self
}
#[deprecated(
note = "Encoding-based API is not yet wired into the compile pipeline. Use with_x/with_y/with_categories instead."
)]
pub fn encode_y(mut self, mut enc: Encoding) -> Self {
enc.channel = crate::grammar::encoding::Channel::Y;
self.encodings.push(enc);
self
}
#[deprecated(
note = "Encoding-based API is not yet wired into the compile pipeline. Use with_x/with_y/with_categories instead."
)]
pub fn encode_color(mut self, mut enc: Encoding) -> Self {
enc.channel = crate::grammar::encoding::Channel::Color;
self.encodings.push(enc);
self
}
#[deprecated(
note = "Encoding-based API is not yet wired into the compile pipeline. Use with_x/with_y/with_categories instead."
)]
pub fn encode_size(mut self, mut enc: Encoding) -> Self {
enc.channel = crate::grammar::encoding::Channel::Size;
self.encodings.push(enc);
self
}
pub fn stat(mut self, stat: Stat) -> Self {
self.stat = stat;
self
}
pub fn with_x(mut self, x: Vec<f64>) -> Self {
self.x_data = Some(x);
self
}
pub fn with_y(mut self, y: Vec<f64>) -> Self {
self.y_data = Some(y);
self
}
pub fn with_categories(mut self, cats: Vec<String>) -> Self {
self.categories = Some(cats);
self
}
pub fn with_inner_radius_fraction(mut self, fraction: f32) -> Self {
self.inner_radius_fraction = fraction;
self
}
pub fn position(mut self, position: Position) -> Self {
self.position = position;
self
}
pub fn with_facet_values(mut self, facet_values: Vec<String>) -> Self {
self.facet_values = Some(facet_values);
self
}
pub fn with_heatmap_data(mut self, data: Vec<Vec<f64>>) -> Self {
self.heatmap_data = Some(data);
self
}
pub fn with_row_labels(mut self, labels: Vec<String>) -> Self {
self.row_labels = Some(labels);
self
}
pub fn with_col_labels(mut self, labels: Vec<String>) -> Self {
self.col_labels = Some(labels);
self
}
pub fn annotate_cells(mut self) -> Self {
self.annotate_cells = true;
self
}
pub fn with_error_bars(mut self, errors: Vec<f64>) -> Self {
self.error_bars = Some(errors);
self
}
}