Skip to content

Commit

Permalink
add value formatter to tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Sep 3, 2024
1 parent be38cae commit adad818
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions charming/src/element/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub struct Tooltip {
#[serde(skip_serializing_if = "Option::is_none")]
formatter: Option<Formatter>,

#[serde(skip_serializing_if = "Option::is_none")]
value_formatter: Option<Formatter>,

#[serde(skip_serializing_if = "Option::is_none")]
position: Option<String>,

Expand Down Expand Up @@ -65,6 +68,7 @@ impl Tooltip {
trigger_on: None,
axis_pointer: None,
formatter: None,
value_formatter: None,
position: None,
padding: None,
background_color: None,
Expand Down Expand Up @@ -93,6 +97,11 @@ impl Tooltip {
self
}

pub fn value_formatter<F: Into<Formatter>>(mut self, value_formatter: F) -> Self {
self.value_formatter = Some(value_formatter.into());
self
}

pub fn position<S: Into<String>>(mut self, position: S) -> Self {
self.position = Some(position.into());
self
Expand Down
7 changes: 4 additions & 3 deletions gallery/src/line/distribution_of_electricity.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use charming::{
component::{Axis, Feature, SaveAsImage, Title, Toolbox, VisualMap, VisualMapPiece},
element::{
AxisLabel, AxisPointer, AxisPointerType, AxisType, ItemStyle, MarkArea, MarkAreaData,
Tooltip, Trigger,
AxisLabel, AxisPointer, AxisPointerType, AxisType, Formatter, ItemStyle, MarkArea,
MarkAreaData, Tooltip, Trigger,
},
series::Line,
Chart,
Expand All @@ -18,7 +18,8 @@ pub fn chart() -> Chart {
.tooltip(
Tooltip::new()
.trigger(Trigger::Axis)
.axis_pointer(AxisPointer::new().type_(AxisPointerType::Cross)),
.axis_pointer(AxisPointer::new().type_(AxisPointerType::Cross))
.value_formatter(Formatter::Function("value => value + 'W'".into())),
)
.toolbox(
Toolbox::new()
Expand Down

0 comments on commit adad818

Please sign in to comment.