MCPcopy Create free account
hub / github.com/elftausend/graplot / run

Function run

src/render/graph.rs:7–53  ·  view source on GitHub ↗
(graph: Graph)

Source from the content-addressed store, hash-verified

5use super::COLOR_ARRAY;
6
7pub async fn run(graph: Graph) {
8
9 let radius = graph.graph_desc.node_radius;
10 let node_distance_x = graph.graph_desc.node_distance_x;
11 let node_distance_y = graph.graph_desc.node_distance_y;
12 let layers = graph.layers();
13
14 let mut node_coords = HashMap::<usize, (f32, f32)>::new();
15
16 loop {
17 clear_background(WHITE);
18
19 let mut node_count = 0;
20 for layer in &layers {
21 let length = (radius * 2. + (node_distance_x - radius *2.)) * layer.nodes.len() as f32 - (node_distance_x - radius*2.);
22
23
24 for (idx, node) in layer.nodes.iter().enumerate() {
25 let x = screen_width() / 2. + node_distance_x * idx as f32 - length / 2.;
26 let y = 30. + node_distance_y * layer.layer as f32;
27 node_coords.insert(node.idx, (x, y));
28
29 draw_circle(x, y, radius, graph.graph_desc.node_color);
30 draw_circle_lines(x, y, radius, graph.graph_desc.outer_ring.1, graph.graph_desc.outer_ring.0);
31
32 //draw_line(screen_width() / 2. - radius, y, screen_width() / 2. - radius +length, y, 5., BLUE);
33
34 for dep in &node.deps {
35 if let Some((prev_x, prev_y)) = node_coords.get(dep) {
36
37 let color = match graph.graph_desc.egde_color {
38 EdgeColor::Use(color) => color,
39 EdgeColor::Mixed => COLOR_ARRAY[node_count % COLOR_ARRAY.len()],
40 };
41 draw_line(*prev_x, prev_y + radius, x, y - radius, 2., color);
42 }
43
44 }
45 node_count += 1;
46 }
47
48 }
49 next_frame().await;
50 std::thread::sleep(std::time::Duration::from_millis(16));
51 }
52
53}

Callers

nothing calls this directly

Calls 1

layersMethod · 0.80

Tested by

no test coverage detected