1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Add plot legends (#349)

* add plot legends

* don't show crosshairs when hovering over legend

* add a toggle for the legend

* changes based on review

* improve legend behavior when curves share names
This commit is contained in:
Sven Niederberger
2021-05-07 10:32:17 +02:00
committed by GitHub
parent d862ff66ac
commit 838f3e4ff2
4 changed files with 202 additions and 29 deletions

View File

@@ -9,6 +9,7 @@ pub struct PlotDemo {
circle_radius: f64,
circle_center: Pos2,
square: bool,
legend: bool,
proportional: bool,
}
@@ -20,6 +21,7 @@ impl Default for PlotDemo {
circle_radius: 1.5,
circle_center: Pos2::new(0.0, 0.0),
square: false,
legend: true,
proportional: true,
}
}
@@ -54,6 +56,7 @@ impl PlotDemo {
circle_radius,
circle_center,
square,
legend,
proportional,
} = self;
@@ -87,6 +90,7 @@ impl PlotDemo {
ui.checkbox(animate, "animate");
ui.add_space(8.0);
ui.checkbox(square, "square view");
ui.checkbox(legend, "legend");
ui.checkbox(proportional, "proportional data axes");
});
});
@@ -145,7 +149,8 @@ impl super::View for PlotDemo {
.curve(self.circle())
.curve(self.sin())
.curve(self.thingy())
.min_size(Vec2::new(256.0, 200.0));
.show_legend(self.legend)
.min_size(Vec2::new(200.0, 200.0));
if self.square {
plot = plot.view_aspect(1.0);
}