2020-04-13 23:01:01 +00:00
|
|
|
use tui::{
|
|
|
|
backend::TestBackend,
|
|
|
|
layout::Rect,
|
|
|
|
style::{Color, Style},
|
|
|
|
symbols,
|
2020-05-10 21:48:12 +00:00
|
|
|
widgets::{Axis, Block, Borders, Chart, Dataset, GraphType::Line},
|
2020-04-13 23:01:01 +00:00
|
|
|
Terminal,
|
|
|
|
};
|
2019-06-20 05:30:36 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_chart_can_have_axis_with_zero_length_bounds() {
|
2019-06-20 05:30:36 +00:00
|
|
|
let backend = TestBackend::new(100, 100);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
|
|
|
.draw(|mut f| {
|
2019-12-15 20:38:18 +00:00
|
|
|
let datasets = [Dataset::default()
|
2020-04-13 23:01:01 +00:00
|
|
|
.marker(symbols::Marker::Braille)
|
2019-12-15 20:38:18 +00:00
|
|
|
.style(Style::default().fg(Color::Magenta))
|
|
|
|
.data(&[(0.0, 0.0)])];
|
|
|
|
let chart = Chart::default()
|
2019-07-16 06:03:02 +00:00
|
|
|
.block(Block::default().title("Plot").borders(Borders::ALL))
|
|
|
|
.x_axis(Axis::default().bounds([0.0, 0.0]).labels(&["0.0", "1.0"]))
|
|
|
|
.y_axis(Axis::default().bounds([0.0, 1.0]).labels(&["0.0", "1.0"]))
|
2019-12-15 20:38:18 +00:00
|
|
|
.datasets(&datasets);
|
|
|
|
f.render_widget(
|
|
|
|
chart,
|
|
|
|
Rect {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
},
|
|
|
|
);
|
2019-07-16 06:03:02 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2019-06-20 05:30:36 +00:00
|
|
|
}
|
2020-05-10 12:40:04 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_chart_handles_overflows() {
|
2020-05-10 12:40:04 +00:00
|
|
|
let backend = TestBackend::new(80, 30);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
|
|
|
.draw(|mut f| {
|
|
|
|
let datasets = [Dataset::default()
|
|
|
|
.marker(symbols::Marker::Braille)
|
|
|
|
.style(Style::default().fg(Color::Magenta))
|
|
|
|
.data(&[
|
2020-05-16 22:51:57 +00:00
|
|
|
(1_588_298_471.0, 1.0),
|
|
|
|
(1_588_298_473.0, 0.0),
|
|
|
|
(1_588_298_496.0, 1.0),
|
2020-05-10 12:40:04 +00:00
|
|
|
])];
|
|
|
|
let chart = Chart::default()
|
|
|
|
.block(Block::default().title("Plot").borders(Borders::ALL))
|
|
|
|
.x_axis(
|
|
|
|
Axis::default()
|
2020-05-16 22:51:57 +00:00
|
|
|
.bounds([1_588_298_471.0, 1_588_992_600.0])
|
2020-05-10 12:40:04 +00:00
|
|
|
.labels(&["1588298471.0", "1588992600.0"]),
|
|
|
|
)
|
|
|
|
.y_axis(Axis::default().bounds([0.0, 1.0]).labels(&["0.0", "1.0"]))
|
|
|
|
.datasets(&datasets);
|
|
|
|
f.render_widget(
|
|
|
|
chart,
|
|
|
|
Rect {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 80,
|
|
|
|
height: 30,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
}
|
2020-05-10 21:48:12 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_chart_can_have_empty_datasets() {
|
2020-05-10 21:48:12 +00:00
|
|
|
let backend = TestBackend::new(100, 100);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
|
|
|
|
terminal
|
|
|
|
.draw(|mut f| {
|
|
|
|
let datasets = [Dataset::default().data(&[]).graph_type(Line)];
|
|
|
|
let chart = Chart::default()
|
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("Empty Dataset With Line")
|
|
|
|
.borders(Borders::ALL),
|
|
|
|
)
|
|
|
|
.x_axis(Axis::default().bounds([0.0, 0.0]).labels(&["0.0", "1.0"]))
|
|
|
|
.y_axis(Axis::default().bounds([0.0, 1.0]).labels(&["0.0", "1.0"]))
|
|
|
|
.datasets(&datasets);
|
|
|
|
f.render_widget(
|
|
|
|
chart,
|
|
|
|
Rect {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
}
|