Skip to content

Commit

Permalink
feat(widgets/chart): add option to set the position of legend (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuha authored Dec 15, 2023
1 parent 113b4b7 commit b8f71c0
Show file tree
Hide file tree
Showing 3 changed files with 480 additions and 41 deletions.
7 changes: 5 additions & 2 deletions examples/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ fn ui(f: &mut Frame, app: &App) {
.style(Style::default().fg(Color::Gray))
.bounds([0.0, 5.0])
.labels(vec!["0".bold(), "2.5".into(), "5.0".bold()]),
);
)
.hidden_legend_constraints((Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)));
f.render_widget(chart, chunks[1]);

let datasets = vec![Dataset::default()
Expand Down Expand Up @@ -249,6 +250,8 @@ fn ui(f: &mut Frame, app: &App) {
.style(Style::default().fg(Color::Gray))
.bounds([0.0, 5.0])
.labels(vec!["0".bold(), "2.5".into(), "5".bold()]),
);
)
.legend_position(Some(LegendPosition::TopLeft))
.hidden_legend_constraints((Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)));
f.render_widget(chart, chunks[2]);
}
2 changes: 1 addition & 1 deletion src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use bitflags::bitflags;
pub use self::{
barchart::{Bar, BarChart, BarGroup},
block::{Block, BorderType, Padding},
chart::{Axis, Chart, Dataset, GraphType},
chart::{Axis, Chart, Dataset, GraphType, LegendPosition},
clear::Clear,
gauge::{Gauge, LineGauge},
list::{List, ListDirection, ListItem, ListState},
Expand Down
Loading

0 comments on commit b8f71c0

Please sign in to comment.