#[non_exhaustive]pub struct Coordinate<T, U> {
pub x: T,
pub y: U,
}
Expand description
A representation in rust of a ChartJS coordinate, allowing convenient formatting when constructing tooltips
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.x: T
§y: U
Implementations§
Source§impl<T, TE, U, UE> Coordinate<T, U>
impl<T, TE, U, UE> Coordinate<T, U>
Sourcepub fn from_js_value(val: JsValue) -> Result<Self, CoordinateError>
pub fn from_js_value(val: JsValue) -> Result<Self, CoordinateError>
This should be used inside a #[wasm_bindgen]
function
where it is known that the parameter passed to the function
will have the shape of an individual coordinate
- first create a function
#[wasm_bindgen]
pub fn chart_data_label_formatter(a: JsValue, _: JsValue) -> JsValue {
match Coordinate::<NaiveDate, Dollars>::from_js_value(a) {
Ok(val) => JsValue::from_str(&val.y.format().to_string()),
Err(e) => {
console_dbg!("Error converting to serde", e);
JsValue::from_str("")
}
}
}
- then use it with the
crate::objects::DataLabels
builder:
DataLabels::new()
.formatter(FnWithArgs::<2>::new().run_rust_fn(chart_data_label_formatter)),
Trait Implementations§
Auto Trait Implementations§
impl<T, U> Freeze for Coordinate<T, U>
impl<T, U> RefUnwindSafe for Coordinate<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Coordinate<T, U>
impl<T, U> Sync for Coordinate<T, U>
impl<T, U> Unpin for Coordinate<T, U>
impl<T, U> UnwindSafe for Coordinate<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