Skip to content

Commit

Permalink
Fix bar chart references to function x and y, Fix x axis labels and y…
Browse files Browse the repository at this point in the history
… 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!
  • Loading branch information
el-falso authored Oct 6, 2023
1 parent 8bf268b commit 5c8f22c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions addons/easy_charts/control_charts/chart.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 3 additions & 3 deletions addons/easy_charts/control_charts/plotters/bar_plotter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion addons/easy_charts/utilities/scripts/ec_utilities.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 5c8f22c

Please sign in to comment.