Skip to content

Conversation

@bircni
Copy link
Contributor

@bircni bircni commented May 4, 2025

This pull request introduces enhancements to the Legend functionality in the egui_plot library, updates the plot demos to include legend titles, and modifies related tests and snapshots to reflect these changes. The most significant changes include adding a title property to the Legend struct, updating plot demos to utilize this new feature, and adjusting test infrastructure and snapshots accordingly.

Enhancements to Legend functionality:

  • egui_plot/src/legend.rs: Added a title property to the Legend struct, with a default value of None. Introduced a new title method to set the legend title and updated the LegendWidget to display the title if it is set. [1] [2] [3] [4]

Updates to plot demos:

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but the title should always be on top

pub text_style: TextStyle,
pub background_alpha: f32,
pub position: Corner,
pub title: Option<String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use WidgetText instead for more customizability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't work as WidgetText does not implement serde - we could do this here too but i dont know if that is good

@emilk emilk changed the title add legend title Add optional legend title Jun 16, 2025
@bircni
Copy link
Contributor Author

bircni commented Jun 16, 2025

when we update to the newer egui main we can use PixelThreshold so these tests dont fail anymore
@emilk

# Conflicts:
#	demo/tests/snapshots/demos/Items.png
#	demo/tests/snapshots/demos/Lines.png
#	demo/tests/snapshots/demos/Markers.png
#	demo/tests/snapshots/light_mode.png
#	demo/tests/snapshots/scale_0.50.png
#	demo/tests/snapshots/scale_1.00.png
#	demo/tests/snapshots/scale_1.39.png
#	demo/tests/snapshots/scale_2.00.png
@lucasmerlin lucasmerlin added enhancement New feature or request include in changelog This change will be included in the changelog labels Jul 11, 2025
@lucasmerlin lucasmerlin merged commit 2178cb3 into emilk:main Jul 11, 2025
11 of 12 checks passed
@bircni bircni deleted the patch98 branch July 11, 2025 12:50
michalsustr pushed a commit that referenced this pull request Nov 26, 2025
This pull request introduces enhancements to the `Legend` functionality
in the `egui_plot` library, updates the plot demos to include legend
titles, and modifies related tests and snapshots to reflect these
changes. The most significant changes include adding a `title` property
to the `Legend` struct, updating plot demos to utilize this new feature,
and adjusting test infrastructure and snapshots accordingly.

### Enhancements to `Legend` functionality:
*
[`egui_plot/src/legend.rs`](diffhunk://#diff-41de195c6ebce678a328dcb6d36642dcccd13eb73aa023e13590b61e2f74f1cfR49):
Added a `title` property to the `Legend` struct, with a default value of
`None`. Introduced a new `title` method to set the legend title and
updated the `LegendWidget` to display the title if it is set.
[[1]](diffhunk://#diff-41de195c6ebce678a328dcb6d36642dcccd13eb73aa023e13590b61e2f74f1cfR49)
[[2]](diffhunk://#diff-41de195c6ebce678a328dcb6d36642dcccd13eb73aa023e13590b61e2f74f1cfR64)
[[3]](diffhunk://#diff-41de195c6ebce678a328dcb6d36642dcccd13eb73aa023e13590b61e2f74f1cfR94-R100)
[[4]](diffhunk://#diff-41de195c6ebce678a328dcb6d36642dcccd13eb73aa023e13590b61e2f74f1cfR340-R342)

### Updates to plot demos:
*
[`demo/src/plot_demo.rs`](diffhunk://#diff-5a1025d5dd6c016d4b4017e33bb3322bd767ab0591195efa41a2a41da09efc9eL286-R286):
Updated the `Legend` configuration in `LineDemo`, `MarkerDemo`, and
`ItemsDemo` to include titles ("Lines", "Markers", and "Items",
respectively).
[[1]](diffhunk://#diff-5a1025d5dd6c016d4b4017e33bb3322bd767ab0591195efa41a2a41da09efc9eL286-R286)
[[2]](diffhunk://#diff-5a1025d5dd6c016d4b4017e33bb3322bd767ab0591195efa41a2a41da09efc9eL376-R376)
[[3]](diffhunk://#diff-5a1025d5dd6c016d4b4017e33bb3322bd767ab0591195efa41a2a41da09efc9eL764-R768)

* Closes <#98>
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: lucasmerlin <hi@lucasmerlin.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request include in changelog This change will be included in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Title (or label) for legend.

3 participants