Skip to content

Commit ea18ca0

Browse files
committed
fix: improve ms/ns display, waveforms now format time correctly
1 parent 89f67bf commit ea18ca0

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/components/ControllableWave/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const ControllableWave = ({
1818
durationGroups,
1919
timestamps,
2020
gridLineMetrics,
21+
timeFormat,
2122
}) => {
2223
let [matrix, setMatrix] = useRafState(() => {
2324
const mat = new Matrix()
@@ -54,6 +55,7 @@ export const ControllableWave = ({
5455
curves={curves}
5556
width={width}
5657
height={height}
58+
timeFormat={timeFormat}
5759
transformMatrix={matrix}
5860
gridLineMetrics={gridLineMetrics}
5961
timestamps={timestamps}

src/components/MainLayout/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const MainLayout = ({
198198
gridLineMetrics={gridLineMetrics}
199199
topLevelMatrix={topLevelMatrix}
200200
setTopLevelMatrix={setTopLevelMatrix}
201+
timeFormat={timeFormat}
201202
/>
202203
))}
203204
</Container>

src/components/Timeline/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const TimeText = styled("div")(({ x, faded }) => ({
2424
left: x,
2525
borderLeft: "1px solid rgba(255,255,255,0.5)",
2626
paddingLeft: 4,
27-
whiteSpace: "wrap",
28-
opacity: faded ? 0.5 : 1,
27+
whiteSpace: "pre-wrap",
28+
opacity: faded ? 0.25 : 0.75,
2929
}))
3030

3131
const Svg = styled("svg")({

src/components/Wave/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import colorAlpha from "color-alpha"
55
import useColors from "../../hooks/use-colors"
66
import { formatTime } from "../../utils/format-time"
77

8-
const userSelectOffStyle = { userSelect: "none" }
8+
const userSelectOffStyle = {
9+
userSelect: "none",
10+
whiteSpace: "pre",
11+
fontVariantNumeric: "tabular-nums",
12+
}
913

1014
const Container = styled("div")({})
1115

@@ -53,6 +57,7 @@ export const Wave = ({
5357
width,
5458
height,
5559
transformMatrix,
60+
timeFormat,
5661
durationGroups = [],
5762
timestamps = [],
5863
gridLineMetrics,
@@ -85,10 +90,10 @@ export const Wave = ({
8590
const globalTimelineIndex = Math.floor(timeAtLine / majorDuration)
8691

8792
let textElm = null
88-
if (globalTimelineIndex % 7 === 0) {
93+
if (globalTimelineIndex % 1 === 0) {
8994
const timeLines = formatTime(
9095
timeAtLine,
91-
"dates",
96+
timeFormat,
9297
visibleDuration
9398
).split("\n")
9499
textElm = timeLines.map((tl, i) => (

src/utils/format-time.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ export const formatTime = (time, format, visibleDuration) => {
1212
(!lessThan3DaysShown ? "" : "\n" + moment(time).format("h:mm:ss a"))
1313
)
1414
}
15-
if (time < 0) return "< 00:00:00"
16-
const deciSecs = Math.floor((time % 1000) / 10)
15+
const showNs = visibleDuration < 5
16+
const showMs = visibleDuration < 5000
17+
const ns = Math.floor((time * 1000) % 1000)
18+
const ms = Math.floor(time % 1000)
1719
const secs = Math.floor((time / 1000) % 60)
1820
const mins = Math.floor((time / 60000) % 60)
1921
const hours = Math.floor(time / (60000 * 60))
20-
return [hours, mins, secs, deciSecs]
21-
.map((t) => t.toString().padStart(2, "0"))
22-
.join(":")
22+
if (time < 0) return "< 00:00:00"
23+
return (
24+
[hours, mins, secs].map((t) => t.toString().padStart(2, "0")).join(":") +
25+
(showMs ? `.${ms.toString().padStart(3, "0")}` : "") +
26+
(showNs ? `\n+${ns.toString()} ns` : "")
27+
)
2328
}
2429
export default formatTime

src/utils/get-minor-major-duration-lines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const findReasonableGridDuration = (duration) => {
3232
let bestFittingIntervalIndex = 0
3333
let bestFittingIntervalScore = -Infinity
3434
for (const [i, [, timeInterval]] of Object.entries(timeIntervals)) {
35-
const timeIntervalScore = -1 * Math.abs(duration / timeInterval - 20)
35+
const timeIntervalScore = -1 * Math.abs(duration / timeInterval - 5)
3636
if (timeIntervalScore > bestFittingIntervalScore) {
3737
bestFittingIntervalIndex = i
3838
bestFittingIntervalScore = timeIntervalScore

0 commit comments

Comments
 (0)