From 9d8b5684389e290bb0518caab5ba2eb052b36d92 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:28:05 -0600 Subject: [PATCH] timeline zooming demo (#9980) --- web/src/pages/UIPlayground.tsx | 53 +++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/web/src/pages/UIPlayground.tsx b/web/src/pages/UIPlayground.tsx index 2e0001a29..056dd87e8 100644 --- a/web/src/pages/UIPlayground.tsx +++ b/web/src/pages/UIPlayground.tsx @@ -11,6 +11,7 @@ import { useApiHost } from "@/api"; import TimelineScrubber from "@/components/playground/TimelineScrubber"; import EventReviewTimeline from "@/components/timeline/EventReviewTimeline"; import { ReviewData, ReviewSegment, ReviewSeverity } from "@/types/review"; +import { Button } from "@/components/ui/button"; // Color data const colors = [ @@ -100,7 +101,7 @@ function UIPlayground() { const contentRef = useRef(null); const [mockEvents, setMockEvents] = useState([]); const [handlebarTime, setHandlebarTime] = useState( - Math.floor(Date.now() / 1000) - 27 * 60 + Math.floor(Date.now() / 1000) - 7 * 60 ); const onSelect = useCallback(({ items }: { items: string[] }) => { @@ -122,6 +123,33 @@ function UIPlayground() { setMockEvents(initialEvents); }, []); + const [zoomLevel, setZoomLevel] = useState(0); + const [zoomSettings, setZoomSettings] = useState({ + segmentDuration: 60, + timestampSpread: 15, + }); + + const possibleZoomLevels = [ + { segmentDuration: 60, timestampSpread: 15 }, + { segmentDuration: 30, timestampSpread: 5 }, + { segmentDuration: 10, timestampSpread: 1 }, + ]; + + function handleZoomIn() { + const nextZoomLevel = Math.min( + possibleZoomLevels.length - 1, + zoomLevel + 1 + ); + setZoomLevel(nextZoomLevel); + setZoomSettings(possibleZoomLevels[nextZoomLevel]); + } + + function handleZoomOut() { + const nextZoomLevel = Math.max(0, zoomLevel - 1); + setZoomLevel(nextZoomLevel); + setZoomSettings(possibleZoomLevels[nextZoomLevel]); + } + return ( <> UI Playground @@ -162,9 +190,20 @@ function UIPlayground() {
- Handlebar time + Timeline -

{handlebarTime}

+

Handlebar timestamp: {handlebarTime}

+

+ + +

Color scheme @@ -192,10 +231,10 @@ function UIPlayground() {