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

Add a public API for overriding plot legend traces' visibilities #3534

Merged
merged 4 commits into from
Jan 6, 2024

Conversation

jayzhudev
Copy link
Contributor

@jayzhudev jayzhudev commented Nov 6, 2023

Added a public API in egui_plot -> legend to allow hidden_items to be overridden in the plot legend widget. This allows convenient control of traces' visibilities the selection of traces from the application code.

Example

    let legend_config = if plot_selection_changed {
        let hidden_items = match plot_selection {
            PlotSelection::SelectAll => Vec::new(),
            PlotSelection::DeselectAll => all_trace_names,
        };

        Legend::default()
            .position(Corner::RightTop)
            .hidden_items(hidden_items) // Overrides `hidden_items`
    } else {
        Legend::default().position(Corner::RightTop)
    };

    Plot::new(id)
        .legend(legend_config)
        .show(ui, draw_plot);

Closes #3533.

This reduces the coupling of the `Legend` implementation and the `Plot`
implementation, and is cleaner to have this public API implemented in
`Legend` instead of in `Plot`.
@jayzhudev jayzhudev force-pushed the plot-legend-visibility-api branch from 467916e to c529795 Compare November 16, 2023 13:45
@jayzhudev
Copy link
Contributor Author

@emilk Hello, any comment or feedback on this small PR? Thanks 😃

@emilk emilk added the egui_plot Related to egui_plot label Jan 6, 2024
@emilk emilk changed the title plot(legend): add a public API for overriding traces' visibilities Add a public API for overriding plot legend traces' visibilities Jan 6, 2024
@emilk emilk merged commit e13cc69 into emilk:master Jan 6, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui_plot Related to egui_plot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plot(legend): public API for overriding hidden items
2 participants