hoffstadt / DearPyGui

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

Insufficient precision of the get_plot_mouse_pos() #1847

Open sedenka opened 2 years ago

sedenka commented 2 years ago

Version of Dear PyGui

Version: 1.6.2 Operating System: Windows 10

My Issue/Question

Function dpg.get_plot_mouse_pos() does not return coordinates with sufficient precision. The mouse position is stored in the mvContext as float. Such precision is insufficient for time axis storing timestamps. The precision should be fixed also here and here.

To Reproduce

Steps to reproduce the behavior:

  1. Run the code below.
  2. Move the mouse pointer horizontally over the graph area.
  3. Watch the coordinates in the command line output (the x-coordinate is not changing, it is always 1658792448.0)

Expected behavior

The first ("x") coordinate should change between 1658792466.0 and 1658792466.999 according to mouse move.

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

def mouse_move_callback():
    print(dpg.get_plot_mouse_pos())

with dpg.handler_registry():
    dpg.add_mouse_move_handler(callback=mouse_move_callback)

with dpg.window(tag="Primary"):
    with dpg.plot(height=-1, width=-1):
        dpg.add_plot_axis(dpg.mvXAxis, time=True)
        with dpg.plot_axis(dpg.mvYAxis):
            dpg.add_scatter_series([1658792466, 1658792467], [0, 1])

dpg.show_viewport()
dpg.set_primary_window("Primary", True)
dpg.start_dearpygui()
dpg.destroy_context()
sedenka commented 2 years ago

Functions get_axis_limits()/set_axis_limits() should use double precision as well. Also, I would like to be able to set time=True for the y-axis to make graph "time vs. time" so both the coordinates should be in double. Perhaps you may want to use ImPlotRange instead of the ImVec2 for mvPlotAxisConfig.limits and mvPlotAxisConfig.limits_actual?

sedenka commented 2 years ago

Another problem with the get_plot_mouse_pos() is that it updates the position only inside of the plot, otherwise it keeps and returns old (=invalid) coordinates. I think there should be else clause setting the coordinates to NaN.

sedenka commented 2 years ago

Also all plotting functions like draw_rectangle() should internally work with double precision in order to render the data to the correct location when using time axis.

sedenka commented 1 year ago

I think it is actually a bug because: