refactor: move around some files related to the time graphs (#1942)

* refactor: move around some files related to the time graphs

* fmt

* fmt again

* update changelog

* add docs for time_graph

* rename time_graph to time_chart to be consistent

* nvm, that just makes it more annoying

* fmt

* Update documentation comment for time_graph.rs

* add extra rustdoc lint as well while I'm here
This commit is contained in:
Clement Tsang
2025-12-29 00:22:15 -05:00
committed by GitHub
parent 003d625090
commit 151e4d6127
12 changed files with 384 additions and 200 deletions
+359 -186
View File
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -95,7 +95,11 @@ starship-battery = { version = "0.10.3", optional = true }
sysinfo = "=0.37.2"
timeless = "0.0.14-alpha"
toml_edit = { version = "0.24.0", features = ["serde"] }
tui = { version = "0.30.0", package = "ratatui", features = ["unstable-rendered-line-info", "layout-cache", "crossterm"] }
tui = { version = "0.30.0", package = "ratatui", features = [
"unstable-rendered-line-info",
"layout-cache",
"crossterm",
] }
unicode-ellipsis = "0.3.0"
unicode-segmentation = "1.12.0"
unicode-width = "0.2.2"
@@ -249,6 +253,7 @@ rust_2018_idioms = "deny"
[lints.rustdoc]
broken_intra_doc_links = "deny"
private_intra_doc_links = "deny"
missing_crate_level_docs = "deny"
[lints.clippy]
+13
View File
@@ -0,0 +1,13 @@
//! A graph displaying data in the y-axis over time in the x-axis.
//!
//! A "base" version is available, based on a vendored version of
//! ratatui's [charts](https://docs.rs/ratatui/latest/ratatui/widgets/struct.Chart.html),
//! as are variants for common use cases.
mod base;
mod variants;
mod vendored;
pub(crate) use base::*;
pub(crate) use variants::percent::PercentTimeGraph;
pub(crate) use vendored::*;
+1 -2
View File
@@ -1,8 +1,6 @@
mod time_chart;
use std::{borrow::Cow, time::Instant};
use concat_string::concat_string;
pub use time_chart::*;
use tui::{
Frame,
layout::{Constraint, Rect},
@@ -12,6 +10,7 @@ use tui::{
widgets::{BorderType, GraphType},
};
use crate::canvas::components::time_graph::*;
use crate::{app::data::Values, canvas::drawing_utils::widget_block};
/// Represents the data required by the [`TimeGraph`].
-4
View File
@@ -1,4 +0,0 @@
mod base;
pub mod variants;
pub(crate) use base::*;
@@ -2,7 +2,7 @@
//! right-aligned timeseries data.
//!
//! Generally should be updated to be in sync with [`chart.rs`](https://github.com/ratatui-org/ratatui/blob/main/src/widgets/chart.rs);
//! the specializations are factored out to `time_chart/points.rs`.
//! the specializations are factored out to `time_graph/points.rs`.
mod canvas;
mod grid;
@@ -410,10 +410,8 @@ impl ChartScaling {
/// - Styling option for the legend box
/// - Automatically trimming out redundant draws in the x-bounds.
/// - Automatic interpolation to points that fall *just* outside of the screen.
///
/// TODO: Support for putting the legend on the left side.
#[derive(Debug, Default, Clone)]
pub struct TimeChart<'a> {
pub(super) struct TimeChart<'a> {
/// A block to display around the widget eventually
block: Option<Block<'a>>,
/// The horizontal axis
@@ -112,7 +112,7 @@ mod test {
use super::*;
#[test]
fn time_chart_test_interpolation() {
fn time_graph_test_interpolation() {
let data = [(-3.0, 8.0), (-1.0, 6.0), (0.0, 5.0)];
assert_eq!(interpolate_point(&data[1], &data[2], 0.0), 5.0);
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
Painter,
components::{
data_table::{DrawInfo, SelectionState},
time_graph::{GraphData, variants::percent::PercentTimeGraph},
time_graph::{GraphData, PercentTimeGraph},
},
drawing_utils::should_hide_x_label,
},
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
app::{App, data::Values},
canvas::{
Painter,
components::time_graph::{GraphData, variants::percent::PercentTimeGraph},
components::time_graph::{GraphData, PercentTimeGraph},
drawing_utils::should_hide_x_label,
},
collection::memory::MemData,