From 5c8f22c19d8ff8e0e6c94af0e7703da7e9fdc829 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 6 Oct 2023 16:51:09 +0000 Subject: [PATCH] Fix bar chart references to function x and y, Fix x axis labels and y axis not starting at zero (#95) * fix barchart references to function x and y * fix labels in the chart not being displayed correctly * fix scaling of the y axis Thanks! --- addons/easy_charts/control_charts/chart.gd | 5 +++++ addons/easy_charts/control_charts/plotters/bar_plotter.gd | 6 +++--- addons/easy_charts/utilities/scripts/ec_utilities.gd | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/easy_charts/control_charts/chart.gd b/addons/easy_charts/control_charts/chart.gd index 3b814af..caf2d74 100644 --- a/addons/easy_charts/control_charts/chart.gd +++ b/addons/easy_charts/control_charts/chart.gd @@ -63,6 +63,11 @@ func load_functions(functions: Array[Function]) -> void: self.x.append(function.__x) self.y.append(function.__y) + # Load Labels + if self.x_labels.is_empty(): + if ECUtilities._contains_string(function.__x): + self.x_labels = function.__x + # Create FunctionPlotter var function_plotter: FunctionPlotter = get_function_plotter(function) function_plotter.connect("point_entered", Callable(plot_box, "_on_point_entered")) diff --git a/addons/easy_charts/control_charts/plotters/bar_plotter.gd b/addons/easy_charts/control_charts/plotters/bar_plotter.gd index d53f576..244e666 100644 --- a/addons/easy_charts/control_charts/plotters/bar_plotter.gd +++ b/addons/easy_charts/control_charts/plotters/bar_plotter.gd @@ -26,10 +26,10 @@ func _draw() -> void: func sample(x_sampled_domain: Dictionary, y_sampled_domain: Dictionary) -> void: bars = [] bars_rects = [] - for i in function.x.size(): + for i in function.__x.size(): var top: Vector2 = Vector2( ECUtilities._map_domain(i, x_domain, x_sampled_domain), - ECUtilities._map_domain(function.y[i], y_domain, y_sampled_domain) + ECUtilities._map_domain(function.__y[i], y_domain, y_sampled_domain) ) var base: Vector2 = Vector2(top.x, ECUtilities._map_domain(0.0, y_domain, y_sampled_domain)) bars.push_back(top) @@ -44,7 +44,7 @@ func _input(event: InputEvent) -> void: if event is InputEventMouse: for i in bars_rects.size(): if bars_rects[i].grow(5).abs().has_point(get_relative_position(event.position)): - var point: Point = Point.new(bars_rects[i].get_center(), { x = function.x[i], y = function.y[i]}) + var point: Point = Point.new(bars_rects[i].get_center(), { x = function.__x[i], y = function.__y[i]}) if focused_bar_midpoint == point: return else: diff --git a/addons/easy_charts/utilities/scripts/ec_utilities.gd b/addons/easy_charts/utilities/scripts/ec_utilities.gd index cb811ed..6d137cb 100644 --- a/addons/easy_charts/utilities/scripts/ec_utilities.gd +++ b/addons/easy_charts/utilities/scripts/ec_utilities.gd @@ -45,7 +45,7 @@ static func _find_min_max(values: Array) -> Dictionary: for dim in temp: min_ts.append(dim.min()) max_ts.append(dim.max()) - _min = min_ts.min() + _min = min(min_ts.min(), 0) _max = max(0, max_ts.max()) return { min = _min, max = _max }