Struct Coordinate

Source
#[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>
where T: FromStr<Err = TE>, U: FromStr<Err = UE>, TE: Error + Sync + Send + 'static, UE: Error + Sync + Send + 'static,

Source

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

  1. 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("")
        }
    }
}
  1. then use it with the crate::objects::DataLabels builder:
DataLabels::new()
.formatter(FnWithArgs::<2>::new().run_rust_fn(chart_data_label_formatter)),

Trait Implementations§

Source§

impl<T: Debug, U: Debug> Debug for Coordinate<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for Coordinate<T, U>
where T: Freeze, U: Freeze,

§

impl<T, U> RefUnwindSafe for Coordinate<T, U>

§

impl<T, U> Send for Coordinate<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for Coordinate<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for Coordinate<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for Coordinate<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.