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

Does it support polygon frames #2453

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

Does it support polygon frames #2453

monkeycc opened this issue Dec 23, 2024 · 8 comments

Comments

@monkeycc
Copy link

monkeycc commented Dec 23, 2024

微信截图_20241224004008
微信截图_20241224004508

polygon

@v-ein
Copy link
Contributor

v-ein commented Dec 25, 2024

It's not clear what you mean or what help you might need. Would you please provide a detailed description of your issue?

@monkeycc
Copy link
Author

bandicam.2024-12-25.17-07-50-252.mp4
  1. Implement polygon frame function with mouse
  2. Polygons can be edited

@v-ein
Copy link
Contributor

v-ein commented Dec 25, 2024

Well, that's something you have to do on your own 😂. If you need some ideas on how this can be implemented, here's an example I recently made for a question asked on Discord.

from math import sin
import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport(title=f"Test - {dpg.get_dearpygui_version()}", width=700, height=750)

def on_point_dragged(drag_point, app_data, idx):
    new_x, new_y = dpg.get_value(drag_point)
    xs, ys, *_ = dpg.get_value("line-series")
    # Uncomment this if you need X to be clamped between the neighbour points
    # if idx > 0 and new_x < xs[idx - 1]:
    #     new_x = xs[idx - 1]
    #     dpg.set_value(drag_point, (new_x, new_y))
    # elif idx < len(xs) - 1 and new_x > xs[idx + 1]:
    #     new_x = xs[idx + 1]
    #     dpg.set_value(drag_point, (new_x, new_y))

    xs[idx] = new_x
    ys[idx] = new_y
    dpg.set_value("line-series", (xs, ys))

with dpg.window() as wnd:
    dpg.set_primary_window(dpg.last_item(), True)

    x_data = [x/3 for x in range(0, 30)]
    y_data = [sin(x) for x in x_data]

    with dpg.theme() as marker_theme:
        with dpg.theme_component():
            dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Circle, category=dpg.mvThemeCat_Plots)

    with dpg.plot(width=-1, height=-1, tag="plot"):
        x_axis = dpg.add_plot_axis(dpg.mvXAxis, label="x")
        with dpg.plot_axis(dpg.mvYAxis, label="y", no_label=True) as y_axis:
            dpg.add_line_series(x_data, y_data, label="Line series", tag="line-series")
            dpg.bind_item_theme(dpg.last_item(), marker_theme)

        for i, (x, y) in enumerate(zip(x_data, y_data)):
            dpg.add_drag_point(label="", default_value=(x, y), callback=on_point_dragged, user_data=i, color=(0, 0, 0, 0))

dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

@monkeycc
Copy link
Author

wow
Thank you so much for your help

As long as there is code reference
I will make changes

Thank you very much for your help

@monkeycc monkeycc reopened this Jan 17, 2025
@monkeycc
Copy link
Author

Image

Hello, I found this issue after modifying your code based on it
How to remove excess filling ?

from math import sin
import dearpygui.dearpygui as dpg
import math

dpg.create_context()
dpg.create_viewport(title=f"Test - {dpg.get_dearpygui_version()}", width=700, height=750)

def on_point_dragged(drag_point, app_data, idx):
    new_x, new_y = dpg.get_value(drag_point)
    xs, ys, *_ = dpg.get_value("line-series")
    # Uncomment this if you need X to be clamped between the neighbour points
    # if idx > 0 and new_x < xs[idx - 1]:
    #     new_x = xs[idx - 1]
    #     dpg.set_value(drag_point, (new_x, new_y))
    # elif idx < len(xs) - 1 and new_x > xs[idx + 1]:
    #     new_x = xs[idx + 1]
    #     dpg.set_value(drag_point, (new_x, new_y))

    xs[idx] = new_x
    ys[idx] = new_y
    dpg.set_value("line-series", (xs, ys))

with dpg.window() as wnd:
    dpg.set_primary_window(dpg.last_item(), True)

    num_points = 10  
    radius = 5  
    theta = [2 * math.pi * i / num_points for i in range(num_points)]
    x_data = [radius * math.cos(t) for t in theta]
    y_data = [radius * math.sin(t) for t in theta]


    with dpg.plot(width=-1, height=-1, tag="plot"):
        x_axis = dpg.add_plot_axis(dpg.mvXAxis, label="x")
        with dpg.plot_axis(dpg.mvYAxis, label="y") as y_axis:
            dpg.add_line_series(x_data, y_data, label="Circle", tag="line-series",shaded=True)

        for i, (x, y) in enumerate(zip(x_data, y_data)):
            dpg.add_drag_point(label="", default_value=(x, y), callback=on_point_dragged, user_data=i, color=(0, 0, 0, 0))

dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

@monkeycc monkeycc reopened this Jan 17, 2025
@v-ein
Copy link
Contributor

v-ein commented Jan 17, 2025

shaded=True makes line_series behave much the same way as shade_series: it fills the space between the line and the X axis. It doesn't suit for drawing arbitrary filled polygons.

I believe you can use draw_polygon in place of line_series to do what you need.

@v-ein
Copy link
Contributor

v-ein commented Jan 17, 2025

Well.. turns out that #2045 ruins the idea of using draw_polygon to render a filled polygon.

@v-ein
Copy link
Contributor

v-ein commented Jan 17, 2025

Another option is add_area_series in place of add_line_series:

dpg.add_area_series(x_data, y_data, tag="line-series", fill=(255, 255, 255, 255))

Works just fine.

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