Debian Codegraph @

src/components/time_series.rs

raw symbols SCIP
1 mod auto_yrust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/;
2 mod percentrust-analyzer cargo bottom 0.14.9 components/time_series/percent/;
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
5 borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#,
6 cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::{maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max()., minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().},
7 timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::{Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#},
8 };
9
10 pub use auto_yrust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/::*;
11 pub use percentrust-analyzer cargo bottom 0.14.9 components/time_series/percent/::*;
12 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{stylerust-analyzer cargo ratatui-core 0.1.2 style/::Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, symbolsrust-analyzer cargo ratatui-core 0.1.2 symbols/::Markerrust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#, widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::BorderTyperust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#};
13
14 use craterust-analyzer cargo bottom 0.14.9 crate/::canvasrust-analyzer cargo bottom 0.14.9 canvas/::componentsrust-analyzer cargo bottom 0.14.9 canvas/components/::time_seriesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/::{
15 AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#, ChartScalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/ChartScaling#, GraphDatarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#, LegendConstraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#, LegendPositionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/LegendPosition#, TimeGraphrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#,
16 };
17
18 const STALE_MIN_MILLISECONDSrust-analyzer cargo bottom 0.14.9 components/time_series/STALE_MIN_MILLISECONDS.: u64 = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(30).as_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_millis().() as u64;
19
20 /// Configuration values for a [`TimeseriesState`], sourced from [`crate::app::AppConfigFields`].
21 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
22 pub struct TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig# {
23 pub time_intervalrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#time_interval.: u64,
24 pub retention_msrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#retention_ms.: u64,
25 pub autohide_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#autohide_time.: bool,
26 pub default_time_valuerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#default_time_value.: u64,
27 }
28
29 /// A time_series graph widget displays data over a period of time.
30 pub struct TimeseriesStaterust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState# {
31 configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config.: TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#,
32 current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time.: u64,
33 autohide_timerrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#autohide_timer.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#>,
34 }
35
36 impl TimeseriesStaterust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState# {
37 /// Create a new [`TimeseriesState`] using the given config and `autohide_timer` setting.
38 pub fn newrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]new().(config: TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#, autohide_timer: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#>) -> Selfrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState] {
39 Selfrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState] {
40 current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time.: config.default_time_valuerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#default_time_value.,
41 configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config.,
42 autohide_timerrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#autohide_timer.,
43 }
44 }
45
46 /// Get a mutable reference to the autohide timer.
47 pub fn autohide_timer_mutrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]autohide_timer_mut().(&mut self) -> &mut Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#> {
48 &mut self.autohide_timerrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#autohide_timer.
49 }
50
51 /// Get the current display time.
52 pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]current_display_time().(&self) -> u64 {
53 self.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time.
54 }
55
56 /// Zoom in on the x-axis (reducing the time range shown).
57 pub fn zoom_inrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_in().(&mut self) {
58 let new_time = self
59 .current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time.
60 .saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(self.configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config..time_intervalrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#time_interval.);
61 self.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time. = maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(new_time, STALE_MIN_MILLISECONDSrust-analyzer cargo bottom 0.14.9 components/time_series/STALE_MIN_MILLISECONDS.);
62 self.maybe_start_autohiderust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]maybe_start_autohide().();
63 }
64
65 /// Zoom out on the x-axis (increasing the time range shown).
66 pub fn zoom_outrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_out().(&mut self) {
67 let new_time = self
68 .current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time.
69 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_add().(self.configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config..time_intervalrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#time_interval.);
70 self.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time. = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(new_time, self.configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config..retention_msrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#retention_ms.);
71 self.maybe_start_autohiderust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]maybe_start_autohide().();
72 }
73
74 /// Reset the zoom level to the default.
75 pub fn reset_zoomrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]reset_zoom().(&mut self) {
76 self.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time. = self.configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config..default_time_valuerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#default_time_value.;
77 self.maybe_start_autohiderust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]maybe_start_autohide().();
78 }
79
80 fn maybe_start_autohiderust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]maybe_start_autohide().(&mut self) {
81 if self.configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config..autohide_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#autohide_time. {
82 self.autohide_timerrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#autohide_timer. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().());
83 }
84 }
85 }
86
87 /// Per-render context passed to component draw methods. Carries everything that
88 /// varies each frame but is not persistent state.
89 pub struct GraphDrawCtxrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#<'a> {
90 pub titlerust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#title.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>,
91 pub border_stylerust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#border_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
92 pub title_stylerust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#title_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
93 pub graph_stylerust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#graph_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
94 pub general_widget_stylerust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#general_widget_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#,
95 pub border_typerust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#border_type.: BorderTyperust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#,
96 pub markerrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#marker.: Markerrust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#,
97 pub hide_x_labelsrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#hide_x_labels.: bool,
98 pub is_selectedrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#is_selected.: bool,
99 pub is_expandedrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#is_expanded.: bool,
100 pub legend_positionrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#legend_position.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<LegendPositionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/LegendPosition#>,
101 pub legend_constraintsrust-analyzer cargo bottom 0.14.9 components/time_series/GraphDrawCtx#legend_constraints.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<LegendConstraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#>,
102 }
103
104 #[cfg(test)]
105 mod time_series_testsrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/ {
106 use superrust-analyzer cargo bottom 0.14.9 components/time_series/::*;
107
108 const TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.: TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig# = TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig# {
109 time_intervalrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#time_interval.: 15_000,
110 retention_msrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#retention_ms.: 300_000,
111 autohide_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#autohide_time.: false,
112 default_time_valuerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#default_time_value.: 60_000,
113 };
114
115 fn state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(display_time: u64, cfg: TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#) -> TimeseriesStaterust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState# {
116 TimeseriesStaterust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState# {
117 configrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#config.: cfg,
118 current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time.: display_time,
119 autohide_timerrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#autohide_timer.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
120 }
121 }
122
123 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
124 fn zoom_in_decreases_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/zoom_in_decreases_display_time().() {
125 let mut state = state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(60_000, TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.);
126 state.zoom_inrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_in().();
127 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(state.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time., 45_000);
128 }
129
130 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
131 fn zoom_in_clamps_at_minimumrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/zoom_in_clamps_at_minimum().() {
132 let mut state = state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(35_000, TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.);
133 state.zoom_inrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_in().();
134 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(state.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time., STALE_MIN_MILLISECONDSrust-analyzer cargo bottom 0.14.9 components/time_series/STALE_MIN_MILLISECONDS.);
135 }
136
137 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
138 fn zoom_out_increases_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/zoom_out_increases_display_time().() {
139 let mut state = state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(60_000, TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.);
140 state.zoom_outrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_out().();
141 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(state.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time., 75_000);
142 }
143
144 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
145 fn zoom_out_clamps_at_retentionrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/zoom_out_clamps_at_retention().() {
146 let mut state = state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(290_000, TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.);
147 state.zoom_outrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_out().();
148 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(state.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time., 300_000);
149 }
150
151 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
152 fn reset_zoom_restores_defaultrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/reset_zoom_restores_default().() {
153 let mut state = state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(120_000, TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.);
154 state.reset_zoomrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]reset_zoom().();
155 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(state.current_display_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#current_display_time., 60_000);
156 }
157
158 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
159 fn autohide_armed_on_changerust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/autohide_armed_on_change().() {
160 let mut state = state_atrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/state_at().(
161 60_000,
162 TimeseriesConfigrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig# {
163 autohide_timerust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesConfig#autohide_time.: true,
164 ..TEST_CONFIGrust-analyzer cargo bottom 0.14.9 components/time_series/time_series_tests/TEST_CONFIG.
165 },
166 );
167 state.zoom_inrust-analyzer cargo bottom 0.14.9 components/time_series/impl#[TimeseriesState]zoom_in().();
168 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(state.autohide_timerrust-analyzer cargo bottom 0.14.9 components/time_series/TimeseriesState#autohide_timer..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
169 }
170 }
171
172 #[cfg(test)]
173 mod graph_height_testsrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/ {
174 use timelessrust-analyzer cargo timeless 0.1.0 crate/::datarust-analyzer cargo timeless 0.1.0 data/::ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#;
175
176 use superrust-analyzer cargo bottom 0.14.9 components/time_series/::*;
177
178 fn buildrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/build().(times: &[Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#], values: &[f64]) -> ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<f64> {
179 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(times.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), values.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
180 let mut data = ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#::defaultrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`][Default]default().();
181 for &v in values {
182 data.pushrust-analyzer cargo timeless 0.1.0 data/chunked/impl#[`ChunkedData<D>`]push().(v);
183 }
184 data
185 }
186
187 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
188 fn picks_max_across_sourcesrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/picks_max_across_sources().() {
189 let mut cache = GraphHeightCacherust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/GraphHeightCache#::defaultrust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache][Default]default().();
190 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
191 let times = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
192 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(300),
193 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(200),
194 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(100),
195 now,
196 ];
197 let a = buildrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/build().(&times, &[1.0, 2.0, 3.0, 4.0]);
198 let b = buildrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/build().(&times, &[10.0, 5.0, 0.5, 0.25]);
199
200 let result = cache.get_or_updaterust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache]get_or_update().(&now, 1_000, [&a, &b].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().(), &times);
201 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, 10.0);
202 }
203
204 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
205 fn cache_hit_skips_older_pointsrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/cache_hit_skips_older_points().() {
206 // On a cache hit, only points after `right_edge` are rescanned. So if
207 // we pass a fresh source whose only large values are *older* than the
208 // previous `last_time`, the cached max should still win.
209 let mut cache = GraphHeightCacherust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/GraphHeightCache#::defaultrust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache][Default]default().();
210 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
211 let times = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
212 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(200),
213 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(100),
214 now,
215 ];
216 let first = buildrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/build().(&times, &[3.0, 5.0, 7.0]);
217
218 let first_result = cache.get_or_updaterust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache]get_or_update().(&now, 10_000, [&first].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().(), &times);
219 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(first_result, 7.0);
220
221 // Older points carry huge values; newest is small. A full rescan would
222 // return 1000.0 — a true cache hit returns the cached 7.0.
223 let second = buildrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/build().(&times, &[1000.0, 999.0, 4.0]);
224 let second_result = cache.get_or_updaterust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache]get_or_update().(&now, 10_000, [&second].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().(), &times);
225 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(second_result, 7.0);
226 }
227
228 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
229 fn cache_invalidates_on_period_changerust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/cache_invalidates_on_period_change().() {
230 // First call uses a small window that excludes the older high value.
231 // Second call uses a larger window that should include it; a stale
232 // cache would miss it and return the previous max.
233 let mut cache = GraphHeightCacherust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/GraphHeightCache#::defaultrust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache][Default]default().();
234 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
235 let times = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
236 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(500),
237 now -rust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant][`Sub<Duration>`]sub(). Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(50),
238 now,
239 ];
240 let data = buildrust-analyzer cargo bottom 0.14.9 components/time_series/graph_height_tests/build().(&times, &[100.0, 5.0, 7.0]);
241
242 let first = cache.get_or_updaterust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache]get_or_update().(&now, 100, [&data].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().(), &times);
243 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(first, 7.0);
244
245 let second = cache.get_or_updaterust-analyzer cargo bottom 0.14.9 components/time_series/auto_y/impl#[GraphHeightCache]get_or_update().(&now, 1_000, [&data].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().(), &times);
246 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(second, 100.0);
247 }
248 }