esoc_chart/grammar/
encoding.rs1#[derive(Clone, Debug)]
6pub enum FieldType {
7 Quantitative,
9 Nominal,
11 Ordinal,
13 Temporal,
15}
16
17#[derive(Clone, Debug)]
19pub enum Channel {
20 X,
22 Y,
24 Color,
26 Size,
28 #[doc(hidden)]
30 Shape,
31 #[doc(hidden)]
33 Opacity,
34 #[doc(hidden)]
36 Text,
37}
38
39#[derive(Clone, Debug)]
41pub struct Encoding {
42 pub channel: Channel,
44 pub field_type: FieldType,
46 pub field: FieldAccessor,
48 pub title: Option<String>,
50}
51
52#[derive(Clone, Debug)]
54pub enum FieldAccessor {
55 Index(usize),
57 Name(String),
59}
60
61#[deprecated(note = "Defaults channel to X which is misleading; use Encoding struct directly")]
63pub fn quantitative(index: usize) -> Encoding {
64 Encoding {
65 channel: Channel::X,
66 field_type: FieldType::Quantitative,
67 field: FieldAccessor::Index(index),
68 title: None,
69 }
70}
71
72#[deprecated(note = "Defaults channel to X which is misleading; use Encoding struct directly")]
74pub fn nominal(index: usize) -> Encoding {
75 Encoding {
76 channel: Channel::X,
77 field_type: FieldType::Nominal,
78 field: FieldAccessor::Index(index),
79 title: None,
80 }
81}
82
83impl Encoding {
84 pub fn channel(mut self, ch: Channel) -> Self {
86 self.channel = ch;
87 self
88 }
89
90 pub fn title(mut self, title: impl Into<String>) -> Self {
92 self.title = Some(title.into());
93 self
94 }
95}