Mix colours

This commit is contained in:
2026-05-24 15:28:46 +02:00
parent 4cbf8bff6d
commit 91d549588b
+9 -2
View File
@@ -1,5 +1,6 @@
use eframe::egui; use eframe::egui;
use egui::Vec2b; use egui::ecolor::Hsva;
use egui::{Color32, Vec2b};
use egui_plot::{AxisHints, Legend, Line, Plot, PlotPoints, VPlacement}; use egui_plot::{AxisHints, Legend, Line, Plot, PlotPoints, VPlacement};
use crate::signal::{decimate, nearest_y, PlottedSignal}; use crate::signal::{decimate, nearest_y, PlottedSignal};
@@ -40,6 +41,12 @@ fn full_x_range(signals: &[PlottedSignal]) -> (f64, f64) {
(min, max) (min, max)
} }
fn color_for(id: u64) -> Color32 {
let mixed = (id.wrapping_mul(2654435761)) as u32;
let hue = mixed as f32 / u32::MAX as f32;
Hsva::new(hue, 0.85, 0.9, 1.0).into()
}
fn line_label(sig: &PlottedSignal, cursor_x: Option<f64>) -> String { fn line_label(sig: &PlottedSignal, cursor_x: Option<f64>) -> String {
let unit_suffix = if sig.unit.is_empty() { let unit_suffix = if sig.unit.is_empty() {
String::new() String::new()
@@ -117,7 +124,7 @@ pub fn show_plot_panel(
decimate(&sig.points, x_min, x_max, pixel_width.max(1), &mut buf); decimate(&sig.points, x_min, x_max, pixel_width.max(1), &mut buf);
let plot_points = PlotPoints::Owned(std::mem::take(&mut buf)); let plot_points = PlotPoints::Owned(std::mem::take(&mut buf));
let name = line_label(sig, prev_cursor_x); let name = line_label(sig, prev_cursor_x);
plot_ui.line(Line::new(name, plot_points)); plot_ui.line(Line::new(name, plot_points).color(color_for(sig.id)));
} }
plot_ui.pointer_coordinate().map(|c| c.x) plot_ui.pointer_coordinate().map(|c| c.x)
}); });