#[derive(Clone, Debug)]
pub enum FieldType {
Quantitative,
Nominal,
Ordinal,
Temporal,
}
#[derive(Clone, Debug)]
pub enum Channel {
X,
Y,
Color,
Size,
#[doc(hidden)]
Shape,
#[doc(hidden)]
Opacity,
#[doc(hidden)]
Text,
}
#[derive(Clone, Debug)]
pub struct Encoding {
pub channel: Channel,
pub field_type: FieldType,
pub field: FieldAccessor,
pub title: Option<String>,
}
#[derive(Clone, Debug)]
pub enum FieldAccessor {
Index(usize),
Name(String),
}
#[deprecated(note = "Defaults channel to X which is misleading; use Encoding struct directly")]
pub fn quantitative(index: usize) -> Encoding {
Encoding {
channel: Channel::X,
field_type: FieldType::Quantitative,
field: FieldAccessor::Index(index),
title: None,
}
}
#[deprecated(note = "Defaults channel to X which is misleading; use Encoding struct directly")]
pub fn nominal(index: usize) -> Encoding {
Encoding {
channel: Channel::X,
field_type: FieldType::Nominal,
field: FieldAccessor::Index(index),
title: None,
}
}
impl Encoding {
pub fn channel(mut self, ch: Channel) -> Self {
self.channel = ch;
self
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
}