Skip to content

Commit 15fed4b

Browse files
authored
v0.7.4 (#67) Edge customization, node & edge coloring
2 parents 0848048 + 91433aa commit 15fed4b

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "egui_graphs"
3-
version = "0.7.3"
3+
version = "0.7.4"
44
authors = ["Dmitrii Samsonov <blitzarx1@gmail.com>"]
55
license = "MIT"
66
homepage = "https://github.com/blitzarx1/egui_graphs"

examples/configurable/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod settings;
2121
const SIMULATION_DT: f32 = 0.035;
2222
const FPS_LINE_COLOR: Color32 = Color32::from_rgb(128, 128, 128);
2323
const CHANGES_LIMIT: usize = 100;
24+
const EDGE_COLOR: Color32 = Color32::from_rgba_premultiplied(128, 128, 128, 64);
2425

2526
pub struct ConfigurableApp {
2627
g: Graph<(), (), Directed>,
@@ -654,7 +655,8 @@ impl App for ConfigurableApp {
654655
let settings_style = &egui_graphs::SettingsStyle::new()
655656
.with_labels_always(self.settings_style.labels_always)
656657
.with_edge_radius_weight(self.settings_style.edge_radius_weight)
657-
.with_folded_radius_weight(self.settings_style.edge_radius_weight);
658+
.with_folded_radius_weight(self.settings_style.edge_radius_weight)
659+
.with_edge_color(EDGE_COLOR);
658660
ui.add(
659661
&mut GraphView::new(&mut self.g)
660662
.with_interactions(settings_interaction)

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ pub use self::settings::{SettingsInteraction, SettingsNavigation, SettingsStyle}
1717
pub use self::state_computed::StateComputedNode;
1818
pub use self::subgraphs::SubGraph;
1919
pub use self::transform::{
20-
add_edge, add_node, add_node_custom, default_edge_transform, default_node_transform,
21-
to_input_graph, to_input_graph_custom,
20+
add_edge, add_edge_custom, add_node, add_node_custom, default_edge_transform,
21+
default_node_transform, to_input_graph, to_input_graph_custom,
2222
};

src/settings.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ impl SettingsStyle {
233233
self
234234
}
235235

236+
/// Sets default color for node.
237+
pub fn with_node_color(mut self, color: Color32) -> Self {
238+
self.color_node = color;
239+
self
240+
}
241+
242+
/// Sets default color for edge.
243+
pub fn with_edge_color(mut self, color: Color32) -> Self {
244+
self.color_edge = color;
245+
self
246+
}
247+
236248
pub(crate) fn color_node<N: Clone>(&self, ctx: &egui::Context, n: &Node<N>) -> Color32 {
237249
if n.color().is_some() {
238250
return n.color().unwrap();

src/transform.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
use crate::{graph_view::Graph, Edge, Node};
22
use egui::Vec2;
33
use petgraph::{
4-
data::Build,
54
stable_graph::{EdgeIndex, NodeIndex, StableGraph},
65
visit::IntoNodeReferences,
76
EdgeType,
87
};
9-
use rand::{seq::IteratorRandom, Rng};
8+
use rand::Rng;
109
use std::collections::HashMap;
1110

1211
pub const DEFAULT_SPAWN_SIZE: f32 = 250.;
1312

14-
/// Helper function which adds user's node to the [`egui_graphs::Graph`] instance.
13+
/// Helper function which adds user's node to the [`super::Graph`] instance.
1514
///
1615
/// If graph is not empty it picks any node position and adds new node in the vicinity of it.
1716
pub fn add_node<N: Clone, E: Clone, Ty: EdgeType>(g: &mut Graph<N, E, Ty>, n: &N) -> NodeIndex {
18-
g.add_node(default_node_transform(
19-
NodeIndex::new(g.node_count() + 1),
20-
n,
21-
))
17+
add_node_custom(g, n, default_node_transform)
2218
}
2319

24-
/// Helper function which adds user's node to the [`egui_graphs::Graph`] instance.
20+
/// Helper function which adds user's node to the [`super::Graph`] instance with custom node transform function.
2521
///
2622
/// If graph is not empty it picks any node position and adds new node in the vicinity of it.
2723
pub fn add_node_custom<N: Clone, E: Clone, Ty: EdgeType>(
@@ -32,17 +28,28 @@ pub fn add_node_custom<N: Clone, E: Clone, Ty: EdgeType>(
3228
g.add_node(node_transform(NodeIndex::new(g.node_count() + 1), n))
3329
}
3430

35-
/// Helper function which adds user's edge to the [`egui_graphs::Graph`] instance.
31+
/// Helper function which adds user's edge to the [`super::Graph`] instance.
3632
pub fn add_edge<N: Clone, E: Clone, Ty: EdgeType>(
3733
g: &mut Graph<N, E, Ty>,
3834
start: NodeIndex,
3935
end: NodeIndex,
4036
e: &E,
37+
) -> EdgeIndex {
38+
add_edge_custom(g, start, end, e, default_edge_transform)
39+
}
40+
41+
/// Helper function which adds user's edge to the [`super::Graph`] instance with custom edge transform function.
42+
pub fn add_edge_custom<N: Clone, E: Clone, Ty: EdgeType>(
43+
g: &mut Graph<N, E, Ty>,
44+
start: NodeIndex,
45+
end: NodeIndex,
46+
e: &E,
47+
edge_transform: impl Fn(EdgeIndex, &E) -> Edge<E>,
4148
) -> EdgeIndex {
4249
g.add_edge(
4350
start,
4451
end,
45-
default_edge_transform(EdgeIndex::new(g.edge_count() + 1), e),
52+
edge_transform(EdgeIndex::new(g.edge_count() + 1), e),
4653
)
4754
}
4855

0 commit comments

Comments
 (0)