re_view_time_series/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
//! Rerun time series View
//!
//! A View that shows plots over Rerun timelines.
// TODO(#6330): remove unwrap()
#![allow(clippy::unwrap_used)]
mod aggregation;
mod line_visualizer_system;
mod point_visualizer_system;
mod series_query;
mod util;
mod view_class;
use re_types::components::{AggregationPolicy, MarkerShape};
use re_viewer_context::external::re_entity_db::InstancePath;
pub use view_class::TimeSeriesView;
/// Computes a deterministic, globally unique ID for the plot based on the ID of the view
/// itself.
///
/// Use it to access the plot's state from anywhere, e.g.:
/// ```ignore
/// let plot_mem = egui_plot::PlotMemory::load(egui_ctx, crate::plot_id(query.view_id));
/// ```
#[inline]
pub(crate) fn plot_id(view_id: re_viewer_context::ViewId) -> egui::Id {
egui::Id::new(("plot", view_id))
}
// ---
#[derive(Clone, Debug)]
pub struct PlotPointAttrs {
pub color: egui::Color32,
/// Radius of markers, or stroke radius for lines.
pub radius_ui: f32,
pub kind: PlotSeriesKind,
}
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
pub struct ScatterAttrs {
pub marker: MarkerShape,
}
impl PartialEq for PlotPointAttrs {
fn eq(&self, rhs: &Self) -> bool {
let Self {
color,
radius_ui,
kind,
} = self;
color.eq(&rhs.color) && radius_ui.total_cmp(&rhs.radius_ui).is_eq() && kind.eq(&rhs.kind)
}
}
impl Eq for PlotPointAttrs {}
#[derive(Clone, Debug, PartialEq)]
struct PlotPoint {
time: i64,
value: f64,
attrs: PlotPointAttrs,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PlotSeriesKind {
Continuous,
Scatter(ScatterAttrs),
Clear,
}
#[derive(Clone, Debug)]
pub struct PlotSeries {
pub instance_path: InstancePath,
/// Id used for this series in the egui plot view.
pub id: egui::Id,
/// Whether the individual series is visible.
///
/// If this is false, [`PlotSeries::points`] is allowed to be empty.
pub visible: bool,
/// Label of the series.
pub label: String,
pub color: egui::Color32,
/// Radius of markers, or stroke radius for lines.
pub radius_ui: f32,
pub kind: PlotSeriesKind,
pub points: Vec<(i64, f64)>,
/// Earliest time an entity was recorded at on the current timeline.
pub min_time: i64,
/// What kind of aggregation was used to compute the graph?
pub aggregator: AggregationPolicy,
/// `1.0` for raw data.
///
/// How many raw data points were aggregated into a single step of the graph?
/// This is an average.
pub aggregation_factor: f64,
}