Skip to main content

orbital_charts/context/
heatmap_context.rs

1//! Heatmap plot context for cell data separate from cartesian projection.
2
3use leptos::prelude::*;
4
5use crate::{ColorScale, HeatmapCell};
6
7/// Heatmap cell data and color scale provided by [`Heatmap`].
8#[derive(Clone, Debug)]
9pub struct HeatmapPlotContext {
10    /// Cell tuples `[x_index, y_index, value]`.
11    pub cells: Vec<HeatmapCell>,
12    /// Z-axis color scale.
13    pub color_scale: ColorScale,
14    /// Optional domain minimum override.
15    pub value_min: Option<f64>,
16    /// Optional domain maximum override.
17    pub value_max: Option<f64>,
18}
19
20/// Read heatmap cell data from context inside the plot layer.
21pub fn use_heatmap_plot_context() -> HeatmapPlotContext {
22    expect_context::<HeatmapPlotContext>()
23}
24
25/// Provide heatmap plot data to child layers.
26#[component]
27pub fn HeatmapPlotProvider(context: HeatmapPlotContext, children: Children) -> impl IntoView {
28    provide_context(context);
29    children()
30}