| … | … | @@ -10,64 +10,64 @@ signal node_drag_started(node) |
| 10 | 10 | signal node_drag_ended(node) |
| 11 | 11 | |
| 12 | 12 | func _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 | |
| 16 | 16 | |
| 17 | 17 | func _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 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | func 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 | |
| 39 | 39 | |
| 40 | 40 | func _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) | |
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | func _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 | |
| 51 | 51 | |
| 52 | 52 | # 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 |
| 53 | 53 | # to connect the edges to the node, and prevent the edges from overlapping the node and other edges |
| 54 | 54 | func 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 | |
| 58 | 58 | |
| 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 | |
| 62 | 62 | |
| 63 | queue_redraw() | |
| 63 | queue_redraw() | |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | func _ready(): |
| 69 | 69 | |
| 70 | add_to_group("nodes") | |
| 71 | make_offset_circles() | |
| 70 | add_to_group("nodes") | |
| 71 | make_offset_circles() | |
| 72 | 72 | |
| 73 | pass | |
| 73 | pass |
| … | … | @@ -23,3 +23,4 @@ offset_left = -20.0 |
| 23 | 23 | offset_top = -20.0 |
| 24 | 24 | offset_right = 20.0 |
| 25 | 25 | offset_bottom = 3.0 |
| 26 | theme_override_colors/font_color = Color(0, 0, 0, 1) |
| … | … | @@ -4,111 +4,112 @@ extends Node2D |
| 4 | 4 | var edges : Dictionary |
| 5 | 5 | var nodes : Dictionary |
| 6 | 6 | class 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 | ||
| 16 | 16 | func 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 | |
| 36 | 36 | |
| 37 | 37 | func 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()]) | |
| 54 | 55 | |
| 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 | ||
| 72 | 73 | |
| 73 | 74 | |
| 74 | 75 | |
| 75 | 76 | func _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. | |
| 80 | 81 | |
| 81 | 82 | func 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 | |
| 105 | 106 | |
| 106 | file.close() | |
| 107 | return nodes | |
| 107 | file.close() | |
| 108 | return nodes | |
| 108 | 109 | |
| 109 | 110 | |
| 110 | 111 | |
| 111 | 112 | # Called every frame. 'delta' is the elapsed time since the previous frame. |
| 112 | 113 | func _process(delta): |
| 113 | pass | |
| 114 | ||
| 114 | pass | |
| 115 |
| … | … | @@ -1,45 +1,33 @@ |
| 1 | 333 335 313 #SUP: 723 | |
| 2 | 333 335 #SUP: 853 | |
| 3 | 333 270 #SUP: 1158 | |
| 4 | 239 #SUP: 1384 | |
| 5 | 333 239 #SUP: 690 | |
| 6 | 333 264 293 260 295 325 #SUP: 855 | |
| 7 | 333 280 315 293 295 325 #SUP: 970 | |
| 8 | 333 280 293 295 325 #SUP: 1052 | |
| 9 | 333 264 293 295 325 #SUP: 1151 | |
| 10 | 333 293 295 325 #SUP: 2091 | |
| 11 | 333 264 293 260 295 #SUP: 856 | |
| 12 | 333 280 315 293 295 #SUP: 971 | |
| 13 | 333 280 293 295 #SUP: 1055 | |
| 14 | 333 264 293 295 #SUP: 1156 | |
| 15 | 333 293 295 #SUP: 2103 | |
| 16 | 333 264 293 260 #SUP: 866 | |
| 17 | 264 260 #SUP: 2144 | |
| 18 | 333 264 260 #SUP: 1021 | |
| 19 | 264 280 266 #SUP: 760 | |
| 20 | 264 266 #SUP: 2291 | |
| 21 | 333 264 266 #SUP: 1431 | |
| 22 | 333 280 315 293 #SUP: 994 | |
| 23 | 333 280 293 #SUP: 1105 | |
| 24 | 333 264 293 #SUP: 1209 | |
| 25 | 333 293 #SUP: 2303 | |
| 26 | 280 315 282 #SUP: 794 | |
| 27 | 280 282 #SUP: 953 | |
| 28 | 333 282 #SUP: 802 | |
| 29 | 282 #SUP: 2542 | |
| 30 | 264 280 315 #SUP: 822 | |
| 31 | 333 264 280 315 #SUP: 729 | |
| 32 | 333 280 315 #SUP: 2176 | |
| 33 | 280 315 #SUP: 3522 | |
| 34 | 290 #SUP: 3635 | |
| 35 | 264 280 #SUP: 1307 | |
| 36 | 333 264 280 #SUP: 938 | |
| 37 | 333 280 #SUP: 2832 | |
| 38 | 240 280 #SUP: 735 | |
| 39 | 280 #SUP: 5734 | |
| 40 | 333 264 #SUP: 2879 | |
| 41 | 240 264 #SUP: 1397 | |
| 42 | 264 #SUP: 8897 | |
| 43 | 333 #SUP: 9224 | |
| 44 | 240 333 #SUP: 1410 | |
| 45 | 240 #SUP: 14458 | |
| 1 | Environment_and_Natural_Resources Pollution_Management #SUP: 1 | |
| 2 | Climate_Change Climate_Science #SUP: 1 | |
| 3 | Energy_and_Extractives Renewable_Energy Energy_Efficiency #SUP: 1 | |
| 4 | Energy_and_Extractives Climate_Change Renewable_Energy Energy_Efficiency #SUP: 1 | |
| 5 | Energy_and_Extractives Climate_Change Energy_Efficiency #SUP: 1 | |
| 6 | Energy_and_Extractives Energy_Efficiency #SUP: 1 | |
| 7 | Climate_Change Climate_Finance #SUP: 1 | |
| 8 | Energy_and_Extractives Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1 | |
| 9 | Energy_and_Extractives Climate_Change Climate_Change_Mitigation Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1 | |
| 10 | Energy_and_Extractives Renewable_Energy Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1 | |
| 11 | Energy_and_Extractives Climate_Change Renewable_Energy Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1 | |
| 12 | Energy_and_Extractives Climate_Change Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1 | |
| 13 | Energy_and_Extractives Oil_and_Gas_Policy,_Strategy_and_Institutions #SUP: 1 | |
| 14 | Environment_and_Natural_Resources Forests #SUP: 1 | |
| 15 | Climate_Change Environment_and_Natural_Resources Forests #SUP: 1 | |
| 16 | Energy_and_Extractives Climate_Change Renewable_Energy Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane #SUP: 1 | |
| 17 | Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane #SUP: 1 | |
| 18 | Energy_and_Extractives Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) Methane #SUP: 1 | |
| 19 | Energy_and_Extractives Climate_Change Renewable_Energy Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) #SUP: 1 | |
| 20 | Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) #SUP: 1 | |
| 21 | Energy_and_Extractives Climate_Change Climate_Change_Mitigation Short-lived_Climate_Pollutants_(SLCPs) #SUP: 1 | |
| 22 | Energy_and_Extractives Climate_Change Renewable_Energy Climate_Change_Mitigation #SUP: 1 | |
| 23 | Climate_Change Climate_Change_Mitigation #SUP: 1 | |
| 24 | Energy_and_Extractives Climate_Change Climate_Change_Mitigation #SUP: 1 | |
| 25 | Environment_and_Natural_Resources Natural_Resource_Management_ #SUP: 1 | |
| 26 | Climate_Change Natural_Resource_Management_ #SUP: 1 | |
| 27 | Energy_and_Extractives Renewable_Energy #SUP: 1 | |
| 28 | Energy_and_Extractives Climate_Change Renewable_Energy #SUP: 1 | |
| 29 | Environment_and_Natural_Resources Investment_Climate #SUP: 1 | |
| 30 | Climate_Change Environment_and_Natural_Resources #SUP: 1 | |
| 31 | Energy_and_Extractives Environment_and_Natural_Resources #SUP: 1 | |
| 32 | Energy_and_Extractives Health_Emergency_Preparedness_and_Disaster_Response #SUP: 1 | |
| 33 | Energy_and_Extractives Climate_Change #SUP: 1 |
| … | … | @@ -12,7 +12,7 @@ config_version=5 |
| 12 | 12 | |
| 13 | 13 | config/name="Hypergodot" |
| 14 | 14 | run/main_scene="res://main.tscn" |
| 15 | config/features=PackedStringArray("4.0", "Forward Plus") | |
| 15 | config/features=PackedStringArray("4.2", "Forward Plus") | |
| 16 | 16 | config/icon="res://icon.svg" |
| 17 | 17 | |
| 18 | 18 | [dotnet] |
| … | … | @@ -23,6 +23,6 @@ project/assembly_name="Hypergodot" |
| 23 | 23 | |
| 24 | 24 | left_click={ |
| 25 | 25 | "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) | |
| 27 | 27 | ] |
| 28 | 28 | } |