Layout graphs in a horizontal direction

This commit is contained in:
Sebastian Morr 2020-10-27 16:10:02 +01:00
parent 4c1d70a99f
commit 00538ee581
2 changed files with 6 additions and 7 deletions

View file

@ -35,15 +35,17 @@ func _process(_delta):
apply_forces() apply_forces()
func apply_forces(): func apply_forces():
var offset = Vector2(0, 80) var offset = Vector2(-80, 0)
for c in children.keys(): for c in children.keys():
if type == "ref" or type == "head":
offset = Vector2(0, 80)
if repository.objects.has(c): if repository.objects.has(c):
var other = repository.objects[c] var other = repository.objects[c]
if other.visible: if other.visible:
var d = other.position.distance_to(position+offset) var d = other.position.distance_to(position+offset)
var dir = (other.position - (position+offset)).normalized() var dir = (other.position - (position+offset)).normalized()
var f = (d*0.03) var f = (d*0.12)
position += dir*f position += dir*f
other.position -= dir*f other.position -= dir*f

View file

@ -148,7 +148,7 @@ func update_node_positions():
var hash_regex = RegEx.new() var hash_regex = RegEx.new()
hash_regex.compile("[a-f0-9]+") hash_regex.compile("[a-f0-9]+")
var regex_match = hash_regex.search(line) 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(): for ref in all_refs():
var target_reference = objects[ref].children.keys()[0] var target_reference = objects[ref].children.keys()[0]
@ -159,9 +159,6 @@ func update_node_positions():
if objects.has(target_reference): if objects.has(target_reference):
var target = objects[target_reference] var target = objects[target_reference]
objects["HEAD"].position = Vector2(target.position.x ,target.position.y - 100) objects["HEAD"].position = Vector2(target.position.x ,target.position.y - 100)
func update_refs(): func update_refs():
for r in all_refs(): for r in all_refs():
@ -193,7 +190,7 @@ func apply_forces():
var center_of_gravity = nodes.rect_size/2 var center_of_gravity = nodes.rect_size/2
var d = o.position.distance_to(center_of_gravity) var d = o.position.distance_to(center_of_gravity)
var dir = (o.position - center_of_gravity).normalized() 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 o.position -= dir*f
func find_position(n): func find_position(n):