Skip to content

Commit

Permalink
add connect_nulls to line; allow optional numeric values
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Sep 9, 2024
1 parent be38cae commit fdecc8d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
10 changes: 10 additions & 0 deletions charming/src/datatype/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl From<f64> for NumericValue {
#[serde(untagged)]
pub enum CompositeValue {
Number(NumericValue),
OptionalNumber(Option<NumericValue>),
String(String),
Array(Vec<CompositeValue>),
}
Expand All @@ -48,6 +49,15 @@ where
}
}

impl<N> From<Option<N>> for CompositeValue
where
N: Into<NumericValue>,
{
fn from(n: Option<N>) -> Self {
CompositeValue::OptionalNumber(n.map(Into::into))
}
}

impl From<&str> for CompositeValue {
fn from(s: &str) -> Self {
CompositeValue::String(s.to_string())
Expand Down
9 changes: 9 additions & 0 deletions charming/src/series/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub struct Line {
#[serde(skip_serializing_if = "Option::is_none")]
smooth: Option<f64>,

#[serde(skip_serializing_if = "Option::is_none")]
connect_nulls: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
mark_point: Option<MarkPoint>,

Expand Down Expand Up @@ -101,6 +104,7 @@ impl Line {
item_style: None,
emphasis: None,
smooth: None,
connect_nulls: None,
mark_point: None,
mark_line: None,
mark_area: None,
Expand Down Expand Up @@ -179,6 +183,11 @@ impl Line {
self
}

pub fn connect_nulls(mut self, connect_nulls: bool) -> Self {
self.connect_nulls = Some(connect_nulls);
self
}

pub fn mark_point<M: Into<MarkPoint>>(mut self, mark_point: M) -> Self {
self.mark_point = Some(mark_point.into());
self
Expand Down
23 changes: 21 additions & 2 deletions gallery/src/line/distribution_of_electricity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,28 @@ pub fn chart() -> Chart {
Line::new()
.name("Electricity")
.smooth(0.5)
.connect_nulls(true)
.data(vec![
300, 280, 250, 260, 270, 300, 550, 500, 400, 390, 380, 390, 400, 500, 600, 750,
800, 700, 600, 400,
Some(300),
Some(280),
Some(250),
None,
Some(270),
Some(300),
Some(550),
Some(500),
Some(400),
Some(390),
Some(380),
Some(390),
Some(400),
Some(500),
Some(600),
Some(750),
Some(800),
Some(700),
Some(600),
Some(400),
])
.mark_area(
MarkArea::new()
Expand Down

0 comments on commit fdecc8d

Please sign in to comment.