From 849004ed9d6f425397600ee7c8b6a39ef442396e Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Fri, 24 May 2024 03:28:51 +0200 Subject: [PATCH] updated example --- examples/fdg-example/src/main.rs | 40 +++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/fdg-example/src/main.rs b/examples/fdg-example/src/main.rs index 6398079..56f763a 100644 --- a/examples/fdg-example/src/main.rs +++ b/examples/fdg-example/src/main.rs @@ -5,11 +5,13 @@ use asd::{ parser, }; use fdg::{ - fruchterman_reingold::{FruchtermanReingold, FruchtermanReingoldConfiguration}, - nalgebra::Rotation2, + fruchterman_reingold::{ + FruchtermanReingold, FruchtermanReingoldConfiguration, FruchtermanReingoldParallel, + }, petgraph::Graph, - simple::Center, - Force, ForceGraph, + // simple::Center, + Force, + ForceGraph, }; use macroquad::prelude::*; @@ -50,7 +52,7 @@ async fn main() { } let mut force_graph: ForceGraph = - fdg::init_force_graph_uniform(graph, 200.0); + fdg::init_force_graph_uniform(graph, 1000.0); // custom closure force which rotates each node // let mut rotate = |graph: &mut ForceGraph| { @@ -58,9 +60,9 @@ async fn main() { // .node_weights_mut() // .for_each(|(_, p)| *p = Rotation2::new(0.005).transform_point(p)) // }; - let mut force = FruchtermanReingold { + let mut force = FruchtermanReingoldParallel { conf: FruchtermanReingoldConfiguration { - scale: 400.0, + scale: 100.0, ..Default::default() }, ..Default::default() @@ -68,9 +70,9 @@ async fn main() { loop { println!("frame"); - force.apply_many(&mut force_graph, 1); + force.apply_many(&mut force_graph, 2); - Center::default().apply(&mut force_graph); + // Center::default().apply(&mut force_graph); // rotate.apply(&mut force_graph); let scale = calculate_scale(&force_graph); @@ -93,23 +95,23 @@ async fn main() { translate_y(source.coords.column(0)[1], scale), translate_x(target.coords.column(0)[0], scale), translate_y(target.coords.column(0)[1], scale), - 4.0, + 1.0, BLACK, ); } - for ((name, orient), pos) in force_graph.node_weights() { + for ((_name, _orient), pos) in force_graph.node_weights() { let x = translate_x(pos.coords.column(0)[0], scale); let y = translate_y(pos.coords.column(0)[1], scale); - draw_circle(x, y, 20.0 * scale, RED); - draw_text( - format!("{}{}", name, orient).as_str(), - x - 30.0 * scale, - y - 30.0 * scale, - 40.0 * scale, - BLACK, - ); + draw_circle(x, y, 2.0, RED); + // draw_text( + // format!("{}{}", name, orient).as_str(), + // x - 30.0 * scale, + // y - 30.0 * scale, + // 40.0 * scale, + // BLACK, + // ); } next_frame().await