From 5559986009dfdbe0804c1cb184aff798936f2e3a Mon Sep 17 00:00:00 2001 From: Martin Turoci Date: Mon, 3 Oct 2022 11:26:57 +0200 Subject: [PATCH] chore: Minor refactor. #1597 --- ui/src/image_annotator.test.tsx | 2 +- ui/src/image_annotator.tsx | 2 +- ui/src/image_annotator_polygon.ts | 3 +-- ui/src/image_annotator_rect.ts | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ui/src/image_annotator.test.tsx b/ui/src/image_annotator.test.tsx index 5e07212a33..d94595ae6a 100644 --- a/ui/src/image_annotator.test.tsx +++ b/ui/src/image_annotator.test.tsx @@ -394,7 +394,7 @@ describe('ImageAnnotator.tsx', () => { ]) }) - it.only('Moves polygon by a single point, then moves it whole', async () => { + it('Moves polygon by a single point, then moves it whole', async () => { const { container } = render() await waitForImgLoad() const canvasEl = container.querySelectorAll('canvas')[1] diff --git a/ui/src/image_annotator.tsx b/ui/src/image_annotator.tsx index b221158a6c..257e1f59ba 100644 --- a/ui/src/image_annotator.tsx +++ b/ui/src/image_annotator.tsx @@ -306,7 +306,7 @@ export const XImageAnnotator = ({ model }: { model: ImageAnnotator }) => { canvas.parentElement!.style.height = px(height) rectRef.current = new RectAnnotator(canvas) - polygonRef.current = new PolygonAnnotator(canvas) + if (ctxRef.current) polygonRef.current = new PolygonAnnotator(ctxRef.current) ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width * aspectRatio, img.height * aspectRatio) if (!drawnShapes.length) { diff --git a/ui/src/image_annotator_polygon.ts b/ui/src/image_annotator_polygon.ts index 937dca8911..c35a3820f2 100644 --- a/ui/src/image_annotator_polygon.ts +++ b/ui/src/image_annotator_polygon.ts @@ -3,12 +3,11 @@ import { DrawnPoint, DrawnShape, ImageAnnotatorPoint, Position } from "./image_a import { ARC_RADIUS } from "./image_annotator_rect" export class PolygonAnnotator { - private ctx: CanvasRenderingContext2D | null private currPolygonPoints: ImageAnnotatorPoint[] = [] private draggedPoint: ImageAnnotatorPoint | null = null private draggedShape: DrawnShape | null = null - constructor(private canvas: HTMLCanvasElement) { this.ctx = canvas.getContext('2d') } + constructor(private ctx: CanvasRenderingContext2D) { } resetDragging() { this.draggedPoint = null diff --git a/ui/src/image_annotator_rect.ts b/ui/src/image_annotator_rect.ts index 6aed768049..091ecbaf37 100644 --- a/ui/src/image_annotator_rect.ts +++ b/ui/src/image_annotator_rect.ts @@ -101,7 +101,6 @@ export class RectAnnotator { } else if (this.movedRect || intersected?.isFocused) { this.movedRect = this.movedRect || intersected - this.canvas.style.cursor = 'move' if (!this.movedRect?.shape.rect) return const