From 1cdb51dba7782355318d035059af8942fcab79ae Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Mon, 12 Apr 2021 14:39:14 +0300 Subject: [PATCH 1/2] Fixed: Changing a label on canvas does not work when 'Show object details' enabled #3083 --- cvat-canvas/package-lock.json | 2 +- cvat-canvas/package.json | 2 +- cvat-canvas/src/typescript/canvasView.ts | 28 ++++++++++++++++-------- cvat-canvas/src/typescript/shared.ts | 5 ++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cvat-canvas/package-lock.json b/cvat-canvas/package-lock.json index 52752363d23f..38ddf7a80f31 100644 --- a/cvat-canvas/package-lock.json +++ b/cvat-canvas/package-lock.json @@ -1,6 +1,6 @@ { "name": "cvat-canvas", - "version": "2.4.1", + "version": "2.4.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/cvat-canvas/package.json b/cvat-canvas/package.json index 486a71a7af34..d67069978725 100644 --- a/cvat-canvas/package.json +++ b/cvat-canvas/package.json @@ -1,6 +1,6 @@ { "name": "cvat-canvas", - "version": "2.4.1", + "version": "2.4.2", "description": "Part of Computer Vision Annotation Tool which presents its canvas library", "main": "src/canvas.ts", "scripts": { diff --git a/cvat-canvas/src/typescript/canvasView.ts b/cvat-canvas/src/typescript/canvasView.ts index e84f00448a01..95e89b7d6aed 100644 --- a/cvat-canvas/src/typescript/canvasView.ts +++ b/cvat-canvas/src/typescript/canvasView.ts @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Intel Corporation +// Copyright (C) 2019-2021 Intel Corporation // // SPDX-License-Identifier: MIT @@ -1175,7 +1175,7 @@ export class CanvasViewImpl implements CanvasView, Listener { } } else if (reason === UpdateReasons.IMAGE_MOVED) { this.moveCanvas(); - } else if ([UpdateReasons.OBJECTS_UPDATED].includes(reason)) { + } else if (reason === UpdateReasons.OBJECTS_UPDATED) { if (this.mode === Mode.GROUP) { this.groupHandler.resetSelectedObjects(); } @@ -1443,6 +1443,7 @@ export class CanvasViewImpl implements CanvasView, Listener { clientID: state.clientID, outside: state.outside, occluded: state.occluded, + source: state.source, hidden: state.hidden, lock: state.lock, shapeType: state.shapeType, @@ -1534,13 +1535,22 @@ export class CanvasViewImpl implements CanvasView, Listener { } } - for (const attrID of Object.keys(state.attributes)) { - if (state.attributes[attrID] !== drawnState.attributes[+attrID]) { - if (text) { - const [span] = (text.node.querySelectorAll(`[attrID="${attrID}"]`) as any) as SVGTSpanElement[]; - if (span && span.textContent) { - const prefix = span.textContent.split(':').slice(0, -1).join(':'); - span.textContent = `${prefix}: ${state.attributes[attrID]}`; + if (drawnState.label.id !== state.label.id) { + // need to remove created text and create it again + if (text) { + text.remove(); + this.svgTexts[state.clientID] = this.addText(state); + } + } else { + // check if there are updates in attributes + for (const attrID of Object.keys(state.attributes)) { + if (state.attributes[attrID] !== drawnState.attributes[+attrID]) { + if (text) { + const [span] = text.node.querySelectorAll(`[attrID="${attrID}"]`); + if (span && span.textContent) { + const prefix = span.textContent.split(':').slice(0, -1).join(':'); + span.textContent = `${prefix}: ${state.attributes[attrID]}`; + } } } } diff --git a/cvat-canvas/src/typescript/shared.ts b/cvat-canvas/src/typescript/shared.ts index 55790f05409f..9ffa080ebdaa 100644 --- a/cvat-canvas/src/typescript/shared.ts +++ b/cvat-canvas/src/typescript/shared.ts @@ -41,6 +41,7 @@ export interface DrawnState { occluded?: boolean; hidden?: boolean; lock: boolean; + source: 'AUTO' | 'MANUAL'; shapeType: string; points?: number[]; attributes: Record; @@ -176,5 +177,7 @@ export function scalarProduct(a: Vector2D, b: Vector2D): number { } export function vectorLength(vector: Vector2D): number { - return Math.sqrt((vector.i ** 2) + (vector.j ** 2)); + const sqrI = vector.i ** 2; + const sqrJ = vector.j ** 2; + return Math.sqrt(sqrI + sqrJ); } From 30c9a22804dff0966723e2648991d88c4c498e30 Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Mon, 12 Apr 2021 14:45:42 +0300 Subject: [PATCH 2/2] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 217545cb63b2..b6a6eaa280bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Export of instance masks with holes () +- Changing a label on canvas does not work when 'Show object details' enabled () ### Security