Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot Layer hierarchy issue #2452

Open
monkeycc opened this issue Dec 23, 2024 · 9 comments
Open

plot Layer hierarchy issue #2452

monkeycc opened this issue Dec 23, 2024 · 9 comments

Comments

@monkeycc
Copy link

monkeycc commented Dec 23, 2024

import dearpygui.dearpygui as dpg
import numpy as np
from matplotlib import cm
import time
import cv2


dpg.create_context()

with dpg.window(label="Tutorial", width=400, height=400):
    
    
    values: np.ndarray = np.random.rand(100, 100)
            
    colmap = cm.get_cmap('viridis', 256)
    lut = (colmap.colors[...,0:4]*255).astype(np.uint8)
    rescaled = ((values.astype(float) - values.min())*255/(values.max() - values.min())).astype(np.uint8)
    result = np.ones((*rescaled.shape,4), dtype=np.uint8)
    np.take(lut, rescaled, axis=0, out=result)
    result = result.flatten()/255
    
    with dpg.group(horizontal=True):
        with dpg.texture_registry(show=False):
            dpg.add_raw_texture(width=100, height=100, default_value=np.asarray(result, dtype=np.float32), tag=f"texture_tag", format=dpg.mvFormat_Float_rgba)

        with dpg.plot(label="title", height=-1, width=-1, crosshairs=True, anti_aliased =False, delay_search=True, tag=f"_plot_with"):
            dpg.add_plot_axis(dpg.mvXAxis)


            with dpg.plot_axis(dpg.mvYAxis):
                dpg.add_image_series("texture_tag", [0, 0], [800,800]  )
                
            dpg.add_drag_rect(default_value=(-100, -100, 500, 500),) 



dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

微信截图_20241223235528

I want to adjust the rectangle to the topmost level
add_drag_rect

@v-ein
Copy link
Contributor

v-ein commented Dec 25, 2024

Same as #1820.

@monkeycc
Copy link
Author

unhappily
This issue has been present since 2022
Unresolved
It seems to be relatively low-level code
Do I need to consult imgui?

@v-ein
Copy link
Contributor

v-ein commented Dec 25, 2024

Do I need to consult imgui?

This is purely a DPG issue, neither ImGui nor ImPlot communities can help. It will eventually get fixed - I have some ideas, but I can't really promise anything. Anyway, this will take time. Can easily be half a year or a year.

@v-ein
Copy link
Contributor

v-ein commented Dec 25, 2024

What you can probably do at the moment is overlay two plots (specify pos=(x, y) on both of them), add drag rect to the foreground plot (the one that gets created later) and draw the image series on the background plot (created earlier). Then, when the user pans or zooms the foreground plot, sync the position of the background plot with it. Needless to say that the background color (mvPlotCol_PlotBg) on the foreground plot needs to be kept transparent (AFAIK it's transparent by default).

@monkeycc
Copy link
Author

Thank you for your suggestions and ideas
I will try

@monkeycc
Copy link
Author

bandicam.2024-12-25.20-00-50-608.mp4

unfortunately
The effect is not good
I will take some time to study and take a look

See if there are any ideas

@monkeycc
Copy link
Author

Implot will not be updated for one year

Can I skip using implot
To achieve this effect

Is there a similar image module
Can achieve image enlargement and reduction

@v-ein
Copy link
Contributor

v-ein commented Dec 26, 2024

You can use draw_image without add_plot, but you'll have to handle all mouse clicks and movements on your own.

As for ImPlot-based solution, exactly what doesn't work for you? Let's see if there's a workaround or a tiny fix that can solve your issue.

@monkeycc
Copy link
Author

dpg.plot
Layer not supported

dpg.drawlist
dpg.draw_layer
dpg.add_drag_rect

unfortunately
Attempt to solve the problem with layers , But it was found that it is not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants