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

add symbol callback #91

Merged
merged 4 commits into from
Oct 7, 2024
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
2 changes: 1 addition & 1 deletion charming/src/component/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl From<(String, String)> for LegendItem {
}
}

#[derive(Serialize, Debug, PartialEq, PartialOrd, Clone)]
#[derive(Serialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Legend {
/// Type of legend.
Expand Down
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
Loading