OverviewFilesCommitsIssuesDocsReleasesPeers

Attila772-hypergodot commits / 2de213f

Use string values for nodes
Use string values for node names, and make the label black, so it can actually be read.
2de213f814e16db6fea9858b5ca78b6576edece1
by Attila772 <71554727+Attila772@users.noreply.github.com> · 2024-02-20T12:36:09.000Z

Changed files (5) +167 -177

HyperNode.gd +38 -38
……@@ -10,64 +10,64 @@ signal node_drag_started(node)
1010signal node_drag_ended(node)
1111
1212func _set_node_id(value : String):
13 node_id = value
14 var label = get_node("Label")
15 label.text = node_id
13 node_id = value
14 var label = get_node("Label")
15 label.text = node_id
1616
1717func _input(event):
18 if event is InputEventMouseButton:
19 if event.button_index == MOUSE_BUTTON_LEFT:
20 if event.pressed:
21 var mouse_pos = get_viewport().get_mouse_position()
22 if get_rect().has_point(mouse_pos):
23 dragging = true
24 drag_offset = mouse_pos - get_position()
25 emit_signal("node_drag_started", self)
26 modulate = Color(1, 2, 1, 0.7)
27 else:
28 if dragging:
29 emit_signal("node_drag_ended", self)
30 modulate = Color(1, 1, 1, 1)
31 dragging = false
18 if event is InputEventMouseButton:
19 if event.button_index == MOUSE_BUTTON_LEFT:
20 if event.pressed:
21 var mouse_pos = get_viewport().get_mouse_position()
22 if get_rect().has_point(mouse_pos):
23 dragging = true
24 drag_offset = mouse_pos - get_position()
25 emit_signal("node_drag_started", self)
26 modulate = Color(1, 2, 1, 0.7)
27 else:
28 if dragging:
29 emit_signal("node_drag_ended", self)
30 modulate = Color(1, 1, 1, 1)
31 dragging = false
3232
3333
3434func get_rect() -> Rect2:
35 var area = Rect2(-25, -25, 50, 50)
36 area.position.x = position.x + area.position.x
37 area.position.y = position.y + area.position.y
38 return area
35 var area = Rect2(-25, -25, 50, 50)
36 area.position.x = position.x + area.position.x
37 area.position.y = position.y + area.position.y
38 return area
3939
4040func _process(delta):
41 if dragging:
42 var mouse_pos = get_viewport().get_mouse_position()
43 set_position(mouse_pos - drag_offset)
41 if dragging:
42 var mouse_pos = get_viewport().get_mouse_position()
43 set_position(mouse_pos - drag_offset)
4444
4545
4646func _draw():
47 #randomize() # Initialize the random number generator
48 #for radius in offset_circles:
49 # draw_circle(Vector2(), radius, Color(randf(), randf(), randf(), 0.5)) # Draw semi-transparent circles with random colors
50 pass
47 #randomize() # Initialize the random number generator
48 #for radius in offset_circles:
49 # draw_circle(Vector2(), radius, Color(randf(), randf(), randf(), 0.5)) # Draw semi-transparent circles with random colors
50 pass
5151
5252# This function should use the edges array, and construct as many circles around the node, with a small offset in the radius, that will be used
5353# to connect the edges to the node, and prevent the edges from overlapping the node and other edges
5454func make_offset_circles():
55 offset_circles.clear() # Reset previous data
56 var circle_count = edges.size()
57 var base_radius = 25 # Starting radius for the smallest circle
55 offset_circles.clear() # Reset previous data
56 var circle_count = edges.size()
57 var base_radius = 25 # Starting radius for the smallest circle
5858
59 for i in range(circle_count):
60 var radius = base_radius + i * 5 # Increase radius for each subsequent circle
61 offset_circles.append(radius) # Store only the radius, as center is the node's position
59 for i in range(circle_count):
60 var radius = base_radius + i * 5 # Increase radius for each subsequent circle
61 offset_circles.append(radius) # Store only the radius, as center is the node's position
6262
63 queue_redraw()
63 queue_redraw()
6464
6565
6666
6767
6868func _ready():
6969
70 add_to_group("nodes")
71 make_offset_circles()
70 add_to_group("nodes")
71 make_offset_circles()
7272
73 pass
73 pass
HyperNode.tscn +1 -0
……@@ -23,3 +23,4 @@ offset_left = -20.0
2323offset_top = -20.0
2424offset_right = 20.0
2525offset_bottom = 3.0
26theme_override_colors/font_color = Color(0, 0, 0, 1)
main.gd +93 -92
……@@ -4,111 +4,112 @@ extends Node2D
44var edges : Dictionary
55var nodes : Dictionary
66class NodeData:
7 var id = 0 # Node identifier
8 var edges = [] # Array to hold edge identifiers (based on line number or custom ID)
9 var support = 0 # Support value
10
11 func _to_string():
12 return "Edges: " + str(edges) + ", Support: " + str(support)
13
14
15
7 var id = 0 # Node identifier
8 var edges = [] # Array to hold edge identifiers (based on line number or custom ID)
9 var support = 0 # Support value
10
11 func _to_string():
12 return "Edges: " + str(edges) + ", Support: " + str(support)
13
14
15
1616func create_nodes(nodes: Dictionary):
17 var scene = load("HyperNode.tscn")
18 var row = 1
19 var column = 1
20 var spacing = Vector2(100, 100)
21 var per_row = 10
22 for id in nodes.keys():
23 var node_instance = scene.instantiate()
24 node_instance.node_id = id
25 node_instance.name = str(id)
26 node_instance.position = Vector2(column * spacing.x, row * spacing.y)
27 node_instance._set_node_id(str(id))
28 node_instance.edges = nodes[id].edges
29
30 add_child(node_instance)
31
32 column += 1
33 if column >= per_row:
34 column = 0
35 row += 1
17 var scene = load("HyperNode.tscn")
18 var row = 1
19 var column = 1
20 var spacing = Vector2(100, 100)
21 var per_row = 10
22 for id in nodes.keys():
23 var node_instance = scene.instantiate()
24 node_instance.node_id = id
25 node_instance.name = str(id)
26 node_instance.position = Vector2(column * spacing.x, row * spacing.y)
27 node_instance._set_node_id(str(id))
28 node_instance.edges = nodes[id].edges
29
30 add_child(node_instance)
31
32 column += 1
33 if column >= per_row:
34 column = 0
35 row += 1
3636
3737func populate_edge_data():
38 var hyperedge_scene = load("res://HyperEdge.tscn")
39 for node_id in nodes:
40 var node_edges = nodes[node_id].edges
41 var circle_ref = get_node(str(node_id)) # Assuming this gets a node instance with 'offset_circles' available
42 var offset_circles = circle_ref.offset_circles # List of radii for offset circles
43 for edge_index in range(node_edges.size()):
44 var edge_id = node_edges[edge_index]
45 if not edges.has(edge_id):
46 edges[edge_id] = {"nodes": [], "radii": []}
47
48 if edge_index < offset_circles.size(): # Ensure there's a corresponding circle
49 var radius = offset_circles[edge_index]
50 edges[edge_id]["nodes"].append(node_id)
51 edges[edge_id]["radii"].append(radius)
52 else:
53 print("Error: Node %s has more edges (%s) than offset circles provided." % [node_id, node_edges.size()])
38 var hyperedge_scene = load("res://HyperEdge.tscn")
39 for node_id in nodes:
40 var node_edges = nodes[node_id].edges
41 print(nodes)
42 var circle_ref = get_node(str(node_id)) # Assuming this gets a node instance with 'offset_circles' available
43 var offset_circles = circle_ref.offset_circles # List of radii for offset circles
44 for edge_index in range(node_edges.size()):
45 var edge_id = node_edges[edge_index]
46 if not edges.has(edge_id):
47 edges[edge_id] = {"nodes": [], "radii": []}
48
49 if edge_index < offset_circles.size(): # Ensure there's a corresponding circle
50 var radius = offset_circles[edge_index]
51 edges[edge_id]["nodes"].append(node_id)
52 edges[edge_id]["radii"].append(radius)
53 else:
54 print("Error: Node %s has more edges (%s) than offset circles provided." % [node_id, node_edges.size()])
5455
55 for edge_id in edges:
56 var hyperedge_instance = hyperedge_scene.instantiate()
57 var edge_data = edges[edge_id]
58 var node_radii_pairs = {}
59 for i in range(edge_data["nodes"].size()):
60 var nodeid = edge_data["nodes"][i]
61 var radius = edge_data["radii"][i]
62 node_radii_pairs[nodeid] = radius
63 hyperedge_instance.nodes = node_radii_pairs
64
65 var color = Color(randf(), randf(), randf(), 0.3) # Generate a random color
66 hyperedge_instance.color = color
67 add_child(hyperedge_instance)
68
69
70
71
56 for edge_id in edges:
57 var hyperedge_instance = hyperedge_scene.instantiate()
58 var edge_data = edges[edge_id]
59 var node_radii_pairs = {}
60 for i in range(edge_data["nodes"].size()):
61 var nodeid = edge_data["nodes"][i]
62 var radius = edge_data["radii"][i]
63 node_radii_pairs[nodeid] = radius
64 hyperedge_instance.nodes = node_radii_pairs
65
66 var color = Color(randf(), randf(), randf(), 0.5) # Generate a random color
67 hyperedge_instance.color = color
68 add_child(hyperedge_instance)
69
70
71
72
7273
7374
7475
7576func _ready():
76 nodes = read_file("patterns.txt")
77 create_nodes(nodes)
78 populate_edge_data()
79 pass # Replace with function body.
77 nodes = read_file("patterns.txt")
78 create_nodes(nodes)
79 populate_edge_data()
80 pass # Replace with function body.
8081
8182func read_file(path):
82 var file = FileAccess.open(path, FileAccess.READ)
83 var nodes = {} # Dictionary to hold all nodes
84 var edge_id = 0 # Unique identifier for each edge, can use line number as well
85
86 while not file.eof_reached():
87 var line = file.get_line().strip_edges()
88 if line.find("#SUP:") == -1:
89 continue # Skip this line
90 var parts = line.split(" #SUP: ")
91 var node_ids = parts[0].split(" ")
92 var support = int(parts[1])
93
94 # Process each node ID in the line
95 for node_id in node_ids:
96 var id = int(node_id)
97 if not nodes.has(id):
98 nodes[id] = NodeData.new()
99 # Always append the edge_id to the node's edges array
100 nodes[id].edges.append(edge_id)
101 # Update the support value
102 nodes[id].support = max(nodes[id].support, support)
103
104 edge_id += 1 # Increment edge ID for the next line
83 var file = FileAccess.open(path, FileAccess.READ)
84 var nodes = {} # Dictionary to hold all nodes
85 var edge_id = 0 # Unique identifier for each edge, can use line number as well
86
87 while not file.eof_reached():
88 var line = file.get_line().strip_edges()
89 if line.find("#SUP:") == -1:
90 continue # Skip this line
91 var parts = line.split(" #SUP: ")
92 var node_ids = parts[0].split(" ")
93 var support = int(parts[1])
94
95 # Process each node ID in the line
96 for node_id in node_ids:
97 var id = node_id
98 if not nodes.has(id):
99 nodes[id] = NodeData.new()
100 # Always append the edge_id to the node's edges array
101 nodes[id].edges.append(edge_id)
102 # Update the support value
103 nodes[id].support = max(nodes[id].support, support)
104
105 edge_id += 1 # Increment edge ID for the next line
105106
106 file.close()
107 return nodes
107 file.close()
108 return nodes
108109
109110
110111
111112# Called every frame. 'delta' is the elapsed time since the previous frame.
112113func _process(delta):
113 pass
114
114 pass
115
patterns.txt +33 -45
……@@ -1,45 +1,33 @@
1333 335 313 #SUP: 723
2333 335 #SUP: 853
3333 270 #SUP: 1158
4239 #SUP: 1384
5333 239 #SUP: 690
6333 264 293 260 295 325 #SUP: 855
7333 280 315 293 295 325 #SUP: 970
8333 280 293 295 325 #SUP: 1052
9333 264 293 295 325 #SUP: 1151
10333 293 295 325 #SUP: 2091
11333 264 293 260 295 #SUP: 856
12333 280 315 293 295 #SUP: 971
13333 280 293 295 #SUP: 1055
14333 264 293 295 #SUP: 1156
15333 293 295 #SUP: 2103
16333 264 293 260 #SUP: 866
17264 260 #SUP: 2144
18333 264 260 #SUP: 1021
19264 280 266 #SUP: 760
20264 266 #SUP: 2291
21333 264 266 #SUP: 1431
22333 280 315 293 #SUP: 994
23333 280 293 #SUP: 1105
24333 264 293 #SUP: 1209
25333 293 #SUP: 2303
26280 315 282 #SUP: 794
27280 282 #SUP: 953
28333 282 #SUP: 802
29282 #SUP: 2542
30264 280 315 #SUP: 822
31333 264 280 315 #SUP: 729
32333 280 315 #SUP: 2176
33280 315 #SUP: 3522
34290 #SUP: 3635
35264 280 #SUP: 1307
36333 264 280 #SUP: 938
37333 280 #SUP: 2832
38240 280 #SUP: 735
39280 #SUP: 5734
40333 264 #SUP: 2879
41240 264 #SUP: 1397
42264 #SUP: 8897
43333 #SUP: 9224
44240 333 #SUP: 1410
45240 #SUP: 14458
1Environment_and_Natural_Resources Pollution_Management #SUP: 1
2Climate_Change Climate_Science #SUP: 1
3Energy_and_Extractives Renewable_Energy Energy_Efficiency #SUP: 1
4Energy_and_Extractives Climate_Change Renewable_Energy Energy_Efficiency #SUP: 1
5Energy_and_Extractives Climate_Change Energy_Efficiency #SUP: 1
6Energy_and_Extractives Energy_Efficiency #SUP: 1
7Climate_Change Climate_Finance #SUP: 1
8Energy_and_Extractives Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1
9Energy_and_Extractives Climate_Change Climate_Change_Mitigation Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1
10Energy_and_Extractives Renewable_Energy Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1
11Energy_and_Extractives Climate_Change Renewable_Energy Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1
12Energy_and_Extractives Climate_Change Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1
13Energy_and_Extractives Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1
14Environment_and_Natural_Resources Forests #SUP: 1
15Climate_Change Environment_and_Natural_Resources Forests #SUP: 1
16Energy_and_Extractives Climate_Change Renewable_Energy Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane #SUP: 1
17Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane #SUP: 1
18Energy_and_Extractives Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane #SUP: 1
19Energy_and_Extractives Climate_Change Renewable_Energy Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) #SUP: 1
20Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) #SUP: 1
21Energy_and_Extractives Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) #SUP: 1
22Energy_and_Extractives Climate_Change Renewable_Energy Climate_Change_Mitigation #SUP: 1
23Climate_Change Climate_Change_Mitigation #SUP: 1
24Energy_and_Extractives Climate_Change Climate_Change_Mitigation #SUP: 1
25Environment_and_Natural_Resources Natural_Resource_Management_ #SUP: 1
26Climate_Change Natural_Resource_Management_ #SUP: 1
27Energy_and_Extractives Renewable_Energy #SUP: 1
28Energy_and_Extractives Climate_Change Renewable_Energy #SUP: 1
29Environment_and_Natural_Resources Investment_Climate #SUP: 1
30Climate_Change Environment_and_Natural_Resources #SUP: 1
31Energy_and_Extractives Environment_and_Natural_Resources #SUP: 1
32Energy_and_Extractives Health_Emergency_Preparedness_and_Disaster_Response #SUP: 1
33Energy_and_Extractives Climate_Change #SUP: 1
project.godot +2 -2
……@@ -12,7 +12,7 @@ config_version=5
1212
1313config/name="Hypergodot"
1414run/main_scene="res://main.tscn"
15config/features=PackedStringArray("4.0", "Forward Plus")
15config/features=PackedStringArray("4.2", "Forward Plus")
1616config/icon="res://icon.svg"
1717
1818[dotnet]
……@@ -23,6 +23,6 @@ project/assembly_name="Hypergodot"
2323
2424left_click={
2525"deadzone": 0.5,
26"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
26"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
2727]
2828}