Skip to content

Commit

Permalink
Merge pull request #91 from yg0x01/main
Browse files Browse the repository at this point in the history
add symbol callback
  • Loading branch information
LukaOber authored Oct 7, 2024
2 parents 9fca003 + 55704af commit 8def462
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions charming/src/element/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::RawString;
use serde::Serialize;

#[derive(Debug, PartialEq, PartialOrd, Clone)]
Expand All @@ -11,6 +12,7 @@ pub enum Symbol {
Arrow,
None,
Custom(String),
Callback(RawString),
}

impl Serialize for Symbol {
Expand All @@ -25,6 +27,7 @@ impl Serialize for Symbol {
Symbol::Arrow => serializer.serialize_str("arrow"),
Symbol::None => serializer.serialize_str("none"),
Symbol::Custom(s) => serializer.serialize_str(s),
Symbol::Callback(s) => s.serialize(serializer),
}
}
}
1 change: 1 addition & 0 deletions gallery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ lazy_static! {
insert!(m, line, area_pieces);
insert!(m, line, basic_area);
insert!(m, line, basic_line);
insert!(m, line, different_symbols);
insert!(m, line, confidence_band);
insert!(m, line, data_transform_filter);
insert!(m, line, distribution_of_electricity);
Expand Down
19 changes: 19 additions & 0 deletions gallery/src/line/different_symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use charming::{
component::Axis,
element::{AxisType, Symbol},
series::Line,
Chart,
};

pub fn chart() -> Chart {
Chart::new()
.x_axis(
Axis::new()
.type_(AxisType::Category)
.data(vec!["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]),
)
.y_axis(Axis::new().type_(AxisType::Value))
.series(Line::new().data(vec![150, 230, 224, 218, 135, 147, 260])
.symbol_size(20)
.symbol(Symbol::Callback("function (value, params) { return params.dataIndex % 2 === 0 ? value > 200 ? 'diamond' : 'circle' : 'triangle'; }".into())))
}
1 change: 1 addition & 0 deletions gallery/src/line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod basic_area;
pub mod basic_line;
pub mod confidence_band;
pub mod data_transform_filter;
pub mod different_symbols;
pub mod distribution_of_electricity;
pub mod gradient_stacked_area;
pub mod large_scale_area;
Expand Down

0 comments on commit 8def462

Please sign in to comment.