| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#}; |
| 2 | |
| 3 | use concat_stringrust-analyzer cargo concat-string 1.0.1 crate/::concat_stringrust-analyzer cargo concat-string 1.0.1 concat_string!; |
| 4 | use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{ |
| 5 | Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#, |
| 6 | layoutrust-analyzer cargo ratatui-core 0.1.2 layout/::{Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#, Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#}, |
| 7 | stylerust-analyzer cargo ratatui-core 0.1.2 style/::Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, |
| 8 | symbolsrust-analyzer cargo ratatui-core 0.1.2 symbols/::Markerrust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#, |
| 9 | textrust-analyzer cargo ratatui-core 0.1.2 text/::{Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#, Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#}, |
| 10 | widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::{BorderTyperust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#, GraphTyperust-analyzer cargo ratatui-widgets 0.3.2 chart/GraphType#}, |
| 11 | }; |
| 12 | use timelessrust-analyzer cargo timeless 0.1.0 crate/::datarust-analyzer cargo timeless 0.1.0 data/::ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#; |
| 13 | |
| 14 | use craterust-analyzer cargo bottom 0.14.9 crate/::canvasrust-analyzer cargo bottom 0.14.9 canvas/::{componentsrust-analyzer cargo bottom 0.14.9 canvas/components/::time_seriesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/::*, drawing_utilsrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/::widget_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/widget_block().}; |
| 15 | |
| 16 | /// Represents the data required by the [`TimeGraph`]. |
| 17 | /// |
| 18 | /// TODO: We may be able to get rid of this intermediary data structure. |
| 19 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 20 | pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct GraphDatarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#<'a, F = f64> { |
| 21 | timerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#time.: &'a [Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#], |
| 22 | valuesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#values.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<F>>, |
| 23 | stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, |
| 24 | namerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#name.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>>, |
| 25 | } |
| 26 | |
| 27 | impl<'a, F> GraphDatarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#<'a, F> { |
| 28 | pub fn timerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`]time().(mut self, time: &'a [Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#]) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`] { |
| 29 | self.timerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#time. = time; |
| 30 | self |
| 31 | } |
| 32 | |
| 33 | pub fn valuesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`]values().(mut self, values: &'a ChunkedDatarust-analyzer cargo timeless 0.1.0 data/chunked/ChunkedData#<F>) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`] { |
| 34 | self.valuesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#values. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(values); |
| 35 | self |
| 36 | } |
| 37 | |
| 38 | pub fn stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`]style().(mut self, style: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`] { |
| 39 | self.stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#style. = style; |
| 40 | self |
| 41 | } |
| 42 | |
| 43 | pub fn namerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`]name().(mut self, name: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`GraphData<'a, F>`] { |
| 44 | self.namerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#name. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name); |
| 45 | self |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 50 | pub struct LegendConstraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints# { |
| 51 | /// The width legend constraints. |
| 52 | pub widthrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#width.: Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#, |
| 53 | |
| 54 | /// The height legend constraints. |
| 55 | pub heightrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#height.: Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#, |
| 56 | } |
| 57 | |
| 58 | pub struct TimeGraphrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#<'a> { |
| 59 | /// The min x value. |
| 60 | pub x_minrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#x_min.: f64, |
| 61 | |
| 62 | /// Whether to hide the time/x-labels. |
| 63 | pub hide_x_labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#hide_x_labels.: bool, |
| 64 | |
| 65 | /// The min and max y boundaries. |
| 66 | pub y_boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#y_bounds.: AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#, |
| 67 | |
| 68 | /// Any y-labels. |
| 69 | pub y_labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#y_labels.: &'a [Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>], |
| 70 | |
| 71 | /// The graph style. |
| 72 | pub graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, |
| 73 | |
| 74 | /// The background colour/styling. |
| 75 | pub general_widget_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#general_widget_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, |
| 76 | |
| 77 | /// The border style. |
| 78 | pub border_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#border_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, |
| 79 | |
| 80 | /// The border type. |
| 81 | pub border_typerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#border_type.: BorderTyperust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#, |
| 82 | |
| 83 | /// The graph title. |
| 84 | pub titlerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>, |
| 85 | |
| 86 | /// Whether this graph is selected. |
| 87 | pub is_selectedrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#is_selected.: bool, |
| 88 | |
| 89 | /// Whether this graph is expanded. |
| 90 | pub is_expandedrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#is_expanded.: bool, |
| 91 | |
| 92 | /// The title style. |
| 93 | pub title_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#, |
| 94 | |
| 95 | /// The legend position. |
| 96 | pub legend_positionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#legend_position.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<LegendPositionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/LegendPosition#>, |
| 97 | |
| 98 | /// Any legend constraints. |
| 99 | pub legend_constraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#legend_constraints.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<LegendConstraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#>, |
| 100 | |
| 101 | /// The marker type. Unlike ratatui's native charts, we assume |
| 102 | /// only a single type of marker. |
| 103 | pub markerrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#marker.: Markerrust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#, |
| 104 | |
| 105 | /// The chart scaling. |
| 106 | pub scalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#scaling.: ChartScalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/ChartScaling#, |
| 107 | } |
| 108 | |
| 109 | impl TimeGraphrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#<'_> { |
| 110 | /// Generates the [`Axis`] for the x-axis. |
| 111 | fn generate_x_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]generate_x_axis().(&self) -> Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#<'_> { |
| 112 | // Due to how we display things, we need to adjust the time bound values. |
| 113 | let adjusted_x_bounds = AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#::Minrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#Min#(self.x_minrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#x_min.); |
| 114 | |
| 115 | if self.hide_x_labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#hide_x_labels. { |
| 116 | Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`][Default]default().().boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]bounds().(adjusted_x_bounds) |
| 117 | } else { |
| 118 | let x_bound_left = ((-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().self.x_minrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#x_min.) as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().1000).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 119 | let x_bound_right = "0s"; |
| 120 | |
| 121 | let x_labels = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 122 | Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(concat_stringrust-analyzer cargo concat-string 1.0.1 concat_string!!(x_bound_left, "s"), self.graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.), |
| 123 | Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(x_bound_right, self.graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.), |
| 124 | ]; |
| 125 | |
| 126 | Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`][Default]default().() |
| 127 | .boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]bounds().(adjusted_x_bounds) |
| 128 | .labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]labels().(x_labels) |
| 129 | .stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]style().(self.graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /// Generates the [`Axis`] for the y-axis. |
| 134 | fn generate_y_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]generate_y_axis().(&self) -> Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#<'_> { |
| 135 | Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`][Default]default().() |
| 136 | .boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]bounds().(self.y_boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#y_bounds.) |
| 137 | .stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]style().(self.graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.) |
| 138 | .labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]labels().( |
| 139 | self.y_labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#y_labels. |
| 140 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 141 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|label| Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(label.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Clone]clone().(), self.graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.)) |
| 142 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 143 | ) |
| 144 | } |
| 145 | |
| 146 | /// Draws a time graph at [`Rect`] location provided by `draw_loc`. A time |
| 147 | /// graph is used to display data points throughout time in the x-axis. |
| 148 | /// |
| 149 | /// This time graph: |
| 150 | /// - Draws with the higher time value on the left, and lower on the right. |
| 151 | /// - Expects a [`TimeGraph`] to be passed in, which details how to draw the |
| 152 | /// graph. |
| 153 | /// - Expects `graph_data`, which represents *what* data to draw, and |
| 154 | /// various details like style and optional legends. |
| 155 | pub fn drawrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]draw().<F: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<f64>>( |
| 156 | &self, f: &mut Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#<'_>, draw_loc: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#, graph_data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<GraphDatarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#<'_, F>>, |
| 157 | ) { |
| 158 | // TODO: (points_rework_v1) can we reduce allocations in the underlying graph by |
| 159 | // saving some sort of state? |
| 160 | |
| 161 | let x_axis = self.generate_x_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]generate_x_axis().(); |
| 162 | let y_axis = self.generate_y_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]generate_y_axis().(); |
| 163 | let data = graph_data.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(create_datasetrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/create_dataset().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 164 | |
| 165 | let block = { |
| 166 | let mut b = widget_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/widget_block().( |
| 167 | false, |
| 168 | self.is_selectedrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#is_selected., |
| 169 | self.border_typerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#border_type., |
| 170 | self.general_widget_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#general_widget_style., |
| 171 | ) |
| 172 | .border_stylerust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]border_style().(self.border_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#border_style.) |
| 173 | .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(self.titlerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().(), self.title_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title_style.)); |
| 174 | |
| 175 | if self.is_expandedrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#is_expanded. { |
| 176 | b = b.title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Esc to go back ", self.title_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title_style.).right_alignedrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]right_aligned().()) |
| 177 | } |
| 178 | |
| 179 | b |
| 180 | }; |
| 181 | |
| 182 | f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().( |
| 183 | TimeChartrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/TimeChart#::newrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]new().(data) |
| 184 | .blockrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]block().(block) |
| 185 | .x_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]x_axis().(x_axis) |
| 186 | .y_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]y_axis().(y_axis) |
| 187 | .markerrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]marker().(self.markerrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#marker.) |
| 188 | .stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]style().(self.general_widget_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#general_widget_style.) |
| 189 | .legend_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]legend_style().(self.graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.) |
| 190 | .legend_positionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]legend_position().(self.legend_positionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#legend_position.) |
| 191 | .hidden_legend_constraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]hidden_legend_constraints().({ |
| 192 | let constraints = self |
| 193 | .legend_constraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#legend_constraints. |
| 194 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(DEFAULT_LEGEND_CONSTRAINTSrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/DEFAULT_LEGEND_CONSTRAINTS.); |
| 195 | |
| 196 | (constraints.widthrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#width., constraints.heightrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/LegendConstraints#height.) |
| 197 | }) |
| 198 | .scalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`TimeChart<'a, F>`]scaling().(self.scalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#scaling.), |
| 199 | draw_loc, |
| 200 | ) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /// Creates a new [`Dataset`]. |
| 205 | fn create_datasetrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/create_dataset().<F: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<f64>>(data: GraphDatarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#<'_, F>) -> Datasetrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Dataset#<'_, F> { |
| 206 | let GraphDatarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData# { |
| 207 | timerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#time., |
| 208 | valuesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#values., |
| 209 | stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#style., |
| 210 | namerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/GraphData#name., |
| 211 | } = data; |
| 212 | |
| 213 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(values) = values else { |
| 214 | return Datasetrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Dataset#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Dataset<'a, F>`][Default]default().(); |
| 215 | }; |
| 216 | |
| 217 | let dataset = Datasetrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Dataset#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Dataset<'a, F>`][Default]default().() |
| 218 | .stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Dataset<'a, F>`]style().(style) |
| 219 | .datarust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Dataset<'a, F>`]data().(time, values) |
| 220 | .graph_typerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Dataset<'a, F>`]graph_type().(GraphTyperust-analyzer cargo ratatui-widgets 0.3.2 chart/GraphType#::Linerust-analyzer cargo ratatui-widgets 0.3.2 chart/GraphType#Line#); |
| 221 | |
| 222 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = name { |
| 223 | dataset.namerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Dataset<'a, F>`]name().(name) |
| 224 | } else { |
| 225 | dataset |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | #[cfg(test)] |
| 230 | mod testrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/ { |
| 231 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#; |
| 232 | |
| 233 | use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{ |
| 234 | stylerust-analyzer cargo ratatui-core 0.1.2 style/::{Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#, Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#}, |
| 235 | symbolsrust-analyzer cargo ratatui-core 0.1.2 symbols/::Markerrust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#, |
| 236 | textrust-analyzer cargo ratatui-core 0.1.2 text/::Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#, |
| 237 | widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::BorderTyperust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#, |
| 238 | }; |
| 239 | |
| 240 | use superrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/::{AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#, ChartScalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/ChartScaling#, TimeGraphrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#}; |
| 241 | use craterust-analyzer cargo bottom 0.14.9 crate/::canvasrust-analyzer cargo bottom 0.14.9 canvas/::componentsrust-analyzer cargo bottom 0.14.9 canvas/components/::time_seriesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/::Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#; |
| 242 | |
| 243 | const Y_LABELSrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/Y_LABELS.: [Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>; 3] = [ |
| 244 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#("0%"), |
| 245 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#("50%"), |
| 246 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#("100%"), |
| 247 | ]; |
| 248 | |
| 249 | fn create_time_seriesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/create_time_series().() -> TimeGraphrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#<'static> { |
| 250 | TimeGraphrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph# { |
| 251 | titlerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title.: " Network ".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 252 | x_minrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#x_min.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().15000.0, |
| 253 | hide_x_labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#hide_x_labels.: false, |
| 254 | y_boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#y_bounds.: AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#::Maxrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#Max#(100.5), |
| 255 | y_labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#y_labels.: &Y_LABELSrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/Y_LABELS., |
| 256 | graph_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#graph_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().().fgrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]fg().(Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#::Redrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#Red#), |
| 257 | general_widget_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#general_widget_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().().bgrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]bg().(Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#::Blackrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#Black#), |
| 258 | border_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#border_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().().fgrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]fg().(Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#::Bluerust-analyzer cargo ratatui-core 0.1.2 style/color/Color#Blue#), |
| 259 | border_typerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#border_type.: BorderTyperust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#::Plainrust-analyzer cargo ratatui-widgets 0.3.2 borders/BorderType#Plain#, |
| 260 | is_selectedrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#is_selected.: false, |
| 261 | is_expandedrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#is_expanded.: false, |
| 262 | title_stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#title_style.: Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().().fgrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]fg().(Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#::Cyanrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#Cyan#), |
| 263 | legend_positionrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#legend_position.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 264 | legend_constraintsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#legend_constraints.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 265 | markerrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#marker.: Markerrust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#::Braillerust-analyzer cargo ratatui-core 0.1.2 symbols/marker/Marker#Braille#, |
| 266 | scalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/TimeGraph#scaling.: ChartScalingrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/ChartScaling#::Linearrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/ChartScaling#Linear#, |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 271 | fn time_series_gen_x_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/time_series_gen_x_axis().() { |
| 272 | let tg = create_time_seriesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/create_time_series().(); |
| 273 | let style = Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().().fgrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]fg().(Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#::Redrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#Red#); |
| 274 | let x_axis = tg.generate_x_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]generate_x_axis().(); |
| 275 | |
| 276 | let actual = Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`][Default]default().() |
| 277 | .boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]bounds().(AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#::Minrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#Min#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().15000.0)) |
| 278 | .labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]labels().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("15s", style), Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("0s", style)]) |
| 279 | .stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]style().(style); |
| 280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(x_axis.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#bounds., actual.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#bounds.); |
| 281 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(x_axis.labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#labels., actual.labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#labels.); |
| 282 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(x_axis.stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#style., actual.stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#style.); |
| 283 | } |
| 284 | |
| 285 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 286 | fn time_series_gen_y_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/time_series_gen_y_axis().() { |
| 287 | let tg = create_time_seriesrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/test/create_time_series().(); |
| 288 | let style = Stylerust-analyzer cargo ratatui-core 0.1.2 style/Style#::defaultrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style][Default]default().().fgrust-analyzer cargo ratatui-core 0.1.2 style/impl#[Style]fg().(Colorrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#::Redrust-analyzer cargo ratatui-core 0.1.2 style/color/Color#Red#); |
| 289 | let y_axis = tg.generate_y_axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/base/impl#[`TimeGraph<'_>`]generate_y_axis().(); |
| 290 | |
| 291 | let actual = Axisrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`][Default]default().() |
| 292 | .boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]bounds().(AxisBoundrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#::Maxrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/AxisBound#Max#(100.5)) |
| 293 | .labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]labels().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 294 | Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("0%", style), |
| 295 | Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("50%", style), |
| 296 | Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("100%", style), |
| 297 | ]) |
| 298 | .stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/impl#[`Axis<'a>`]style().(style); |
| 299 | |
| 300 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(y_axis.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#bounds., actual.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#bounds.); |
| 301 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(y_axis.labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#labels., actual.labelsrust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#labels.); |
| 302 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(y_axis.stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#style., actual.stylerust-analyzer cargo bottom 0.14.9 canvas/components/time_series/vendored/Axis#style.); |
| 303 | } |
| 304 | } |