1- use chrono:: NaiveDateTime ;
1+ use chrono:: DateTime ;
22use tui:: {
3- layout:: Constraint , prelude:: Buffer , style:: { Color , Style } , symbols:: Marker , text:: { Line , Span } , widgets:: { Axis , Block , Borders , Chart , Dataset , GraphType , Widget }
3+ layout:: Constraint ,
4+ prelude:: Buffer ,
5+ style:: { Color , Style } ,
6+ symbols:: Marker ,
7+ text:: { Line , Span } ,
8+ widgets:: { Axis , Block , Borders , Chart , Dataset , GraphType , Widget } ,
49} ;
510
611use crate :: {
@@ -10,14 +15,8 @@ use crate::{
1015} ;
1116
1217pub fn handle ( _app : & mut App , _key : MappedKey ) { }
13- pub fn draw (
14- app : & mut App ,
15- f : & mut Buffer ,
16- area : tui:: layout:: Rect ,
17- ) {
18- let activities = & app
19- . activities ( )
20- . sort ( & SortBy :: Date , & SortOrder :: Asc ) ;
18+ pub fn draw ( app : & mut App , f : & mut Buffer , area : tui:: layout:: Rect ) {
19+ let activities = & app. activities ( ) . sort ( & SortBy :: Date , & SortOrder :: Asc ) ;
2120 let times: Vec < i64 > = activities. timestamps ( ) ;
2221 let paces: Vec < i64 > = activities. meter_per_hours ( ) ;
2322 let tmax = times. iter ( ) . max ( ) ;
@@ -38,7 +37,7 @@ pub fn draw(
3837 . to_vec ( )
3938 . iter ( )
4039 . map ( |a| {
41- let ts = a. start_date . unwrap ( ) . timestamp ( ) ;
40+ let ts = a. start_date . unwrap ( ) . and_utc ( ) . timestamp ( ) ;
4241 ( ts as f64 , a. meters_per_hour ( ) )
4342 } )
4443 . collect ( ) ;
@@ -47,8 +46,14 @@ pub fn draw(
4746 let activities = app. activities ( ) ;
4847 if let Some ( a) = activities. get ( selected) {
4948 if let Some ( a) = activities. find ( a. id ) {
50- current. push ( ( a. start_date . unwrap ( ) . timestamp ( ) as f64 , * pmin as f64 ) ) ;
51- current. push ( ( a. start_date . unwrap ( ) . timestamp ( ) as f64 , * pmax as f64 ) ) ;
49+ current. push ( (
50+ a. start_date . unwrap ( ) . and_utc ( ) . timestamp ( ) as f64 ,
51+ * pmin as f64 ,
52+ ) ) ;
53+ current. push ( (
54+ a. start_date . unwrap ( ) . and_utc ( ) . timestamp ( ) as f64 ,
55+ * pmax as f64 ,
56+ ) ) ;
5257 }
5358 }
5459 }
@@ -84,15 +89,12 @@ pub fn draw(
8489 . title ( Span :: styled ( "Date" , Style :: default ( ) . fg ( Color :: Red ) ) )
8590 . style ( Style :: default ( ) . fg ( Color :: White ) )
8691 . bounds ( [ * tmin. unwrap ( ) as f64 , * tmax. unwrap ( ) as f64 ] )
87- . labels (
88- xaxis
89- . map ( |p| {
90- Line :: from ( match NaiveDateTime :: from_timestamp_millis ( p * 1000 ) {
91- Some ( t) => t. format ( "%Y-%m-%d" ) . to_string ( ) ,
92- None => "n/a" . to_string ( ) ,
93- } )
94- } )
95- ) ,
92+ . labels ( xaxis. map ( |p| {
93+ Line :: from ( match DateTime :: from_timestamp_millis ( p * 1000 ) {
94+ Some ( t) => t. format ( "%Y-%m-%d" ) . to_string ( ) ,
95+ None => "n/a" . to_string ( ) ,
96+ } )
97+ } ) ) ,
9698 )
9799 . y_axis (
98100 Axis :: default ( )
@@ -102,10 +104,7 @@ pub fn draw(
102104 * pmin as f64 ,
103105 * pmax as f64 + ( pdiff as f64 / activities. len ( ) as f64 ) ,
104106 ] )
105- . labels (
106- yaxis
107- . map ( |p| Span :: from ( app. unit_formatter . pace ( 3600 , p as f64 ) ) )
108- ) ,
107+ . labels ( yaxis. map ( |p| Span :: from ( app. unit_formatter . pace ( 3600 , p as f64 ) ) ) ) ,
109108 ) ;
110109 chart. render ( area, f) ;
111110}
0 commit comments