Skip to content

Commit

Permalink
ui-spacetimechart: fix time captions
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Chanas <[email protected]>
  • Loading branch information
anisometropie committed Feb 12, 2025
1 parent 63904b4 commit abe8046
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions ui-spacetimechart/src/components/TimeCaptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback } from 'react';
import { useDraw } from '../hooks/useCanvas';
import { MINUTE } from '../lib/consts';
import { type DrawingFunction } from '../lib/types';
import { computeVisibleTimeMarkers } from '../utils/canvas';

const MINUTES_FORMATTER = (t: number) => `:${new Date(t).getMinutes().toString().padStart(2, '0')}`;
const HOURS_FORMATTER = (t: number, pixelsPerMinute: number) => {
Expand Down Expand Up @@ -71,20 +72,17 @@ const TimeCaptions = () => {
return false;
});

// - Keys are times in ms
// - Values are the highest level on each time
const labelMarks: Record<number, { level: number; rangeIndex: number }> = {};
timeRanges.map((range, i) => {
const labelLevel = labelLevels[i];

if (!labelLevel) return;

let t = Math.floor(minT / range) * range;
while (t <= maxT) {
if (labelLevel) labelMarks[t] = { level: labelLevel, rangeIndex: i };
t += range;
}
const labelMarkFormatter = (labelLevel: number, i: number) => ({
level: labelLevel,
rangeIndex: i,
});
const labelMarks = computeVisibleTimeMarkers(
minT,
maxT,
timeRanges,
labelLevels,
labelMarkFormatter
);

// Render caption background:
ctx.fillStyle = background;
Expand Down

0 comments on commit abe8046

Please sign in to comment.