summaryrefslogtreecommitdiff
path: root/addons/project-time-tracker/SectionGraph.gd
diff options
context:
space:
mode:
Diffstat (limited to 'addons/project-time-tracker/SectionGraph.gd')
-rw-r--r--addons/project-time-tracker/SectionGraph.gd44
1 files changed, 44 insertions, 0 deletions
diff --git a/addons/project-time-tracker/SectionGraph.gd b/addons/project-time-tracker/SectionGraph.gd
new file mode 100644
index 0000000..6353889
--- /dev/null
+++ b/addons/project-time-tracker/SectionGraph.gd
@@ -0,0 +1,44 @@
+@tool
+extends HBoxContainer
+
+
+# Public properties
+var section_colors : Dictionary = {}
+
+
+var sections : Dictionary = {}:
+ set(value):
+ sections = value
+ _update_sections()
+
+
+func _update_sections() -> void:
+ if (!is_inside_tree()):
+ return
+
+ var total = 0.0
+ for section in sections:
+ if (section != "Editor"):
+ total += sections[section]
+
+ for section in sections:
+ if (section == "Editor"):
+ continue
+
+ if (get_node_or_null(section)):
+ get_node(section).size_flags_stretch_ratio = sections[section] / total
+ else:
+ var new_section = preload("res://addons/project-time-tracker/TrackerSectionColor.tscn").instantiate()
+ new_section.name = section
+ if section_colors.has(section):
+ new_section.color = section_colors[section]
+ else:
+ new_section.color = section_colors["default"]
+ new_section.size_flags_stretch_ratio = floor(sections[section]) / floor(sections["Editor"])
+ add_child(new_section)
+
+
+func clear():
+ for child_node in get_children():
+ remove_child(child_node)
+ child_node.queue_free()