Skip to content

Commit b8f71c0

Browse files
authored
feat(widgets/chart): add option to set the position of legend (#378)
1 parent 113b4b7 commit b8f71c0

File tree

3 files changed

+480
-41
lines changed

3 files changed

+480
-41
lines changed

examples/chart.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ fn ui(f: &mut Frame, app: &App) {
221221
.style(Style::default().fg(Color::Gray))
222222
.bounds([0.0, 5.0])
223223
.labels(vec!["0".bold(), "2.5".into(), "5.0".bold()]),
224-
);
224+
)
225+
.hidden_legend_constraints((Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)));
225226
f.render_widget(chart, chunks[1]);
226227

227228
let datasets = vec![Dataset::default()
@@ -249,6 +250,8 @@ fn ui(f: &mut Frame, app: &App) {
249250
.style(Style::default().fg(Color::Gray))
250251
.bounds([0.0, 5.0])
251252
.labels(vec!["0".bold(), "2.5".into(), "5".bold()]),
252-
);
253+
)
254+
.legend_position(Some(LegendPosition::TopLeft))
255+
.hidden_legend_constraints((Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)));
253256
f.render_widget(chart, chunks[2]);
254257
}

src/widgets.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use bitflags::bitflags;
4343
pub use self::{
4444
barchart::{Bar, BarChart, BarGroup},
4545
block::{Block, BorderType, Padding},
46-
chart::{Axis, Chart, Dataset, GraphType},
46+
chart::{Axis, Chart, Dataset, GraphType, LegendPosition},
4747
clear::Clear,
4848
gauge::{Gauge, LineGauge},
4949
list::{List, ListDirection, ListItem, ListState},

0 commit comments

Comments
 (0)