@@ -12,13 +12,34 @@ import tailwindConfig from "../../../tailwind.config.js"
1212
1313const tailwindColors = resolveConfig ( tailwindConfig ) . theme . colors
1414
15+ // Converts microseconds to a display time in the format mm:ss or mm:ss.SSS
16+ // depending on the roundTo parameter
1517function microsecondsToDisplayTime ( microseconds , roundTo ) {
16- var seconds = microseconds / 1_000_000
17- var mins = Math . floor ( seconds / 60 )
18+ const safeMicroseconds = Number . isFinite ( microseconds ) ? microseconds : 0
19+ const precision = Number . isInteger ( roundTo )
20+ ? Math . max ( 0 , Math . min ( 6 , roundTo ) )
21+ : 0
1822
19- return `${ String ( mins ) . padStart ( 2 , "0" ) } :${ String (
20- ( seconds % 60 ) . toFixed ( roundTo ) ,
21- ) . padStart ( 2 , "0" ) } `
23+ const wholeSeconds = Math . floor ( safeMicroseconds / 1_000_000 )
24+ const remainingMicros = safeMicroseconds - wholeSeconds * 1_000_000
25+
26+ const fractionScale = 10 ** precision
27+ let roundedFraction = Math . round (
28+ ( remainingMicros / 1_000_000 ) * fractionScale ,
29+ )
30+
31+ const secondCarry = Math . floor ( roundedFraction / fractionScale )
32+ roundedFraction %= fractionScale
33+
34+ const totalSeconds = wholeSeconds + secondCarry
35+ const mins = Math . floor ( totalSeconds / 60 )
36+ const secs = totalSeconds % 60
37+
38+ if ( precision === 0 ) {
39+ return `${ String ( mins ) . padStart ( 2 , "0" ) } :${ String ( secs ) . padStart ( 2 , "0" ) } `
40+ }
41+
42+ return `${ String ( mins ) . padStart ( 2 , "0" ) } :${ String ( secs ) . padStart ( 2 , "0" ) } .${ String ( roundedFraction ) . padStart ( precision , "0" ) } `
2243}
2344
2445function getChartLabel ( context ) {
@@ -82,7 +103,7 @@ export const dataflashOptions = {
82103 tooltip : {
83104 callbacks : {
84105 title : function ( context ) {
85- return microsecondsToDisplayTime ( context [ 0 ] . parsed . x , 5 )
106+ return microsecondsToDisplayTime ( context [ 0 ] . parsed . x , 3 )
86107 } ,
87108 label : getChartLabel ,
88109 } ,
@@ -111,7 +132,9 @@ export const fgcsOptions = {
111132 tooltip : {
112133 callbacks : {
113134 title : function ( context ) {
114- return moment ( context [ 0 ] . parsed . x ) . format ( "MMMM Do YYYY, h:mm:ss a" )
135+ return moment ( context [ 0 ] . parsed . x ) . format (
136+ "MMMM Do YYYY, HH:mm:ss.SSS" ,
137+ )
115138 } ,
116139 label : getChartLabel ,
117140 } ,
0 commit comments