Spaces:
Runtime error
Runtime error
Khunndev Cursor commited on
Commit ·
43b8802
1
Parent(s): 1337f5b
Restore circle draw animation and show dock only after it finishes.
Browse files
frontend/src/components/ResultCanvas.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
/**
|
| 2 |
* ResultCanvas
|
| 3 |
-
* Optional animation: circles draw in one-by-one (arc sweep) with a count-up.
|
| 4 |
-
*
|
| 5 |
*/
|
| 6 |
import { useEffect, useRef, useState } from 'react'
|
| 7 |
import { isLowMemoryDevice } from '../lib/inference'
|
|
@@ -243,6 +243,12 @@ export function ResultCanvas({
|
|
| 243 |
const [animating, setAnimating] = useState(animate)
|
| 244 |
const skipRef = useRef(false)
|
| 245 |
const rafRef = useRef(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
// zoom / pan state (used in interactive phase)
|
| 248 |
const transformRef = useRef({ scale: 1, tx: 0, ty: 0 })
|
|
@@ -260,6 +266,7 @@ export function ResultCanvas({
|
|
| 260 |
useEffect(() => {
|
| 261 |
if (detections.length === 0) {
|
| 262 |
setAnimating(false)
|
|
|
|
| 263 |
onAnimationComplete?.()
|
| 264 |
return
|
| 265 |
}
|
|
@@ -270,6 +277,12 @@ export function ResultCanvas({
|
|
| 270 |
const ctx = canvas.getContext('2d')
|
| 271 |
if (!ctx) return
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
// Canvas buffer is capped on low-memory devices; ctx.setTransform(rs,rs)
|
| 274 |
// lets all drawing below keep using natural-pixel coordinates. CSS
|
| 275 |
// width:100% then scales the buffer to the display width.
|
|
@@ -300,6 +313,7 @@ export function ResultCanvas({
|
|
| 300 |
|
| 301 |
if (!animate) {
|
| 302 |
setAnimating(false)
|
|
|
|
| 303 |
onAnimationComplete?.()
|
| 304 |
return
|
| 305 |
}
|
|
@@ -371,6 +385,7 @@ export function ResultCanvas({
|
|
| 371 |
if (countDisplayRef?.current) {
|
| 372 |
countDisplayRef.current.textContent = String(detections.length)
|
| 373 |
}
|
|
|
|
| 374 |
setAnimating(false)
|
| 375 |
onAnimationComplete?.()
|
| 376 |
}
|
|
|
|
| 1 |
/**
|
| 2 |
* ResultCanvas
|
| 3 |
+
* Optional intro animation: circles draw in one-by-one (arc sweep) with a count-up.
|
| 4 |
+
* Interactive phase: zoom/pan + edit tools. Tap during intro to skip to the final frame.
|
| 5 |
*/
|
| 6 |
import { useEffect, useRef, useState } from 'react'
|
| 7 |
import { isLowMemoryDevice } from '../lib/inference'
|
|
|
|
| 243 |
const [animating, setAnimating] = useState(animate)
|
| 244 |
const skipRef = useRef(false)
|
| 245 |
const rafRef = useRef(0)
|
| 246 |
+
const introPlayedRef = useRef(false)
|
| 247 |
+
const imageRef = useRef(image)
|
| 248 |
+
if (image !== imageRef.current) {
|
| 249 |
+
imageRef.current = image
|
| 250 |
+
introPlayedRef.current = false
|
| 251 |
+
}
|
| 252 |
|
| 253 |
// zoom / pan state (used in interactive phase)
|
| 254 |
const transformRef = useRef({ scale: 1, tx: 0, ty: 0 })
|
|
|
|
| 266 |
useEffect(() => {
|
| 267 |
if (detections.length === 0) {
|
| 268 |
setAnimating(false)
|
| 269 |
+
introPlayedRef.current = false
|
| 270 |
onAnimationComplete?.()
|
| 271 |
return
|
| 272 |
}
|
|
|
|
| 277 |
const ctx = canvas.getContext('2d')
|
| 278 |
if (!ctx) return
|
| 279 |
|
| 280 |
+
// After the intro animation, layout-only changes (e.g. dock appearing) must not replay it.
|
| 281 |
+
if (introPlayedRef.current && animate) {
|
| 282 |
+
setAnimating(false)
|
| 283 |
+
return
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
// Canvas buffer is capped on low-memory devices; ctx.setTransform(rs,rs)
|
| 287 |
// lets all drawing below keep using natural-pixel coordinates. CSS
|
| 288 |
// width:100% then scales the buffer to the display width.
|
|
|
|
| 313 |
|
| 314 |
if (!animate) {
|
| 315 |
setAnimating(false)
|
| 316 |
+
introPlayedRef.current = true
|
| 317 |
onAnimationComplete?.()
|
| 318 |
return
|
| 319 |
}
|
|
|
|
| 385 |
if (countDisplayRef?.current) {
|
| 386 |
countDisplayRef.current.textContent = String(detections.length)
|
| 387 |
}
|
| 388 |
+
introPlayedRef.current = true
|
| 389 |
setAnimating(false)
|
| 390 |
onAnimationComplete?.()
|
| 391 |
}
|
frontend/src/components/StepResults.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import { useEffect, useRef, useState } from 'react'
|
|
|
|
| 2 |
import type { Detection, DiameterGroup, Lang, ToolMode } from '../lib/types'
|
| 3 |
import { ResultCanvas } from './ResultCanvas'
|
| 4 |
import { ResultsDock } from './ResultsDock'
|
|
@@ -30,14 +31,19 @@ export function StepResults({
|
|
| 30 |
}: Props) {
|
| 31 |
const [tool, setTool] = useState<ToolMode>('view')
|
| 32 |
const [selectedGroupId, setSelectedGroupId] = useState(groups[0]?.id ?? 0)
|
|
|
|
| 33 |
const [exportOpen, setExportOpen] = useState(false)
|
|
|
|
| 34 |
const canvasRef = useRef<HTMLCanvasElement | null>(null)
|
| 35 |
const viewportRef = useRef<HTMLDivElement>(null)
|
| 36 |
const [viewportSize, setViewportSize] = useState<{ w: number; h: number } | null>(null)
|
| 37 |
|
| 38 |
useEffect(() => {
|
| 39 |
const el = viewportRef.current
|
| 40 |
-
if (!el)
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
const measure = () => {
|
| 43 |
const w = el.clientWidth
|
|
@@ -49,13 +55,19 @@ export function StepResults({
|
|
| 49 |
const ro = new ResizeObserver(measure)
|
| 50 |
ro.observe(el)
|
| 51 |
return () => ro.disconnect()
|
| 52 |
-
}, [])
|
| 53 |
|
| 54 |
return (
|
| 55 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
<div
|
| 57 |
ref={viewportRef}
|
| 58 |
-
className="relative flex min-h-0 items-center justify-center overflow-hidden px-2 pt-2 pb-1"
|
| 59 |
>
|
| 60 |
<ResultCanvas
|
| 61 |
image={image}
|
|
@@ -63,26 +75,47 @@ export function StepResults({
|
|
| 63 |
groups={groups}
|
| 64 |
tool={tool}
|
| 65 |
selectedGroupId={selectedGroupId}
|
| 66 |
-
|
|
|
|
| 67 |
onUpdate={onUpdate}
|
| 68 |
onCanvasReady={(c) => { canvasRef.current = c }}
|
|
|
|
|
|
|
| 69 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</div>
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
| 87 |
<ExportSheet
|
| 88 |
lang={lang}
|
|
|
|
| 1 |
import { useEffect, useRef, useState } from 'react'
|
| 2 |
+
import { t } from '../lib/i18n'
|
| 3 |
import type { Detection, DiameterGroup, Lang, ToolMode } from '../lib/types'
|
| 4 |
import { ResultCanvas } from './ResultCanvas'
|
| 5 |
import { ResultsDock } from './ResultsDock'
|
|
|
|
| 31 |
}: Props) {
|
| 32 |
const [tool, setTool] = useState<ToolMode>('view')
|
| 33 |
const [selectedGroupId, setSelectedGroupId] = useState(groups[0]?.id ?? 0)
|
| 34 |
+
const [animDone, setAnimDone] = useState(false)
|
| 35 |
const [exportOpen, setExportOpen] = useState(false)
|
| 36 |
+
const countDisplayRef = useRef<HTMLSpanElement>(null)
|
| 37 |
const canvasRef = useRef<HTMLCanvasElement | null>(null)
|
| 38 |
const viewportRef = useRef<HTMLDivElement>(null)
|
| 39 |
const [viewportSize, setViewportSize] = useState<{ w: number; h: number } | null>(null)
|
| 40 |
|
| 41 |
useEffect(() => {
|
| 42 |
const el = viewportRef.current
|
| 43 |
+
if (!el || !animDone) {
|
| 44 |
+
setViewportSize(null)
|
| 45 |
+
return
|
| 46 |
+
}
|
| 47 |
|
| 48 |
const measure = () => {
|
| 49 |
const w = el.clientWidth
|
|
|
|
| 55 |
const ro = new ResizeObserver(measure)
|
| 56 |
ro.observe(el)
|
| 57 |
return () => ro.disconnect()
|
| 58 |
+
}, [animDone])
|
| 59 |
|
| 60 |
return (
|
| 61 |
+
<div
|
| 62 |
+
className={
|
| 63 |
+
animDone
|
| 64 |
+
? 'grid min-h-0 flex-1 grid-rows-[minmax(0,1fr)_auto] overflow-hidden bg-[var(--bg)]'
|
| 65 |
+
: 'flex min-h-0 flex-1 flex-col overflow-hidden bg-[var(--bg)]'
|
| 66 |
+
}
|
| 67 |
+
>
|
| 68 |
<div
|
| 69 |
ref={viewportRef}
|
| 70 |
+
className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden px-2 pt-2 pb-1"
|
| 71 |
>
|
| 72 |
<ResultCanvas
|
| 73 |
image={image}
|
|
|
|
| 75 |
groups={groups}
|
| 76 |
tool={tool}
|
| 77 |
selectedGroupId={selectedGroupId}
|
| 78 |
+
animate
|
| 79 |
+
displayBounds={animDone ? viewportSize : null}
|
| 80 |
onUpdate={onUpdate}
|
| 81 |
onCanvasReady={(c) => { canvasRef.current = c }}
|
| 82 |
+
onAnimationComplete={() => setAnimDone(true)}
|
| 83 |
+
countDisplayRef={countDisplayRef}
|
| 84 |
/>
|
| 85 |
+
|
| 86 |
+
{!animDone && (
|
| 87 |
+
<div className="pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2">
|
| 88 |
+
<div className="rounded-full border border-[var(--hairline)] bg-[var(--surface)]/95 px-5 py-2 shadow-[var(--shadow-md)] backdrop-blur-sm">
|
| 89 |
+
<span
|
| 90 |
+
ref={countDisplayRef}
|
| 91 |
+
className="text-3xl font-bold tabular-nums text-[var(--brand)]"
|
| 92 |
+
>
|
| 93 |
+
0
|
| 94 |
+
</span>
|
| 95 |
+
<span className="ml-2 text-[10px] font-semibold uppercase tracking-widest text-[var(--text-faint)]">
|
| 96 |
+
{t(lang, 'total')}
|
| 97 |
+
</span>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
)}
|
| 101 |
</div>
|
| 102 |
|
| 103 |
+
{animDone && (
|
| 104 |
+
<ResultsDock
|
| 105 |
+
lang={lang}
|
| 106 |
+
total={detections.length}
|
| 107 |
+
tool={tool}
|
| 108 |
+
groups={groups}
|
| 109 |
+
counts={counts}
|
| 110 |
+
selectedGroupId={selectedGroupId}
|
| 111 |
+
onToolChange={setTool}
|
| 112 |
+
onSelectGroup={setSelectedGroupId}
|
| 113 |
+
onExpectedChange={onExpectedChange}
|
| 114 |
+
onNewPhoto={onNewPhoto}
|
| 115 |
+
onRecount={onRecount}
|
| 116 |
+
onExport={() => setExportOpen(true)}
|
| 117 |
+
/>
|
| 118 |
+
)}
|
| 119 |
|
| 120 |
<ExportSheet
|
| 121 |
lang={lang}
|