-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Bezier-curve multi (self-)edges (#8256)
### Related <!-- Include links to any related issues/PRs in a bulleted list, for example: * Closes #1234 * Part of #1337 --> * Closes: #8238 ### What This PR brings self-edges in the form of Bezier-curves. <img width="230" alt="image" src="https://github.com/user-attachments/assets/85304534-891b-415d-ab8e-3006afe73058"> It also tries to make multiple edges between the same node more legible by applying a small arc on such edges to prevent overlap. <!-- Make sure the PR title and labels are set to maximize their usefulness for the CHANGELOG, and our `git log`. If you have noticed any breaking changes, include them in the migration guide. We track various metrics at <https://build.rerun.io>. For maintainers: * To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. * To deploy documentation changes immediately after merging this PR, add the `deploy docs` label. -->
- Loading branch information
Showing
14 changed files
with
570 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//! Provides geometric (shape) abstractions for the different elements of a graph layout. | ||
use egui::{Pos2, Rect, Vec2}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum PathGeometry { | ||
/// A simple straight edge. | ||
Line { source: Pos2, target: Pos2 }, | ||
|
||
/// Represents a cubic bezier curve. | ||
/// | ||
/// In the future we could probably support more complex splines. | ||
CubicBezier { | ||
source: Pos2, | ||
target: Pos2, | ||
control: [Pos2; 2], | ||
}, | ||
// We could add other geometries, such as `Orthogonal` here too. | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct EdgeGeometry { | ||
pub target_arrow: bool, | ||
pub path: PathGeometry, | ||
} | ||
|
||
impl EdgeGeometry { | ||
pub fn bounding_rect(&self) -> Rect { | ||
match self.path { | ||
PathGeometry::Line { source, target } => Rect::from_two_pos(source, target), | ||
// TODO(grtlr): This is just a crude (upper) approximation, as the resulting bounding box can be too large. | ||
// For now this is fine, as there are no interactions on edges yet. | ||
PathGeometry::CubicBezier { | ||
source, | ||
target, | ||
ref control, | ||
} => Rect::from_points(&[&[source, target], control.as_slice()].concat()), | ||
} | ||
} | ||
|
||
/// The starting position of an edge. | ||
pub fn source_pos(&self) -> Pos2 { | ||
match self.path { | ||
PathGeometry::Line { source, .. } | PathGeometry::CubicBezier { source, .. } => source, | ||
} | ||
} | ||
|
||
/// The end position of an edge. | ||
pub fn target_pos(&self) -> Pos2 { | ||
match self.path { | ||
PathGeometry::Line { target, .. } | PathGeometry::CubicBezier { target, .. } => target, | ||
} | ||
} | ||
|
||
/// The direction of the edge at the source node (normalized). | ||
pub fn source_arrow_direction(&self) -> Vec2 { | ||
use PathGeometry::{CubicBezier, Line}; | ||
match self.path { | ||
Line { source, target } => (source.to_vec2() - target.to_vec2()).normalized(), | ||
CubicBezier { | ||
source, control, .. | ||
} => (control[0].to_vec2() - source.to_vec2()).normalized(), | ||
} | ||
} | ||
|
||
/// The direction of the edge at the target node (normalized). | ||
pub fn target_arrow_direction(&self) -> Vec2 { | ||
use PathGeometry::{CubicBezier, Line}; | ||
match self.path { | ||
Line { source, target } => (target.to_vec2() - source.to_vec2()).normalized(), | ||
CubicBezier { | ||
target, control, .. | ||
} => (target.to_vec2() - control[1].to_vec2()).normalized(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
mod geometry; | ||
mod provider; | ||
mod request; | ||
mod result; | ||
mod slots; | ||
|
||
pub use geometry::{EdgeGeometry, PathGeometry}; | ||
pub use provider::ForceLayoutProvider; | ||
pub use request::LayoutRequest; | ||
pub use request::{EdgeTemplate, LayoutRequest}; | ||
pub use result::Layout; |
Oops, something went wrong.