From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit 25/38] widget: charts: map: allow drawing connections between points
Date: Fri, 27 Nov 2026 17:12:22 +0100 [thread overview]
Message-ID: <20261127161241.3713494-26-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261127161241.3713494-1-d.csapak@proxmox.com>
so users of the map can show that something moves from one point to
another, e.g. a guest that gets migrated between two locations.
A connection references its two points by their index in the list of
points and is drawn as a quadratic curve between the clusters these
points are in. That way it always ends where the points are actually
drawn. Connections inside of a single cluster are not shown, and all
connections between the same two clusters share one curve.
The curve starts and ends at the radius of the clusters instead of at
their centers, so that the arrow head at its end is not hidden by the
dot of the cluster. It bends upwards like the arc of a flight route,
regardless of its direction. Only if there are connections in both
directions between two clusters, each one bends to the left of its
direction, so they don't overlap. An arrow head at its end shows the
direction. Clusters that are so close that there is no room for a curve
with a visible direction get none.
Each connection can have a label and a tooltip. The label is drawn in
the middle of the curve, and the labels of connections that share a
curve are combined (e.g. '2x Migration, Sync'). It is left out if the
connection is too short for it on the screen, since it would hide most
of the connection then, e.g. on a small map. For the tooltip, reuse the
one of the map, which can now target a connection instead of a cluster.
Since the line itself is too thin to hover it comfortably, connections
with a tooltip get an invisible wider line as hit area.
The look is defined in the style sheet with the new
'pwt-map-connection*' classes, including the pulses that move along a
connection to show its direction. A pulse is drawn as three parts on
top of each other, which all end at its head and get shorter. The style
sheet draws the shorter ones stronger, so that a pulse fades out
towards its tail and its direction is also visible while it stands
still.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/charts/map/mod.rs | 457 +++++++++++++++++++++++++++++++--
src/widget/charts/mod.rs | 2 +-
src/widget/charts/world_map.rs | 8 +-
3 files changed, 449 insertions(+), 18 deletions(-)
diff --git a/src/widget/charts/map/mod.rs b/src/widget/charts/map/mod.rs
index cf236f3..069d386 100644
--- a/src/widget/charts/map/mod.rs
+++ b/src/widget/charts/map/mod.rs
@@ -1,3 +1,4 @@
+use std::collections::BTreeMap;
use std::marker::PhantomData;
use gloo_render::{AnimationFrame, request_animation_frame};
@@ -17,9 +18,9 @@ use crate::client_to_svg_coords;
use crate::dom::align::{AlignOptions, align_to, align_to_xy};
use crate::prelude::*;
use crate::touch::{GestureDetector, GestureDragEvent, GesturePhase, GesturePinchZoomEvent};
-use crate::widget::canvas::{Canvas, Circle, Group};
+use crate::widget::canvas::{Canvas, Circle, Group, Path, Text};
use crate::widget::charts::map::zoom_info::ZoomAction;
-use crate::widget::{Button, Card, Container, Row, SizeObserver, Tooltip};
+use crate::widget::{Button, Card, Column, Container, Row, SizeObserver, Tooltip};
use pwt_macros::{builder, widget};
/// x and y coordinates to represent a position
@@ -44,6 +45,99 @@ impl<T> MapPoint<T> {
}
}
+/// A directed connection between two points of a [Map].
+///
+/// It is drawn as a curve between the clusters that contain the two points, so connections
+/// inside of a single cluster are not shown. All connections between the same two clusters share
+/// one curve, with their labels and tooltips combined.
+#[derive(Clone, PartialEq)]
+pub struct MapConnection {
+ /// Index of the start point in the list of points of the map.
+ pub from: usize,
+ /// Index of the end point in the list of points of the map.
+ pub to: usize,
+ /// A short text that is shown on the connection, for example what kind of connection it is.
+ pub label: Option<AttrValue>,
+ /// The details that are shown when hovering the connection.
+ pub tooltip: Option<Html>,
+}
+
+impl MapConnection {
+ /// Create a new connection between the points with the given indices.
+ pub fn new(from: usize, to: usize) -> Self {
+ Self {
+ from,
+ to,
+ label: None,
+ tooltip: None,
+ }
+ }
+
+ /// Builder style method to set the label.
+ pub fn label(mut self, label: impl Into<AttrValue>) -> Self {
+ self.label = Some(label.into());
+ self
+ }
+
+ /// Builder style method to set the tooltip.
+ pub fn tooltip(mut self, tooltip: impl Into<Html>) -> Self {
+ self.tooltip = Some(tooltip.into());
+ self
+ }
+}
+
+/// Returns the label for curves shared by connections.
+///
+/// Each distinct label is listed once, with the number of its occurrences if there are several.
+fn connection_label(connections: &[&MapConnection]) -> Option<String> {
+ let mut labels_map: BTreeMap<&AttrValue, usize> = BTreeMap::new();
+
+ for connection in connections {
+ let Some(label) = &connection.label else {
+ continue;
+ };
+
+ *labels_map.entry(label).or_insert(0) += 1;
+ }
+
+ if labels_map.is_empty() {
+ return None;
+ }
+
+ let labels: Vec<String> = labels_map
+ .into_iter()
+ .map(|(label, count)| match count {
+ 1 => label.to_string(),
+ count => format!("{count}x {label}"),
+ })
+ .collect();
+ Some(labels.join(", "))
+}
+
+// how far a connection bends away from the straight line, relative to its length
+const CONNECTION_CURVATURE: f64 = 0.2;
+
+// the length of the arrow head of a connection in screen pixels
+const CONNECTION_ARROW_SIZE: f64 = 9.0;
+
+// A pulse of a connection is drawn as several parts on top of each other that all end at its
+// head. These are their lengths relative to the whole pulse. The style sheet draws the shorter
+// ones stronger, so that the pulse fades out towards its tail.
+const CONNECTION_PULSE_PARTS: [f64; 3] = [1.0, 0.6, 0.25];
+
+// A label only fits on a connection that is a few times as long as the label. The width of the
+// label is estimated from the number of its characters, in screen pixels.
+const CONNECTION_LABEL_CHAR_WIDTH: f64 = 7.0;
+const CONNECTION_LABEL_MIN_LENGTH_FACTOR: f64 = 2.0;
+
+/// Whether a label fits on a connection with the given length in screen pixels.
+///
+/// A label on a short connection would hide most of it.
+fn connection_label_fits(label: &str, length: f64) -> bool {
+ let width = label.chars().count() as f64 * CONNECTION_LABEL_CHAR_WIDTH;
+ length >= width * CONNECTION_LABEL_MIN_LENGTH_FACTOR
+}
+
// How fast the shown view follows a change of the view: after this time in milliseconds it has
// covered about two thirds of the way, after three times as long nearly all of it.
const VIEW_ANIMATION_TIME_CONSTANT: f64 = 70.0;
@@ -52,6 +146,110 @@ const VIEW_ANIMATION_TIME_CONSTANT: f64 = 70.0;
// frame time of a common display.
const FIRST_FRAME_TIME: f64 = 1000.0 / 60.0;
+/// A quadratic curve between two circles.
+///
+/// It starts and ends on the circles instead of on their centers.
+#[derive(Debug, Clone, Copy, PartialEq)]
+struct ConnectionCurve {
+ start: Coordinates,
+ control: Coordinates,
+ end: Coordinates,
+}
+
+impl ConnectionCurve {
+ /// Returns the curve between the two circles, or `None` if they are too close for one.
+ ///
+ /// The curve bends upwards like the arc of a flight route. If `separate` is set, it bends to
+ /// the left of its direction instead, so that it does not overlap with a curve in the opposite
+ /// direction.
+ fn new(
+ from: Coordinates,
+ from_radius: f64,
+ to: Coordinates,
+ to_radius: f64,
+ separate: bool,
+ ) -> Option<Self> {
+ let dx = to.x - from.x;
+ let dy = to.y - from.y;
+ if (dx * dx + dy * dy) <= (from_radius + to_radius).powi(2) {
+ return None;
+ }
+
+ // The left of the direction is the upper side when going to the right. A vertical curve
+ // has no upper side, so it bends to the left of the map.
+ let side = if separate || dx > 0.0 || (dx == 0.0 && dy < 0.0) {
+ CONNECTION_CURVATURE
+ } else {
+ -CONNECTION_CURVATURE
+ };
+ let control = Coordinates {
+ x: (from.x + to.x) / 2.0 + dy * side,
+ y: (from.y + to.y) / 2.0 - dx * side,
+ };
+
+ // The curve leaves and enters the points in the direction of the control point. A circle
+ // that reaches the control point leaves no room for a curve that still shows a direction.
+ let towards_control = |point: Coordinates, radius: f64| {
+ let dx = control.x - point.x;
+ let dy = control.y - point.y;
+ let length = (dx * dx + dy * dy).sqrt();
+ (radius < length).then(|| Coordinates {
+ x: point.x + dx / length * radius,
+ y: point.y + dy / length * radius,
+ })
+ };
+
+ Some(Self {
+ start: towards_control(from, from_radius)?,
+ control,
+ end: towards_control(to, to_radius)?,
+ })
+ }
+
+ /// The distance between the start and the end of the curve.
+ fn span(&self) -> f64 {
+ let dx = self.end.x - self.start.x;
+ let dy = self.end.y - self.start.y;
+ (dx * dx + dy * dy).sqrt()
+ }
+
+ /// The SVG path commands that draw the curve.
+ fn path(&self) -> String {
+ format!(
+ "M{:.2},{:.2} Q{:.2},{:.2} {:.2},{:.2}",
+ self.start.x, self.start.y, self.control.x, self.control.y, self.end.x, self.end.y
+ )
+ }
+
+ /// The point halfway along the curve.
+ fn center(&self) -> Coordinates {
+ Coordinates {
+ x: 0.25 * self.start.x + 0.5 * self.control.x + 0.25 * self.end.x,
+ y: 0.25 * self.start.y + 0.5 * self.control.y + 0.25 * self.end.y,
+ }
+ }
+
+ /// The SVG path commands for an arrow head of the given length at the end of the curve.
+ fn arrow_head(&self, length: f64) -> String {
+ // the curve arrives from the direction of the control point
+ let dx = self.end.x - self.control.x;
+ let dy = self.end.y - self.control.y;
+ let scale = length / (dx * dx + dy * dy).sqrt();
+ let (dx, dy) = (dx * scale, dy * scale);
+ // the middle of the base of the arrow head, which is half as wide as the head is long
+ let (x, y) = (self.end.x - dx, self.end.y - dy);
+ format!(
+ "M{:.2},{:.2} L{:.2},{:.2} L{:.2},{:.2} Z",
+ self.end.x,
+ self.end.y,
+ x - dy / 2.0,
+ y + dx / 2.0,
+ x + dy / 2.0,
+ y - dx / 2.0,
+ )
+ }
+}
+
/// An interactive Map that handles interaction (zooming, panning) and draws
/// [MapPoint]s on top of the given SVG element.
///
@@ -62,8 +260,8 @@ const FIRST_FRAME_TIME: f64 = 1000.0 / 60.0;
pub struct Map<T: MapPointData + 'static = AttrValue> {
/// The map as an SVG element.
///
- /// It is drawn in an SVG element of its own below the points, and does not react to the
- /// pointer.
+ /// It is drawn in an SVG element of its own below the points and connections, and does not
+ /// react to the pointer.
map: Html,
#[prop_or(1000.0)]
@@ -81,6 +279,11 @@ pub struct Map<T: MapPointData + 'static = AttrValue> {
/// A list of points to highlight on the map.
points: Vec<MapPoint<T>>,
+ #[prop_or_default]
+ #[builder]
+ /// A list of connections to draw between the points of the map.
+ connections: Vec<MapConnection>,
+
#[prop_or(30.0)]
#[builder]
/// The maximum zoom level that is allowed.
@@ -104,7 +307,7 @@ pub enum Msg {
ButtonZoom(ZoomAction),
PinchZoom(GesturePinchZoomEvent),
Resize(f64, f64),
- Tooltip(Option<(usize, i32, i32)>),
+ Tooltip(Option<(TooltipTarget, i32, i32)>),
ToggleInfo(usize),
CloseInfo,
Drag(GestureDragEvent),
@@ -114,6 +317,22 @@ pub enum Msg {
AnimateView(f64),
}
+/// What the tooltip is shown for.
+#[derive(Clone, Copy, PartialEq)]
+pub enum TooltipTarget {
+ /// The cluster with the given index.
+ Cluster(usize),
+ /// The connections from the first to the second cluster.
+ Connection(usize, usize),
+}
+
+// the connections that share one curve, because they are between the same two clusters
+struct ConnectionGroup<'a> {
+ from: usize,
+ to: usize,
+ connections: Vec<&'a MapConnection>,
+}
+
#[derive(PartialEq, Clone)]
// cache to hold the clustering of the points, can change when the zoom or the fit scale changes
struct Cluster {
@@ -147,7 +366,7 @@ pub struct MapComp<T: Clone + PartialEq> {
pinch_last_center: Coordinates,
fit_scale: f64,
svg_ref: NodeRef,
- tooltip: Option<(usize, i32, i32)>,
+ tooltip: Option<(TooltipTarget, i32, i32)>,
tooltip_ref: NodeRef,
info_anchor_ref: NodeRef,
info_ref: NodeRef,
@@ -161,14 +380,14 @@ pub struct MapComp<T: Clone + PartialEq> {
}
impl<T: MapPointData + 'static> MapComp<T> {
- fn create_tooltip(&self, args: &PointsRenderArgs<T>) -> Html {
+ fn create_tooltip(&self, content: Html) -> Html {
Container::new()
.attribute("role", "tooltip")
.attribute("aria-live", "polite")
.attribute("data-show", Some(""))
.class("pwt-tooltip")
.class("pwt-tooltip-rich")
- .with_child(T::render_tooltip(args))
+ .with_child(content)
.into_html_with_ref(self.tooltip_ref.clone())
}
@@ -231,9 +450,15 @@ impl<T: MapPointData + 'static> MapComp<T> {
.position(|cluster| &cluster.indices == indices)
};
self.info_visible = self.info_visible.and_then(remap);
- self.tooltip = self
- .tooltip
- .and_then(|(index, x, y)| Some((remap(index)?, x, y)));
+ self.tooltip = self.tooltip.and_then(|(target, x, y)| {
+ let target = match target {
+ TooltipTarget::Cluster(index) => TooltipTarget::Cluster(remap(index)?),
+ TooltipTarget::Connection(from, to) => {
+ TooltipTarget::Connection(remap(from)?, remap(to)?)
+ }
+ };
+ Some((target, x, y))
+ });
self.clusters = clusters;
}
@@ -301,6 +526,129 @@ impl<T: MapPointData + 'static> MapComp<T> {
}
}
+ fn group_connections<'a>(&self, ctx: &'a Context<Self>) -> Vec<ConnectionGroup<'a>> {
+ let props = ctx.props();
+
+ let mut cluster_of_point = vec![None; props.points.len()];
+ for (cluster_index, cluster) in self.clusters.iter().enumerate() {
+ for &point_index in &cluster.indices {
+ cluster_of_point[point_index] = Some(cluster_index);
+ }
+ }
+ let cluster_of_point = |index: usize| cluster_of_point.get(index).copied().flatten();
+
+ let mut groups: Vec<ConnectionGroup> = Vec::new();
+ for connection in &props.connections {
+ let (Some(from), Some(to)) = (
+ cluster_of_point(connection.from),
+ cluster_of_point(connection.to),
+ ) else {
+ continue;
+ };
+ if from == to {
+ continue;
+ }
+
+ match groups.iter_mut().find(|g| g.from == from && g.to == to) {
+ Some(group) => group.connections.push(connection),
+ None => groups.push(ConnectionGroup {
+ from,
+ to,
+ connections: vec![connection],
+ }),
+ }
+ }
+ groups
+ }
+
+ /// Renders the connections, and the tooltip if one of them is hovered.
+ fn render_connections(
+ &self,
+ ctx: &Context<Self>,
+ effective_radius: f64,
+ ) -> (Group, Option<Html>) {
+ let link = ctx.link();
+
+ let mut tooltip = None;
+ let mut connections = Group::new();
+
+ let groups = self.group_connections(ctx);
+ for group in &groups {
+ let (from, to) = (&self.clusters[group.from], &self.clusters[group.to]);
+ let has_opposite = groups
+ .iter()
+ .any(|other| other.from == group.to && other.to == group.from);
+ let Some(curve) = ConnectionCurve::new(
+ self.shown_view.map_point(from.center),
+ effective_radius * from.radius_factor(),
+ self.shown_view.map_point(to.center),
+ effective_radius * to.radius_factor(),
+ has_opposite,
+ ) else {
+ continue;
+ };
+ let path = curve.path();
+
+ let mut connection = Group::new().class("pwt-map-connection");
+
+ let tooltips: Vec<Html> = group
+ .connections
+ .iter()
+ .filter_map(|connection| connection.tooltip.clone())
+ .collect();
+ if !tooltips.is_empty() {
+ let target = TooltipTarget::Connection(group.from, group.to);
+ // the line itself is too thin to hover it comfortably
+ connection.add_child(
+ Path::new()
+ .class("pwt-map-connection-hit-area")
+ .d(path.clone()),
+ );
+ connection = connection
+ .onpointermove(link.callback(move |event: PointerEvent| {
+ Msg::Tooltip(Some((target, event.client_x(), event.client_y())))
+ }))
+ .onpointerleave(link.callback(|_| Msg::Tooltip(None)));
+
+ if matches!(self.tooltip, Some((hovered, _, _)) if hovered == target) {
+ let content = Column::new().gap(1).children(tooltips);
+ tooltip = Some(self.create_tooltip(content.into()));
+ }
+ }
+
+ connection.add_child(Path::new().class("pwt-map-connection-line").d(path.clone()));
+ for part in CONNECTION_PULSE_PARTS {
+ connection.add_child(
+ Path::new()
+ .class("pwt-map-connection-pulse")
+ .style("--pwt-map-connection-pulse-part", part.to_string())
+ .d(path.clone()),
+ );
+ }
+ connection.add_child(
+ Path::new()
+ .class("pwt-map-connection-arrow")
+ .d(curve.arrow_head(CONNECTION_ARROW_SIZE / self.fit_scale)),
+ );
+
+ let length = curve.span() * self.fit_scale;
+ if let Some(label) = connection_label(&group.connections)
+ .filter(|label| connection_label_fits(label, length))
+ {
+ let center = curve.center();
+ connection.add_child(
+ Text::new(label)
+ .class("pwt-map-connection-label")
+ .position(center.x as f32, center.y as f32),
+ );
+ }
+
+ connections.add_child(connection);
+ }
+
+ (connections, tooltip)
+ }
+
fn update_info_alignment(&self, ctx: &Context<Self>) {
if let (Some(_), Some(anchor), Some(el)) = (
self.info_visible,
@@ -500,7 +848,7 @@ impl<T: MapPointData + 'static> yew::Component for MapComp<T> {
self.cluster_points(ctx);
}
Msg::Tooltip(tooltip) => {
- let target = |tooltip: Option<(usize, i32, i32)>| Some(tooltip?.0);
+ let target = |tooltip: Option<(TooltipTarget, i32, i32)>| Some(tooltip?.0);
let same_target = target(self.tooltip) == target(tooltip);
self.tooltip = tooltip;
if same_target {
@@ -607,8 +955,8 @@ impl<T: MapPointData + 'static> yew::Component for MapComp<T> {
.class("pwt-map-overlay")
.attribute("viewBox", view_box);
+ let (connections, mut tooltip) = self.render_connections(ctx, effective_radius);
let mut points = Group::new();
- let mut tooltip = None;
let mut info = None;
for (index, cluster) in self.clusters.iter().enumerate() {
@@ -638,7 +986,7 @@ impl<T: MapPointData + 'static> yew::Component for MapComp<T> {
.onpointermove(link.callback(move |event: PointerEvent| {
let x = event.client_x();
let y = event.client_y();
- Msg::Tooltip(Some((index, x, y)))
+ Msg::Tooltip(Some((TooltipTarget::Cluster(index), x, y)))
}))
.onpointerleave(link.callback(move |_| Msg::Tooltip(None)))
.onclick(link.callback(move |event: MouseEvent| {
@@ -665,8 +1013,8 @@ impl<T: MapPointData + 'static> yew::Component for MapComp<T> {
}
match &self.tooltip {
- Some((tooltip_idx, _, _)) if *tooltip_idx == index => {
- tooltip = Some(self.create_tooltip(&args));
+ Some((TooltipTarget::Cluster(tooltip_idx), _, _)) if *tooltip_idx == index => {
+ tooltip = Some(self.create_tooltip(T::render_tooltip(&args)));
}
_ => {}
}
@@ -688,6 +1036,7 @@ impl<T: MapPointData + 'static> yew::Component for MapComp<T> {
.with_child(
GestureDetector::new(
overlay
+ .with_child(connections)
.with_child(points)
.into_html_with_ref(self.svg_ref.clone()),
)
@@ -768,3 +1117,79 @@ impl<T: MapPointData + 'static> yew::Component for MapComp<T> {
self.update_info_alignment(ctx);
}
}
+
+#[cfg(test)]
+mod test {
+ use super::{
+ ConnectionCurve, Coordinates, MapConnection, connection_label, connection_label_fits,
+ };
+
+ #[test]
+ fn test_connection_curve() {
+ let left = Coordinates { x: 0.0, y: 100.0 };
+ let right = Coordinates { x: 100.0, y: 100.0 };
+
+ // bends upwards in both directions
+ let curve = ConnectionCurve::new(left, 0.0, right, 0.0, false).unwrap();
+ assert_eq!(curve.path(), "M0.00,100.00 Q50.00,80.00 100.00,100.00");
+ assert_eq!(curve.center(), Coordinates { x: 50.0, y: 90.0 });
+ let curve = ConnectionCurve::new(right, 0.0, left, 0.0, false).unwrap();
+ assert_eq!(curve.path(), "M100.00,100.00 Q50.00,80.00 0.00,100.00");
+
+ // unless opposite directions have to be kept apart
+ let curve = ConnectionCurve::new(left, 0.0, right, 0.0, true).unwrap();
+ assert_eq!(curve.path(), "M0.00,100.00 Q50.00,80.00 100.00,100.00");
+ let curve = ConnectionCurve::new(right, 0.0, left, 0.0, true).unwrap();
+ assert_eq!(curve.path(), "M100.00,100.00 Q50.00,120.00 0.00,100.00");
+
+ // vertical curves bend to the left of the map, and start and end on the circles
+ let top = Coordinates { x: 0.0, y: 0.0 };
+ let bottom = Coordinates { x: 0.0, y: 100.0 };
+ let curve = ConnectionCurve::new(top, 10.0, bottom, 20.0, false).unwrap();
+ assert_eq!(curve.path(), "M-3.71,9.28 Q-20.00,50.00 -7.43,81.43");
+ let curve = ConnectionCurve::new(bottom, 20.0, top, 10.0, false).unwrap();
+ assert_eq!(curve.path(), "M-7.43,81.43 Q-20.00,50.00 -3.71,9.28");
+
+ // nothing to draw between touching or overlapping circles
+ assert_eq!(ConnectionCurve::new(top, 50.0, bottom, 50.0, false), None);
+ assert_eq!(ConnectionCurve::new(top, 0.0, top, 0.0, false), None);
+ // or if a circle is so big that the curve would end before it bends towards it
+ assert_eq!(ConnectionCurve::new(top, 10.0, bottom, 55.0, false), None);
+ }
+
+ #[test]
+ fn test_arrow_head() {
+ // arrives going down, so the arrow head points down
+ let curve = ConnectionCurve {
+ start: Coordinates { x: 0.0, y: 0.0 },
+ control: Coordinates { x: 50.0, y: 0.0 },
+ end: Coordinates { x: 50.0, y: 100.0 },
+ };
+ assert_eq!(
+ curve.arrow_head(10.0),
+ "M50.00,100.00 L45.00,90.00 L55.00,90.00 Z"
+ );
+ assert_eq!(curve.span(), (50.0f64 * 50.0 + 100.0 * 100.0).sqrt());
+ }
+
+ #[test]
+ fn test_connection_label() {
+ let plain = MapConnection::new(0, 1);
+ let migration = MapConnection::new(0, 1).label("Migration");
+ let sync = MapConnection::new(0, 1).label("Sync");
+
+ assert_eq!(connection_label(&[&plain]), None);
+ assert_eq!(
+ connection_label(&[&migration, &plain]).as_deref(),
+ Some("Migration")
+ );
+ assert_eq!(
+ connection_label(&[&migration, &sync, &migration]).as_deref(),
+ Some("2x Migration, Sync")
+ );
+
+ // 9 characters need a connection of 126 pixels
+ assert!(connection_label_fits("Migration", 126.0));
+ assert!(!connection_label_fits("Migration", 125.0));
+ }
+}
diff --git a/src/widget/charts/mod.rs b/src/widget/charts/mod.rs
index a152b5a..dd254c2 100644
--- a/src/widget/charts/mod.rs
+++ b/src/widget/charts/mod.rs
@@ -2,7 +2,7 @@
mod map;
pub use map::{
- Coordinates, Map, MapPoint, MapPointData, PointsRenderArgs, render_info_default,
+ Coordinates, Map, MapConnection, MapPoint, MapPointData, PointsRenderArgs, render_info_default,
render_point_default, render_tooltip_default,
};
diff --git a/src/widget/charts/world_map.rs b/src/widget/charts/world_map.rs
index 172eab9..2ca00f9 100644
--- a/src/widget/charts/world_map.rs
+++ b/src/widget/charts/world_map.rs
@@ -10,7 +10,7 @@ use yew::virtual_dom::{VComp, VNode};
use crate::prelude::*;
use crate::widget::canvas::{Group, Path};
-use crate::widget::charts::{Coordinates, Map, MapPoint, MapPointData};
+use crate::widget::charts::{Coordinates, Map, MapConnection, MapPoint, MapPointData};
use pwt_macros::{builder, widget};
// the constant size of the svg viewport. also use to project lon/lat to svg coordinates
@@ -84,6 +84,11 @@ pub struct WorldMap<T: MapPointData + 'static> {
/// A list of points to highlight on the map.
points: Vec<MapPoint<T>>,
+ #[prop_or_default]
+ #[builder]
+ /// A list of connections to draw between the points of the map. Forwarded to the inner [Map].
+ connections: Vec<MapConnection>,
+
#[prop_or(30.0)]
#[builder]
/// The maximum zoom level that is allowed. Forwarded to the inner [Map].
@@ -340,6 +345,7 @@ impl<T: MapPointData + 'static> yew::Component for WorldMapComp<T> {
.max_zoom_level(props.max_zoom_level)
.info_point_radius(props.info_point_radius)
.points(props.points.clone())
+ .connections(props.connections.clone())
.into()
}
--
2.47.3
next prev parent reply other threads:[~2026-11-27 16:14 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:11 [PATCH datacenter-manager/proxmox-geojson-data/yew-widget-toolkit/yew-widget-toolkit-assets 00/38] map: show running remote migrations and rework the world map Dominik Csapak
2026-11-27 16:11 ` [PATCH proxmox-geojson-data 01/38] generate the borders between countries as lines without duplicates Dominik Csapak
2026-11-28 19:46 ` Thomas Lamprecht
2026-11-27 16:11 ` [PATCH yew-widget-toolkit-assets 02/38] charts: world map: add classes for the map and its features Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 03/38] charts: map: stack the map and its points in two layers Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 04/38] charts: map: show locations as a dot with a halo Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 05/38] charts: map: show the buttons as one panel Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 06/38] charts: map: add classes for connections Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 07/38] charts: world map: add class for the shade of the night Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 08/38] charts: map: add classes for the shares and the ping of a location Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 09/38] charts: map: add class for the shadow of a connection Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 10/38] charts: map: add class for the labels of locations Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit-assets 11/38] charts: map: add class for the status of a map Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 12/38] widget: charts: map: factor out the radius factor of a cluster Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 13/38] widget: charts: map: close the info card with the first click after a drag Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 14/38] widget: menu: open the menu of a button above it if there is no room below Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 15/38] widget: charts: world map: compare the map data by reference Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 16/38] widget: charts: world map: draw polygons as areas and line strings as lines Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 17/38] widget: charts: world map: split the map into one path per region Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 18/38] widget: charts: map: draw the points in an svg element of their own Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 19/38] widget: charts: map: don't render if the pointer moves over the same point Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 20/38] widget: charts: map: keep the tooltip on its points when clustering anew Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 21/38] widget: charts: world map: add a graticule Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 22/38] widget: charts: map: animate changes of the view Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 23/38] widget: charts: map: draw points as a dot with a halo and their count Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 24/38] widget: charts: map: let the style sheet color the zoom buttons Dominik Csapak
2026-11-27 16:12 ` Dominik Csapak [this message]
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 26/38] widget: charts: map: allow additional buttons in the panel Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 27/38] widget: charts: world map: allow shading the night Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 28/38] widget: charts: map: add helpers to show shares and to ping a point Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 29/38] widget: charts: map: draw a shadow below connections Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 30/38] widget: charts: map: allow showing labels next to the points Dominik Csapak
2026-11-27 16:12 ` [PATCH yew-widget-toolkit 31/38] widget: charts: map: allow showing a status in a corner of the map Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 32/38] ui: views: map: only load and parse the world map once Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 33/38] ui: views: map: only format the titles once when sorting Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 34/38] ui: views: map: show running remote migrations Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 35/38] ui: views: map: shade the night on the map Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 36/38] ui: views: map: show the states of a cluster and ping problems Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 37/38] ui: views: map: show the names of the locations Dominik Csapak
2026-11-27 16:12 ` [PATCH datacenter-manager 38/38] ui: views: map: show a summary of the remotes and migrations Dominik Csapak
2026-11-28 23:48 ` [PATCH datacenter-manager/proxmox-geojson-data/yew-widget-toolkit/yew-widget-toolkit-assets 00/38] map: show running remote migrations and rework the world map Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127161241.3713494-26-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.