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
use std::sync::Arc;
use crate::plot::scatter::MarkerShape;
#[derive(Clone)]
pub struct LegendEntry {
pub label: String,
pub color: String,
pub shape: LegendShape, // useful for scatter vs line
pub dasharray: Option<String>,
}
#[derive(Clone, Copy)]
pub enum LegendShape {
Rect,
Line,
Circle,
Marker(MarkerShape),
CircleSize(f64), // circle with explicit pixel radius; used by the size legend
}
#[derive(Clone)]
pub struct LegendGroup {
pub title: String,
pub entries: Vec<LegendEntry>,
}
pub struct Legend {
pub title: Option<String>,
pub entries: Vec<LegendEntry>,
pub groups: Option<Vec<LegendGroup>>,
pub position: LegendPosition,
pub show_box: bool,
}
impl Default for Legend {
fn default() -> Self {
Self {
title: None,
entries: Vec::new(),
groups: None,
position: LegendPosition::default(),
show_box: true,
}
}
}
#[derive(Default, Clone, Copy)]
pub enum LegendPosition {
// Inside the plot axes area (overlay, ~8px inset from axis edges)
InsideTopRight,
InsideTopLeft,
InsideBottomRight,
InsideBottomLeft,
InsideTopCenter,
InsideBottomCenter,
// Outside — right margin (default)
#[default]
OutsideRightTop,
OutsideRightMiddle,
OutsideRightBottom,
// Outside — left margin
OutsideLeftTop,
OutsideLeftMiddle,
OutsideLeftBottom,
// Outside — top margin
OutsideTopLeft,
OutsideTopCenter,
OutsideTopRight,
// Outside — bottom margin
OutsideBottomLeft,
OutsideBottomCenter,
OutsideBottomRight,
/// Below the plot in auto-computed columns. Canvas height is extended to fit all entries.
OutsideBottomColumns,
// Absolute SVG canvas pixel coordinate
Custom(f64, f64),
// Data-space coordinate — mapped through map_x/map_y at render time
DataCoords(f64, f64),
}
pub struct ColorBarInfo {
pub map_fn: Arc<dyn Fn(f64) -> String + Send + Sync>,
pub min_value: f64,
pub max_value: f64,
pub label: Option<String>,
/// When set, overrides auto-generated ticks. Each entry is `(position, label)` where
/// `position` is in `[min_value, max_value]` space.
pub tick_labels: Option<Vec<(f64, String)>>,
/// When set, overrides auto-generated ticks *and* `tick_labels`. Each entry is
/// `(position, value)` where `position` is in `[min_value, max_value]` space and
/// `value` is the data value to display; the value is formatted through the
/// layout's colorbar tick format at render time. Use this (rather than
/// `tick_labels`) when ticks should honour `Layout::with_colorbar_tick_format`,
/// e.g. log/count colorbars where positions live in log space but labels are raw
/// counts.
pub tick_values: Option<Vec<(f64, f64)>>,
}