#[non_exhaustive]pub struct ChartJsPoint<T, U> {
pub formatted_value: String,
pub label: String,
pub dataset: ChartJsPointDataset,
pub raw: Coordinate<T, U>,
}
Expand description
A representation in rust of a ChartJS poinrt, generally exposed via the tooltips plugin
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.formatted_value: String
Probably don’t use this
label: String
Probably don’t use this
dataset: ChartJsPointDataset
Details about the dataset that are seen by the viewer of the chart
raw: Coordinate<T, U>
The raw coordinate value for the point
Implementations§
Source§impl<T, TE, U, UE> ChartJsPoint<T, U>
impl<T, TE, U, UE> ChartJsPoint<T, U>
Sourcepub fn parse(val: JsValue) -> Result<Self, CoordinateError>
pub fn parse(val: JsValue) -> Result<Self, CoordinateError>
This should be used for parameter of crate::objects::TooltipCallbacks::label
- first create a function
#[wasm_bindgen]
pub fn tooltip_value_callback(context: JsValue) -> JsValue {
match ChartJsPoint::<NaiveDate, Dollars>::parse(context) {
Ok(val) => {
let label = val.dataset.label;
let y = val.raw.y.format();
JsValue::from_str(&format!("{label}: {y}"))
}
Err(e) => {
console_dbg!("Error parsing", e);
JsValue::from_str("")
}
}
}
- then use with the builder:
ChartOptions::new()
.plugins(
ChartPlugins::new()
.tooltip(
TooltipPlugin::new().callbacks(
TooltipCallbacks::new()
.label(
FnWithArgs::<1>::new()
.run_rust_fn(tooltip_value_callback),
)
),
),
)
Sourcepub fn parse_array(val: JsValue) -> Result<Vec<Self>, CoordinateError>
pub fn parse_array(val: JsValue) -> Result<Vec<Self>, CoordinateError>
This should be used for the parameter of crate::objects::TooltipCallbacks::title
- first create a function
#[wasm_bindgen]
pub fn tooltip_date_title_callback(context: JsValue) -> JsValue {
match ChartJsPoint::<NaiveDate, Dollars>::parse_array(context) {
Ok(vals) if !vals.is_empty() => JsValue::from_str(vals[0].label.split(",").next().unwrap_or_default()),
Ok(_) => {
console_dbg!("Empty array");
JsValue::from_str("")
}
Err(e) => {
console_dbg!("Error parsing", e);
JsValue::from_str("")
}
}
}
- then use with the builder:
ChartOptions::new()
.plugins(
ChartPlugins::new()
.tooltip(
TooltipPlugin::new().callbacks(
TooltipCallbacks::new()
.title(
FnWithArgs::<1>::new()
.run_rust_fn(tooltip_date_title_callback),
)
),
),
)
Trait Implementations§
Auto Trait Implementations§
impl<T, U> Freeze for ChartJsPoint<T, U>
impl<T, U> RefUnwindSafe for ChartJsPoint<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for ChartJsPoint<T, U>
impl<T, U> Sync for ChartJsPoint<T, U>
impl<T, U> Unpin for ChartJsPoint<T, U>
impl<T, U> UnwindSafe for ChartJsPoint<T, U>where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more