fenix-hub / godot-engine.easy-charts

A Godot Engine addon for plotting general purpose charts. A collection of Control, 2D and 3D Nodes to plot every chart possible.
MIT License
638 stars 48 forks source link

[BUG] Graph does not rescale correctly when mimimizing or maximizing window. #109

Open hansonry opened 3 weeks ago

hansonry commented 3 weeks ago

Describe the bug It's in the title.

To Reproduce Steps to reproduce the behavior:

  1. Run an example.
  2. Maximize the window.
  3. Notice the graph doesn't rescale correctly.

Expected behavior The graph should rescale along with the lines.

Screenshots Running the line_chart example.

At launch:

Screenshot from 2024-08-29 22-00-18

After maximizing and minimizing:

Screenshot from 2024-08-29 22-00-28

Desktop (please complete the following information):

Additional context Seems like the root cause is that get_rect() (being called inside BoxPlot.get_box() and BoxPlot.get_plot_box()) doesn't update right away. So some parts of the redraw are scaled incorrectly.

I think I fixed it by adding this code to box_plot.gd:

func _on_resized() -> void:
    $GridBox.queue_redraw()
    for function in $FunctionsBox.get_children():
        function.queue_redraw()

_on_resized is connected to the BoxPlot resized signal.

This seems to fix the issue. I have no idea if this is the correct way to fix it or if it is the most efficient. I am not even clear on why this is necessary, seems like it would make sense for Godot to not call queue_redraw() until all the parents are updated. I probably don't understand the code well enough. Anyway, I hope this is helpful!