summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-01-20 18:50:20 -0500
committerGitHub <noreply@github.com>2023-01-20 18:50:20 -0500
commit3aa4aa1c08d72b3874c936d266f24b9746a8c385 (patch)
tree7baa6fec16d21a313021aebb2132ba76157a5180 /src
parent4870ff365a91b68eb0b9528c75375f01ce539e75 (diff)
bug: fix axis labels not being styled (#994)
Fixes graph axis labels not being styled.
Diffstat (limited to 'src')
-rw-r--r--src/components/time_graph.rs24
-rw-r--r--src/components/tui_widget/time_chart.rs2
2 files changed, 16 insertions, 10 deletions
diff --git a/src/components/time_graph.rs b/src/components/time_graph.rs
index 912beb3c..6c0ff82e 100644
--- a/src/components/time_graph.rs
+++ b/src/components/time_graph.rs
@@ -71,8 +71,8 @@ impl<'a> TimeGraph<'a> {
let xb_zero = (self.x_bounds[0] / 1000).to_string();
let x_labels = vec![
- Span::raw(concat_string!(xb_one, "s")),
- Span::raw(concat_string!(xb_zero, "s")),
+ Span::styled(concat_string!(xb_one, "s"), self.graph_style),
+ Span::styled(concat_string!(xb_zero, "s"), self.graph_style),
];
Axis::default()
@@ -90,7 +90,7 @@ impl<'a> TimeGraph<'a> {
.labels(
self.y_labels
.iter()
- .map(|label| Span::raw(label.clone()))
+ .map(|label| Span::styled(label.clone(), self.graph_style))
.collect(),
)
}
@@ -213,12 +213,13 @@ mod test {
#[test]
fn time_graph_gen_x_axis() {
let tg = create_time_graph();
-
+ let style = Style::default().fg(Color::Red);
let x_axis = tg.generate_x_axis();
+
let actual = Axis::default()
.bounds([-15000.0, 0.0])
- .labels(vec![Span::raw("15s"), Span::raw("0s")])
- .style(Style::default().fg(Color::Red));
+ .labels(vec![Span::styled("15s", style), Span::styled("0s", style)])
+ .style(style);
assert_eq!(x_axis.bounds, actual.bounds);
assert_eq!(x_axis.labels, actual.labels);
assert_eq!(x_axis.style, actual.style);
@@ -227,12 +228,17 @@ mod test {
#[test]
fn time_graph_gen_y_axis() {
let tg = create_time_graph();
-
+ let style = Style::default().fg(Color::Red);
let y_axis = tg.generate_y_axis();
+
let actual = Axis::default()
.bounds([0.0, 100.5])
- .labels(vec![Span::raw("0%"), Span::raw("50%"), Span::raw("100%")])
- .style(Style::default().fg(Color::Red));
+ .labels(vec![
+ Span::styled("0%", style),
+ Span::styled("50%", style),
+ Span::styled("100%", style),
+ ])
+ .style(style);
assert_eq!(y_axis.bounds, actual.bounds);
assert_eq!(y_axis.labels, actual.labels);
diff --git a/src/components/tui_widget/time_chart.rs b/src/components/tui_widget/time_chart.rs
index c0aed91e..9369263f 100644
--- a/src/components/tui_widget/time_chart.rs
+++ b/src/components/tui_widget/time_chart.rs
@@ -30,7 +30,7 @@ pub struct Axis<'a> {
pub bounds: [f64; 2],
/// A list of labels to put to the left or below the axis
pub labels: Option<Vec<Span<'a>>>,
- /// The style used to draw the axis itself
+ /// The style used to draw the axis itself - NOT The labels.
pub style: Style,
}