Add vertical axis ticks to graph
This commit is contained in:
parent
1d8ba23969
commit
a3529772cd
|
@ -124,6 +124,15 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "axis-ticks"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b8d71f0cd2d8ee5cdf22cc6405287931603f7aa312f6eee0f356320d72f08b1"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.63"
|
||||
|
@ -154,6 +163,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"appdirs",
|
||||
"axis-ticks",
|
||||
"bare-metrics-core",
|
||||
"bare-metrics-reader",
|
||||
"eframe",
|
||||
|
|
|
@ -21,3 +21,4 @@ rfd = "0.6.1"
|
|||
ron = "0.7.0"
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
appdirs = "0.2.0"
|
||||
axis-ticks = "0.1.0"
|
||||
|
|
|
@ -4,7 +4,8 @@ use bare_metrics_core::structures::{
|
|||
};
|
||||
use bare_metrics_reader::{MetricsLogReader, SeekToken};
|
||||
use eframe::egui::{
|
||||
Color32, Frame as EguiFrame, PointerButton, Pos2, Rect, Sense, Stroke, Ui, Vec2,
|
||||
Color32, Frame as EguiFrame, Galley, PointerButton, Pos2, Rect, Sense, Stroke, TextStyle, Ui,
|
||||
Vec2,
|
||||
};
|
||||
use hdrhistogram::Histogram;
|
||||
use log::{debug, error, info};
|
||||
|
@ -762,13 +763,43 @@ impl Graph {
|
|||
// let display_transform =
|
||||
// emath::RectTransform::from_to(Rect::from_x_y_ranges(x_axis, y_axis), display_rect);
|
||||
|
||||
let display_transform =
|
||||
GraphTransform::from_ranges_and_display_rect(x_axis, y_axis, display_rect);
|
||||
let display_transform = GraphTransform::from_ranges_and_display_rect(
|
||||
x_axis.clone(),
|
||||
y_axis.clone(),
|
||||
display_rect,
|
||||
);
|
||||
|
||||
let stroke = Stroke::new(2.0, Color32::GREEN);
|
||||
|
||||
let mut last_point = None;
|
||||
|
||||
let ticks = axis_ticks::ticks(y_axis.start().clone(), y_axis.end().clone(), 10);
|
||||
let tick_stroke = Stroke {
|
||||
width: 0.5,
|
||||
color: Color32::LIGHT_GRAY,
|
||||
};
|
||||
for tick in ticks {
|
||||
let text = ui.fonts().layout_no_wrap(
|
||||
format!("{}", tick),
|
||||
TextStyle::Small,
|
||||
Color32::LIGHT_GRAY,
|
||||
);
|
||||
|
||||
let mut text_rect = text.rect;
|
||||
text_rect.set_center(display_transform * (*x_axis.start(), tick));
|
||||
text_rect.set_left(display_rect.left());
|
||||
ui.painter().line_segment(
|
||||
[
|
||||
display_transform * (*x_axis.start(), tick)
|
||||
+ Vec2::new(5.0 + text.rect.width(), 0.0),
|
||||
display_transform * (*x_axis.end(), tick),
|
||||
],
|
||||
tick_stroke,
|
||||
);
|
||||
|
||||
ui.painter().galley(text_rect.left_top(), text);
|
||||
}
|
||||
|
||||
if let Some(scalar) = current_window
|
||||
.counters
|
||||
.get(&metric_id)
|
||||
|
|
Loading…
Reference in New Issue