Struct ChartJsPoint

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

Source

pub fn parse(val: JsValue) -> Result<Self, CoordinateError>

This should be used for parameter of crate::objects::TooltipCallbacks::label

  1. 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("")
       }
   }
}
  1. 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),
                    )
            ),
        ),
)
Source

pub fn parse_array(val: JsValue) -> Result<Vec<Self>, CoordinateError>

This should be used for the parameter of crate::objects::TooltipCallbacks::title

  1. 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("")
        }
    }
}
  1. 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§

Source§

impl<T: Debug, U: Debug> Debug for ChartJsPoint<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 ChartJsPoint<T, U>
where T: Freeze, U: Freeze,

§

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

§

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

§

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

§

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

§

impl<T, U> UnwindSafe for ChartJsPoint<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.