(&mut self, ui: &mut Ui)
| 169 | } |
| 170 | |
| 171 | fn samples_widget(&mut self, ui: &mut Ui) -> (UtcTimestamp, UtcTimestamp) { |
| 172 | let plot = Plot::new("trace_counts") |
| 173 | .custom_x_axes(vec![timeaxis::mk_time_axis(Axis::X)]) |
| 174 | .custom_y_axes(vec![AxisHints::new_y().label("Samples")]) |
| 175 | .y_axis_min_width(2.0) |
| 176 | .x_grid_spacer(timeaxis::mk_time_grid) |
| 177 | .allow_drag([true, false]) |
| 178 | .height(100.0) |
| 179 | .label_formatter(|_, val| { |
| 180 | format!( |
| 181 | "Time: {}\nSamples: {:.0}", |
| 182 | timeaxis::ts2chrono(val.x as i64), |
| 183 | val.y |
| 184 | ) |
| 185 | }); |
| 186 | |
| 187 | let response = plot.show(ui, |pui| { |
| 188 | let data_start; |
| 189 | let data_end; |
| 190 | |
| 191 | // If there's a requested time range (from tab action), use it |
| 192 | if let Some((req_start, req_end)) = self.requested_time_range.take() { |
| 193 | data_start = req_start; |
| 194 | data_end = req_end; |
| 195 | |
| 196 | pui.set_plot_bounds(PlotBounds::from_min_max( |
| 197 | [data_start as f64, -f64::MIN], |
| 198 | [data_end as f64, f64::MAX], |
| 199 | )); |
| 200 | } else if let Some(new_lookback) = self.auto_scroll_time { |
| 201 | let now = chrono::Utc::now(); |
| 202 | |
| 203 | data_start = (now - new_lookback).timestamp() as UtcTimestamp; |
| 204 | data_end = now.timestamp() as UtcTimestamp; |
| 205 | |
| 206 | pui.set_plot_bounds(PlotBounds::from_min_max( |
| 207 | [data_start as f64, -f64::MIN], |
| 208 | [data_end as f64, f64::MAX], |
| 209 | )); |
| 210 | } else { |
| 211 | let bounds = pui.plot_bounds(); |
| 212 | data_start = bounds.min()[0] as UtcTimestamp; |
| 213 | data_end = bounds.max()[0] as UtcTimestamp; |
| 214 | } |
| 215 | |
| 216 | let kind = self.kind.clone(); |
| 217 | let points = |
| 218 | self.sample_agg_cache |
| 219 | .get_or_create((kind, data_start, data_end), move || { |
| 220 | DB.trace_events |
| 221 | .event_count_buckets(kind, data_start, data_end, 1000) |
| 222 | .into_iter() |
| 223 | .map(|(time, count)| [time as f64, count as f64]) |
| 224 | .collect() |
| 225 | }); |
| 226 | |
| 227 | pui.line(Line::new("", points.clone())); |
| 228 | pui.set_auto_bounds(egui::Vec2b::new(false, true)); |
no test coverage detected