pub struct Axis { /* private fields */ }Expand description
One axis of a Chart: its bounds, title, labels and scale.
use rich_ext::chart::{Axis, AxisScale, Labels};
let axis = Axis::default()
.bounds(1.0, 1000.0)
.scale(AxisScale::Log)
.labels(Labels::Auto(4))
.title("Hz");
assert_eq!(axis.label_values(), vec![1.0, 10.0, 100.0, 1000.0]);Implementations§
Source§impl Axis
impl Axis
Sourcepub fn bounds(self, min: f64, max: f64) -> Self
pub fn bounds(self, min: f64, max: f64) -> Self
The values at either end, in either order. Without bounds, the axis spans the chart’s data.
Sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
The axis title: the y axis’s above its top left, the x axis’s at the right end of the plot’s bottom row.
Sourcepub fn title_style(self, style: impl Into<String>) -> Self
pub fn title_style(self, style: impl Into<String>) -> Self
The title’s style: a theme key or a definition (default
chart.label).
Sourcepub fn labels(self, labels: Labels) -> Self
pub fn labels(self, labels: Labels) -> Self
The labels (default Labels::None: no labels and no axis line).
Sourcepub fn labels_align(self, align: HorizontalAlign) -> Self
pub fn labels_align(self, align: HorizontalAlign) -> Self
How the labels sit, as ratatui’s labels_alignment.
- On the y axis, in the column left of the axis line. By
default
Labels::AutoandLabels::Valuesare right-aligned andLabels::TextandLabels::Markupleft-aligned, as in ratatui. - On the x axis, the first text label against the y axis line:
Left(the default) ends it under the line,Centercentres it on the line,Rightstarts it there. A label placed at a value (Labels::Auto,Labels::Values) starts at its value (Left), is centred on it (the default) or ends at it (Right).
Sourcepub fn style(self, style: impl Into<String>) -> Self
pub fn style(self, style: impl Into<String>) -> Self
The style of the axis line and labels: a theme key or a definition
(default chart.axis).
Sourcepub fn label_format(self, format: ValueFormat) -> Self
pub fn label_format(self, format: ValueFormat) -> Self
How Labels::Auto and Labels::Values are written (default
ValueFormat::Compact).
Sourcepub fn grid(self, values: impl IntoIterator<Item = f64>) -> Self
pub fn grid(self, values: impl IntoIterator<Item = f64>) -> Self
Grid lines across the plot at these values, in the axis’s
grid_style (else its style),
drawn under the datasets with the axis’s
grid_marker (else the chart’s
marker, else the first dataset’s, else Braille):
the x axis’s run up the plot, the y axis’s along it. Values the axis
cannot show (outside its bounds, or not positive on a log axis) are
left out. With Layering::PerDataset each line is a layer of its
own, the y axis’s first, and the datasets are drawn over them, so a
line crossing another and a trace crossing a line break what they
cross, as datasets drawn for the purpose do in ratatui (scope-tui’s
reference lines).
use rich::Console;
use rich_ext::chart::{Axis, Chart, Dataset, Marker};
let console = Console::builder().width(9).color_system(None).build();
let chart = Chart::new(vec![Dataset::new([(2.0, 1.0)]).marker(Marker::Ascii('o'))])
.x_axis(Axis::default().bounds(0.0, 8.0).grid([4.0]))
.y_axis(Axis::default().bounds(0.0, 2.0).grid([0.0]))
.width(9)
.height(3);
// The point at (2, 1); the grid at x = 4 and y = 0, in the axis style.
assert_eq!(console.render_export(&chart), " o \n o o \nooooooooo\n");Sourcepub fn grid_style(self, style: impl Into<String>) -> Self
pub fn grid_style(self, style: impl Into<String>) -> Self
The style of the grid lines: a theme key or a
definition (default: the axis’s style, else
chart.axis), so the lines can be fainter than the axis line and
labels.
use rich::Console;
use rich_ext::chart::{Axis, Chart, Dataset, Labels, Marker};
let console = Console::builder().width(5).force_terminal(true).build();
let chart = Chart::new(Vec::<Dataset>::new())
.marker(Marker::Ascii('.'))
.x_axis(Axis::default().bounds(0.0, 4.0))
.y_axis(
Axis::default()
.bounds(0.0, 1.0)
.labels(Labels::Text(vec!["0".into(), "1".into()]))
.style("bold")
.grid([0.0])
.grid_style("dim"),
)
.width(5)
.height(2);
// The labels and the axis line bold, the grid line dim.
assert_eq!(
console.render_export(&chart),
"\u{1b}[1m1│\u{1b}[0m \n\u{1b}[1m0│\u{1b}[0m\u{1b}[2m...\u{1b}[0m\n"
);Sourcepub fn grid_marker(self, marker: Marker) -> Self
pub fn grid_marker(self, marker: Marker) -> Self
The marker the grid lines are drawn with (default:
the chart’s marker, else the first dataset’s,
else Marker::Braille).
Sourcepub fn label_values(&self) -> Vec<f64>
pub fn label_values(&self) -> Vec<f64>
The values labelled with Labels::Auto or Labels::Values,
when the axis spans its bounds (or 0..1 without them).