Skip to content

Commit

Permalink
docs(Chart): add description about legend_position and make clearly…
Browse files Browse the repository at this point in the history
… chart examples
  • Loading branch information
lyuha committed Dec 13, 2023
1 parent b6e6c0d commit 210a291
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 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 @@ -250,6 +251,7 @@ fn ui(f: &mut Frame, app: &App) {
.bounds([0.0, 5.0])
.labels(vec!["0".bold(), "2.5".into(), "5".bold()]),
)
.legend_position(Some(LegendPosition::TopLeft));
.legend_position(Some(LegendPosition::TopLeft))
.hidden_legend_constraints((Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)));
f.render_widget(chart, chunks[2]);
}
10 changes: 7 additions & 3 deletions src/widgets/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ pub struct Chart<'a> {
style: Style,
/// Constraints used to determine whether the legend should be shown or not
hidden_legend_constraints: (Constraint, Constraint),
/// The position of a legend
/// The position detnermine where the legenth is shown or hide regaurdless of
/// `hidden_legend_constraints`
legend_position: Option<LegendPosition>,
}

Expand All @@ -330,7 +331,7 @@ impl<'a> Chart<'a> {
style: Style::default(),
datasets,
hidden_legend_constraints: (Constraint::Ratio(1, 4), Constraint::Ratio(1, 4)),
legend_position: Some(LegendPosition::TopRight),
legend_position: Some(LegendPosition::default()),
}
}

Expand Down Expand Up @@ -379,7 +380,10 @@ impl<'a> Chart<'a> {
self
}

/// Set the position of a legend.
/// Set the position of a legend or hide it.
///
/// If [`None`], hide the legend even if satisfied with
/// [`hidden_legend_constraints`](Self::hidden_legend_constraints)
///
/// # Examples
///
Expand Down

0 comments on commit 210a291

Please sign in to comment.