Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plotting series with null values #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading