From edc4064009b50d015ea8763f901dfff40d49c6ee Mon Sep 17 00:00:00 2001 From: "Tom A. Wagner" Date: Mon, 28 Jun 2021 10:41:56 +0200 Subject: [PATCH] graphview: Place link curve control points more dynamically Control points are now offset by half the x distance of the start and end points instead of a constant, which makes the curve scale better with varying distance. --- src/view/graph_view.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/view/graph_view.rs b/src/view/graph_view.rs index 5391c13..8a3c409 100644 --- a/src/view/graph_view.rs +++ b/src/view/graph_view.rs @@ -152,12 +152,25 @@ mod imp { for link in self.links.borrow().values() { if let Some((from_x, from_y, to_x, to_y)) = self.get_link_coordinates(link) { link_cr.move_to(from_x, from_y); - link_cr.curve_to(from_x + 75.0, from_y, to_x - 75.0, to_y, to_x, to_y); + + // Place curve control offset by half the x distance between the two points. + // This makes the curve scale well for varying distances between the two ports, + // especially when the output port is farther right than the input port. + let half_x_dist = f64::abs(from_x - to_x) / 2.0; + link_cr.curve_to( + from_x + half_x_dist, + from_y, + to_x - half_x_dist, + to_y, + to_x, + to_y, + ); + if let Err(e) = link_cr.stroke() { warn!("Failed to draw graphview links: {}", e); }; } else { - log::warn!("Could not get allocation of ports of link: {:?}", link); + warn!("Could not get allocation of ports of link: {:?}", link); } } }