From af4389ffa6f204b1c74bdbdc5484716f73f09160 Mon Sep 17 00:00:00 2001 From: fenix-hub Date: Sun, 22 Jan 2023 16:35:48 +0100 Subject: [PATCH] add BarChart --- .../easy_charts/utilities/classes/plotting/bar.gd | 12 ++++++++++++ .../classes/plotting/chart_properties.gd | 4 ++-- .../utilities/classes/plotting/point.gd | 2 +- .../utilities/classes/structures/pair.gd | 15 +++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 addons/easy_charts/utilities/classes/plotting/bar.gd diff --git a/addons/easy_charts/utilities/classes/plotting/bar.gd b/addons/easy_charts/utilities/classes/plotting/bar.gd new file mode 100644 index 0000000..b9491dc --- /dev/null +++ b/addons/easy_charts/utilities/classes/plotting/bar.gd @@ -0,0 +1,12 @@ +extends Reference +class_name Bar + +var rect: Rect2 +var value: Pair + +func _init(rect: Rect2, value: Pair = Pair.new()) -> void: + self.value = value + self.rect = rect + +func _to_string() -> String: + return "Value: %s\nRect: %s" % [self.value, self.rect] diff --git a/addons/easy_charts/utilities/classes/plotting/chart_properties.gd b/addons/easy_charts/utilities/classes/plotting/chart_properties.gd index 0db5e41..c6934fc 100644 --- a/addons/easy_charts/utilities/classes/plotting/chart_properties.gd +++ b/addons/easy_charts/utilities/classes/plotting/chart_properties.gd @@ -18,9 +18,8 @@ var bounding_box: bool = true var grid: bool = false var ticks: bool = true var labels: bool = true -var origin: bool = true +var origin: bool = false var points: bool = true -var lines: bool = true var interactive: bool = false var use_splines: bool = false @@ -33,6 +32,7 @@ var colors: Dictionary = { var point_radius: float = 3.0 var line_width: float = 1.0 +var bar_width: float = 10.0 var shapes: Array = [Point.Shape.CIRCLE, Point.Shape.SQUARE, Point.Shape.TRIANGLE, Point.Shape.CROSS] var font: BitmapFont = Label.new().get_font("") diff --git a/addons/easy_charts/utilities/classes/plotting/point.gd b/addons/easy_charts/utilities/classes/plotting/point.gd index f47e6b3..9e13b36 100644 --- a/addons/easy_charts/utilities/classes/plotting/point.gd +++ b/addons/easy_charts/utilities/classes/plotting/point.gd @@ -12,7 +12,7 @@ enum Shape { var position: Vector2 var value: Pair -func _init(position: Vector2, value: Pair) -> void: +func _init(position: Vector2, value: Pair = Pair.new()) -> void: self.value = value self.position = position diff --git a/addons/easy_charts/utilities/classes/structures/pair.gd b/addons/easy_charts/utilities/classes/structures/pair.gd index 5a5f7e4..063e87d 100644 --- a/addons/easy_charts/utilities/classes/structures/pair.gd +++ b/addons/easy_charts/utilities/classes/structures/pair.gd @@ -7,12 +7,19 @@ or of a Vector2 (ex. `var v2: Vector2 = Vector2(0.6, 0.8)`). extends Reference class_name Pair -var left: float -var right: float +var left +var right -func _init(left: float = 0.0, right: float = 0.0) -> void: +func _init(left = null, right = null) -> void: self.left = left self.right = right +func _format(val) -> String: + var format: String = "%s" + match typeof(val): + TYPE_REAL: + "%.2f" + return format % val + func _to_string() -> String: - return "[%.2f, %.2f]" % [self.left, self.right] + return "[%s, %s]" % [_format(self.left), _format(self.right)]