Skip to content

Commit

Permalink
Add keys to annotation update event
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jul 24, 2024
1 parent 2947f28 commit fd1f14a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/app/drawController.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export class DrawController {
* Update an anotation from the list.
*
* @param {Annotation} annotation The annotation to update.
* @param {string[]} [propKeys] Optional properties that got updated.
*/
updateAnnotation(annotation) {
this.#annotationGroup.update(annotation);
updateAnnotation(annotation, propKeys) {
this.#annotationGroup.update(annotation, propKeys);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/image/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,16 @@ export class AnnotationGroup {
* Update an existing annotation.
*
* @param {Annotation} annotation The annotation to update.
* @param {string[]} [propKeys] Optional properties that got updated.
*/
update(annotation) {
update(annotation, propKeys) {
const index = this.#list.findIndex((item) => item.id === annotation.id);
if (index !== -1) {
this.#list[index] = annotation;
this.#fireEvent({
type: 'annotationupdate',
data: annotation
data: annotation,
keys: propKeys
});
} else {
logger.warn('Cannot find annotation to update');
Expand Down
14 changes: 8 additions & 6 deletions src/tools/drawCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,22 @@ export class UpdateAnnotationCommand {
* Execute the command.
*/
execute() {
for (const prop in this.#newProps) {
this.#annotation[prop] = this.#newProps[prop];
const keys = Object.keys(this.#newProps);
for (const key of keys) {
this.#annotation[key] = this.#newProps[key];
}
this.#drawController.updateAnnotation(this.#annotation);
this.#drawController.updateAnnotation(this.#annotation, keys);
}

/**
* Undo the command.
*/
undo() {
for (const prop in this.#originalProps) {
this.#annotation[prop] = this.#originalProps[prop];
const keys = Object.keys(this.#originalProps);
for (const key of keys) {
this.#annotation[key] = this.#originalProps[key];
}
this.#drawController.updateAnnotation(this.#annotation);
this.#drawController.updateAnnotation(this.#annotation, keys);
}
}
/**
Expand Down
3 changes: 2 additions & 1 deletion src/tools/drawShapeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ export class DrawShapeEditor {
this.#eventCallback({
type: 'annotationupdate',
data: this.#annotation,
dataid: this.#drawLayer.getDataId()
dataid: this.#drawLayer.getDataId(),
keys: Object.keys(newProps)
});
// update original properties
originalProps = {
Expand Down
6 changes: 4 additions & 2 deletions src/tools/drawShapeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ export class DrawShapeHandler {
this.#eventCallback({
type: 'annotationupdate',
data: annotation,
dataid: drawLayer.getDataId()
dataid: drawLayer.getDataId(),
keys: Object.keys(newProps)
});
// update original shape
originalProps = {
Expand Down Expand Up @@ -467,7 +468,8 @@ export class DrawShapeHandler {
this.#eventCallback({
type: 'annotationupdate',
data: annotation,
dataid: drawLayer.getDataId()
dataid: drawLayer.getDataId(),
keys: ['labelPosition']
});
// update original position
originalLabelPosition = newLabelPosition;
Expand Down

0 comments on commit fd1f14a

Please sign in to comment.