hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.94k stars 676 forks source link

mouse pos in plot and axis limit range #1028

Open tiantian1645 opened 3 years ago

tiantian1645 commented 3 years ago

Version of Dear PyGui

Version: 0.816 Operating System: Windows 10

My Issue/Question

I do not think you fix in https://github.com/hoffstadt/DearPyGui/issues/912#issuecomment-875196074

        mouse_x, mouse_y = dpg.get_plot_mouse_pos()
        ymin, ymax = dpg.get_axis_limits(self.plot_axis_y)
        xmin, xmax = dpg.get_axis_limits(self.plot_axis_x)

mouse_x will always larger than xmin mouse_y will always larger than ymin

To Reproduce

use add_mouse_wheel_handler to print

dpg.get_plot_mouse_pos() dpg.get_axis_limits(self.plot_axis_y) dpg.get_axis_limits(self.plot_axis_x)

Expected behavior

mouse_x should less than xmin when mouse in y axis left side mouse_y should less than ymin when mouse below x axis

Screenshots/Video

Snipaste_2021-07-07_09-49-01

Standalone, minimal, complete and verifiable example

from math import cos, pi, sin
import dearpygui.dearpygui as dpg

with dpg.window(label="Label", width=800, height=600):
    with dpg.plot(label="plot_name", width=-1, height=-1):
        dpg.add_plot_legend()
        plot_axis_x = dpg.add_plot_axis(dpg.mvXAxis, label="")
        plot_axis_y = dpg.add_plot_axis(dpg.mvYAxis, label="")
        plot_id = dpg.last_item()
        series_id_1 = dpg.add_line_series(list(range(5)), list(cos(i * pi / 100) for i in range(5)), label="Test 1", parent=plot_id, contribute_to_bounds=False)

def on_mouse_wheel_callback(sender, app_data):
    mouse_x, mouse_y = dpg.get_plot_mouse_pos()
    ymin, ymax = dpg.get_axis_limits(plot_axis_y)
    print(f"ymin {ymin} mouse_y {mouse_y} {mouse_y < ymin}")

with dpg.handler_registry():
    dpg.add_mouse_wheel_handler(callback=on_mouse_wheel_callback)

dpg.start_dearpygui()
hoffstadt commented 3 years ago

Will check again.

hoffstadt commented 3 years ago

This is not actually a bug. dpg.get_plot_mouse_pos() returns the last recorded position of the mouse when it was on the plot. If you move the mouse off too quickly, the position will not necessary update to the boundary. Depends on the frame rate.

You can check this by slowly moving the mouse out of the plot region. You will see the value gets closer to the boundary.

The best course of action is to check if the plot is hovered BEFORE calling dpg.get_plot_mouse_pos().

hoffstadt commented 3 years ago

Let me know if this makes sense.

tiantian1645 commented 3 years ago

I just want to disguish these

Scroll Mouse Wheel: zooms
Scroll Mouse Wheel on Axis: zooms only that axis

But now dpg.get_plot_mouse_pos smaller than dpg.get_axis_limits, How can I check if mouse is below X axis or left Y axis?

tiantian1645 commented 3 years ago

This is not actually a bug. dpg.get_plot_mouse_pos() returns the last recorded position of the mouse when it was on the plot. If you move the mouse off too quickly, the position will not necessary update to the boundary. Depends on the frame rate.

You can check this by slowly moving the mouse out of the plot region. You will see the value gets closer to the boundary.

The best course of action is to check if the plot is hovered BEFORE calling dpg.get_plot_mouse_pos().

is_item_hovered return true in the whole plot , the same range with get_axis_limits, so check hovered is invalid. It only work with different plots