Skip to content

Commit ef23994

Browse files
authored
Add milliseconds to fla graph hover tooltip (#1124)
* Add milliseconds to fla graph hover tooltip * Address copilot review comments
1 parent 1c79f9b commit ef23994

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

gcs/src/components/fla/graphConfigs.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,34 @@ import tailwindConfig from "../../../tailwind.config.js"
1212

1313
const 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
1517
function 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

2445
function 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

Comments
 (0)