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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use iced::Rectangle;
use crate::{camera::Camera, series::ShapeId, ticks::PositionedTick};
/// Messages sent by the plot widget to the application.
///
/// These messages are generated in response to user interactions with the plot.
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone)]
pub enum PlotUiMessage {
/// Toggle the legend visibility.
ToggleLegend,
/// Toggle the in-canvas controls/help overlay.
ToggleControlsOverlay,
/// Toggle visibility of a series or reference line by label.
ToggleSeriesVisibility(ShapeId),
/// Internal render update message.
RenderUpdate(PlotRenderUpdate),
}
impl PlotUiMessage {
/// Get the hover or pick event from the render update.
/// If the plot widget is not in hover or pick mode, this will return None.
pub fn get_hover_pick_event(&self) -> Option<HoverPickEvent> {
if let PlotUiMessage::RenderUpdate(update) = self {
update.hover_pick
} else {
None
}
}
/// Get the drag event from the render update.
pub fn get_drag_event(&self) -> Option<DragEvent> {
if let PlotUiMessage::RenderUpdate(update) = self {
update.drag_event
} else {
None
}
}
}
/// Context passed to hover/pick highlight callbacks.
///
/// Contains information identifying the point being highlighted.
#[derive(Debug, Clone, Copy)]
pub struct TooltipContext<'a> {
/// ID of the series
pub series_id: ShapeId,
/// Label of the series, if any (empty string means none)
pub series_label: &'a str,
/// Index within the series [0..len)
pub point_index: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TooltipUiPayload {
/// screen coordinates of the tooltip.
/// `screen_xy = None` means the tooltip is outside of the plot widget
pub screen_xy: Option<[f32; 2]>,
pub text: String,
}
/// Payload for the small cursor-position overlay shown in the corner.
#[derive(Debug, Clone)]
pub struct CursorPositionUiPayload {
/// World/data-space coordinates for the cursor
pub x: f64,
pub y: f64,
/// Formatted text to render
pub text: String,
}
#[derive(Debug, Clone)]
#[doc(hidden)]
pub struct PlotRenderUpdate {
pub hover_pick: Option<HoverPickEvent>,
pub drag_event: Option<DragEvent>,
pub clear_cursor_position: bool,
pub cursor_position_ui: Option<CursorPositionUiPayload>,
pub x_ticks: Option<Vec<PositionedTick>>,
pub y_ticks: Option<Vec<PositionedTick>>,
/// Internal: Camera and bounds for coordinate conversion (only used internally, not part of public API)
pub(crate) camera_bounds: Option<Box<(Camera, Rectangle)>>,
}
/// Drag interaction event in data/world coordinates.
#[derive(Debug, Clone, Copy)]
pub enum DragEvent {
/// A drag gesture started inside the plot.
Start {
/// Mouse button that initiated the drag stream.
button: iced::mouse::Button,
/// Current cursor world/data coordinate.
world: [f64; 2],
},
/// Cursor moved while drag is active.
Update {
/// Mouse button that initiated the drag stream.
button: iced::mouse::Button,
/// Current cursor world/data coordinate.
world: [f64; 2],
},
/// Active drag gesture ended.
End {
/// Mouse button that initiated the drag stream.
button: iced::mouse::Button,
/// Current cursor world/data coordinate.
world: [f64; 2],
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
/// Identifier for a point in a series.
pub struct PointId {
/// ID of the series
pub series_id: ShapeId,
/// Index within the series [0..len)
pub point_index: usize,
}
/// The hover or pick event.
#[derive(Debug, Clone, Copy)]
pub enum HoverPickEvent {
/// Hover a point.
Hover(PointId),
/// Clear all hovered points.
ClearHover,
/// Pick a point.
Pick(PointId),
/// Clear all picked points.
ClearPick,
}