From 00538ee581810819352e00dd226f5e471665f849 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 27 Oct 2020 16:10:02 +0100 Subject: [PATCH] Layout graphs in a horizontal direction --- scenes/node.gd | 6 ++++-- scenes/repository.gd | 7 ++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scenes/node.gd b/scenes/node.gd index 2ec378e..1d41964 100644 --- a/scenes/node.gd +++ b/scenes/node.gd @@ -35,15 +35,17 @@ func _process(_delta): apply_forces() func apply_forces(): - var offset = Vector2(0, 80) + var offset = Vector2(-80, 0) for c in children.keys(): + if type == "ref" or type == "head": + offset = Vector2(0, 80) if repository.objects.has(c): var other = repository.objects[c] if other.visible: var d = other.position.distance_to(position+offset) var dir = (other.position - (position+offset)).normalized() - var f = (d*0.03) + var f = (d*0.12) position += dir*f other.position -= dir*f diff --git a/scenes/repository.gd b/scenes/repository.gd index 4972f17..8221bb4 100644 --- a/scenes/repository.gd +++ b/scenes/repository.gd @@ -148,7 +148,7 @@ func update_node_positions(): var hash_regex = RegEx.new() hash_regex.compile("[a-f0-9]+") var regex_match = hash_regex.search(line) - objects[regex_match.get_string()].position = Vector2(star_idx * 100 + 500, line_count * 100 + 500) + objects[regex_match.get_string()].position = Vector2((graph_lines.size()-line_count) * 100 + 500, star_idx * 100 + 500) for ref in all_refs(): var target_reference = objects[ref].children.keys()[0] @@ -159,9 +159,6 @@ func update_node_positions(): if objects.has(target_reference): var target = objects[target_reference] objects["HEAD"].position = Vector2(target.position.x ,target.position.y - 100) - - - func update_refs(): for r in all_refs(): @@ -193,7 +190,7 @@ func apply_forces(): var center_of_gravity = nodes.rect_size/2 var d = o.position.distance_to(center_of_gravity) var dir = (o.position - center_of_gravity).normalized() - var f = (d+0.00001)*(Vector2(nodes.rect_size.y, nodes.rect_size.x/3).normalized()/30) + var f = (d+0.00001)*(Vector2(nodes.rect_size.y/10, nodes.rect_size.x/3).normalized()/30) o.position -= dir*f func find_position(n):