MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / eventToTimestamp

Function eventToTimestamp

console/src/utils/graph.ts:28–43  ·  view source on GitHub ↗
({
  event,
  xScale,
  startTime,
  endTime,
}: {
  event: PointerEvent | MouseEvent;
  xScale: { invert: (x: number) => Date };
  startTime: number;
  endTime: number;
})

Source from the content-addressed store, hash-verified

26
27/** Map a pointer event to its cursor timestamp in ms, clamped to `[startTime, endTime]`. Returns `null` only when the event has no coordinates. */
28export function eventToTimestamp({
29 event,
30 xScale,
31 startTime,
32 endTime,
33}: {
34 event: PointerEvent | MouseEvent;
35 xScale: { invert: (x: number) => Date };
36 startTime: number;
37 endTime: number;
38}): number | null {
39 const svgPoint = localPoint(event);
40 if (!svgPoint) return null;
41 const ms = xScale.invert(svgPoint.x).getTime();
42 return Math.min(Math.max(ms, startTime), endTime);
43}
44
45// This function was copied and then modified from the visx XYchart:
46// https://github.com/airbnb/visx/blob/6edbde496fc461094f6b3c60e8ec86c4b720b4f5/packages/visx-xychart/src/utils/findNearestDatumSingleDimension.ts#L7

Callers 1

FreshnessGraphInnerFunction · 0.90

Calls 2

minMethod · 0.80
maxMethod · 0.45

Tested by

no test coverage detected