@@ -66,24 +66,38 @@ function formatXAxis(ts: number) {
6666
6767function formatTimeOfEchart ( params : any , averageByDate : boolean ) : string {
6868 const format = params instanceof Array ? params [ 0 ] : params
69- const { value } = format
69+ const { value, data } = format
70+ const milliseconds = data ?. [ 4 ] || 0
7071 // If average, don't show the date
7172 const start = formatTime ( value [ 2 ] , averageByDate ? '{h}:{i}' : '{m}-{d} {h}:{i}' )
7273 const end = formatTime ( value [ 3 ] , '{h}:{i}' )
73- return `${ formatPeriodCommon ( value [ 1 ] * 1000 ) } <br/>${ start } -${ end } `
74+ return `${ formatPeriodCommon ( Math . floor ( milliseconds ) ) } <br/>${ start } -${ end } `
7475}
7576
7677const TITLE = t ( msg => msg . habit . chart . title )
77- const Y_AXIAS_NAME = t ( msg => msg . habit . chart . yAxisName )
78+ const Y_AXIAS_MIN = t ( msg => msg . habit . chart . yAxisMin )
79+ const Y_AXIAS_HOUR = t ( msg => msg . habit . chart . yAxisHour )
80+
81+ function getYAxiasName ( periodSize : number ) {
82+ return periodSize === 8 ? Y_AXIAS_HOUR : Y_AXIAS_MIN
83+ }
84+
85+ function getYAxiasValue ( milliseconds : number , periodSize : number ) {
86+ const seconds = Math . floor ( milliseconds / 1000 )
87+ const minutes = Number . parseFloat ( ( seconds / 60 ) . toFixed ( 1 ) )
88+ const hours = Number . parseFloat ( ( minutes / 60 ) . toFixed ( 1 ) )
89+ return periodSize === 8 ? hours : minutes
90+ }
91+
7892function generateOptions ( data : timer . period . Row [ ] , averageByDate : boolean , periodSize : number ) : EcOption {
7993 const periodData : timer . period . Row [ ] = averageByDate ? averageByDay ( data , periodSize ) : data
8094 const valueData : any [ ] = [ ]
8195 periodData . forEach ( ( item ) => {
8296 const startTime = item . startTime . getTime ( )
8397 const endTime = item . endTime . getTime ( )
84- const seconds = Math . floor ( item . milliseconds / 1000 )
8598 const x = ( startTime + endTime ) / 2
86- valueData . push ( [ x , seconds , startTime , endTime ] )
99+ const milliseconds = item . milliseconds
100+ valueData . push ( [ x , getYAxiasValue ( milliseconds , periodSize ) , startTime , endTime , milliseconds ] )
87101 } )
88102
89103 const xAxisMin = periodData [ 0 ] . startTime . getTime ( )
@@ -123,7 +137,7 @@ function generateOptions(data: timer.period.Row[], averageByDate: boolean, perio
123137 max : xAxisMax
124138 } ,
125139 yAxis : {
126- name : Y_AXIAS_NAME ,
140+ name : getYAxiasName ( periodSize ) ,
127141 nameTextStyle : { color : textColor } ,
128142 type : 'value' ,
129143 axisLabel : { color : textColor } ,
0 commit comments