mishig HF Staff commited on
Commit
57aa510
·
verified ·
1 Parent(s): d9ee6f1

Sync from huggingface/lerobot-dataset-visualizer via hub-sync

Browse files
Files changed (1) hide show
  1. src/components/data-recharts.tsx +21 -7
src/components/data-recharts.tsx CHANGED
@@ -430,13 +430,20 @@ const SingleDataGraph = React.memo(
430
  return { groups: grouped, singles: singleList, groupColorMap: colorMap };
431
  }, [dataKeys]);
432
 
433
- const handleMouseLeave = () => hoverStore.set(null);
 
 
434
 
435
- const handleClick = (
436
- data: { activePayload?: { payload: { timestamp: number } }[] } | null,
 
 
 
 
 
437
  ) => {
438
- if (data?.activePayload?.length) {
439
- seek(data.activePayload[0].payload.timestamp);
440
  }
441
  };
442
 
@@ -464,7 +471,7 @@ const SingleDataGraph = React.memo(
464
  </p>
465
  )}
466
  <div
467
- className={`relative w-full ${tall ? "h-[500px]" : "h-72"}`}
468
  onMouseLeave={handleMouseLeave}
469
  >
470
  <ResponsiveContainer width="100%" height="100%">
@@ -472,12 +479,19 @@ const SingleDataGraph = React.memo(
472
  data={chartData}
473
  syncId="episode-sync"
474
  margin={CHART_MARGIN}
475
- onClick={handleClick}
 
 
 
 
 
 
476
  onMouseMove={(state) => {
477
  const payload = state?.activePayload?.[0]?.payload as
478
  | { timestamp?: number }
479
  | undefined;
480
  hoverStore.set(payload?.timestamp ?? null);
 
481
  }}
482
  onMouseLeave={handleMouseLeave}
483
  >
 
430
  return { groups: grouped, singles: singleList, groupColorMap: colorMap };
431
  }, [dataKeys]);
432
 
433
+ /// Pressing seeks, and so does moving while the button is down: the chart doubles as a
434
+ /// scrubber, like the one on the Hub's episode preview.
435
+ const isScrubbingRef = useRef(false);
436
 
437
+ const handleMouseLeave = () => {
438
+ isScrubbingRef.current = false;
439
+ hoverStore.set(null);
440
+ };
441
+
442
+ const seekToPoint = (
443
+ state: { activePayload?: { payload: { timestamp: number } }[] } | null,
444
  ) => {
445
+ if (state?.activePayload?.length) {
446
+ seek(state.activePayload[0].payload.timestamp);
447
  }
448
  };
449
 
 
471
  </p>
472
  )}
473
  <div
474
+ className={`relative w-full select-none ${tall ? "h-[500px]" : "h-72"}`}
475
  onMouseLeave={handleMouseLeave}
476
  >
477
  <ResponsiveContainer width="100%" height="100%">
 
479
  data={chartData}
480
  syncId="episode-sync"
481
  margin={CHART_MARGIN}
482
+ onMouseDown={(state) => {
483
+ isScrubbingRef.current = true;
484
+ seekToPoint(state);
485
+ }}
486
+ onMouseUp={() => {
487
+ isScrubbingRef.current = false;
488
+ }}
489
  onMouseMove={(state) => {
490
  const payload = state?.activePayload?.[0]?.payload as
491
  | { timestamp?: number }
492
  | undefined;
493
  hoverStore.set(payload?.timestamp ?? null);
494
+ if (isScrubbingRef.current) seekToPoint(state);
495
  }}
496
  onMouseLeave={handleMouseLeave}
497
  >