use std::collections::BTreeMap;
use egui::Context;
use egui::Id;
use egui::Pos2;
use egui::Vec2b;
use crate::axis::PlotTransform;
use crate::bounds::PlotBounds;
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Clone, Debug)]
pub struct PlotMemory {
pub auto_bounds: Vec2b,
pub hovered_legend_item: Option<Id>,
pub hidden_items: ahash::HashSet<Id>,
pub(crate) transform: PlotTransform,
pub(crate) last_click_pos_for_zoom: Option<Pos2>,
pub(crate) x_axis_thickness: BTreeMap<usize, f32>,
pub(crate) y_axis_thickness: BTreeMap<usize, f32>,
}
impl PlotMemory {
#[inline]
pub fn transform(&self) -> PlotTransform {
self.transform
}
#[inline]
pub fn set_transform(&mut self, t: PlotTransform) {
self.transform = t;
}
#[inline]
pub fn bounds(&self) -> &PlotBounds {
self.transform.bounds()
}
#[inline]
pub fn set_bounds(&mut self, bounds: PlotBounds) {
self.transform.set_bounds(bounds);
}
}
#[cfg(feature = "serde")]
impl PlotMemory {
pub fn load(ctx: &Context, id: Id) -> Option<Self> {
ctx.data_mut(|d| d.get_persisted(id))
}
pub fn store(self, ctx: &Context, id: Id) {
ctx.data_mut(|d| d.insert_persisted(id, self));
}
}
#[cfg(not(feature = "serde"))]
impl PlotMemory {
pub fn load(ctx: &Context, id: Id) -> Option<Self> {
ctx.data_mut(|d| d.get_temp(id))
}
pub fn store(self, ctx: &Context, id: Id) {
ctx.data_mut(|d| d.insert_temp(id, self));
}
}