diff --git a/charming/src/element/mod.rs b/charming/src/element/mod.rs index 14ed0b6..69819ab 100644 --- a/charming/src/element/mod.rs +++ b/charming/src/element/mod.rs @@ -36,6 +36,7 @@ pub mod pointer; pub mod scale_limit; pub mod select; pub mod shape; +pub mod smoothness; pub mod sort; pub mod split_area; pub mod split_line; diff --git a/charming/src/element/smoothness.rs b/charming/src/element/smoothness.rs new file mode 100644 index 0000000..24fac82 --- /dev/null +++ b/charming/src/element/smoothness.rs @@ -0,0 +1,36 @@ +use serde::Serialize; + +pub enum Smoothness { + Single(f64), + Boolean(bool), +} + +impl Serialize for Smoothness { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match self { + Smoothness::Single(smoothness) => serializer.serialize_f64(*smoothness), + Smoothness::Boolean(smoothness) => serializer.serialize_bool(*smoothness), + } + } +} + +impl From for Smoothness { + fn from(smoothness: f64) -> Self { + Smoothness::Single(smoothness) + } +} + +impl From for Smoothness { + fn from(smoothness: i64) -> Self { + Smoothness::Single(smoothness as f64) + } +} + +impl From for Smoothness { + fn from(smoothness: bool) -> Self { + Smoothness::Boolean(smoothness) + } +} diff --git a/charming/src/series/line.rs b/charming/src/series/line.rs index aff6409..9338ccd 100644 --- a/charming/src/series/line.rs +++ b/charming/src/series/line.rs @@ -3,8 +3,8 @@ use serde::Serialize; use crate::{ datatype::{DataFrame, DataPoint}, element::{ - AreaStyle, CoordinateSystem, DimensionEncode, Emphasis, ItemStyle, Label, LineStyle, - MarkArea, MarkLine, MarkPoint, Symbol, + smoothness::Smoothness, AreaStyle, CoordinateSystem, DimensionEncode, Emphasis, ItemStyle, + Label, LineStyle, MarkArea, MarkLine, MarkPoint, Symbol, }, }; @@ -51,7 +51,7 @@ pub struct Line { emphasis: Option, #[serde(skip_serializing_if = "Option::is_none")] - smooth: Option, + smooth: Option, #[serde(skip_serializing_if = "Option::is_none")] mark_point: Option, @@ -174,7 +174,7 @@ impl Line { } /// Smoothness. - pub fn smooth>(mut self, smooth: F) -> Self { + pub fn smooth>(mut self, smooth: F) -> Self { self.smooth = Some(smooth.into()); self } diff --git a/charming/src/series/parallel.rs b/charming/src/series/parallel.rs index 0754b5d..f129613 100644 --- a/charming/src/series/parallel.rs +++ b/charming/src/series/parallel.rs @@ -2,7 +2,7 @@ use serde::Serialize; use crate::{ datatype::{DataFrame, DataPoint}, - element::{ColorBy, CoordinateSystem, Emphasis, LineStyle}, + element::{smoothness::Smoothness, ColorBy, CoordinateSystem, Emphasis, LineStyle}, }; #[derive(Serialize)] @@ -49,7 +49,7 @@ pub struct Parallel { realtime: Option, #[serde(skip_serializing_if = "Option::is_none")] - smooth: Option, + smooth: Option, #[serde(skip_serializing_if = "Option::is_none")] progressive: Option, @@ -142,7 +142,7 @@ impl Parallel { self } - pub fn smooth>(mut self, smooth: F) -> Self { + pub fn smooth>(mut self, smooth: F) -> Self { self.smooth = Some(smooth.into()); self }