Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating proper values for ChangeType parameter in AnnotationModifiedEventDetail. #1821

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,8 @@ enum ChangeTypes {
MetadataReferenceModified = "MetadataReferenceModified",
// (undocumented)
StatsUpdated = "StatsUpdated"
// (undocumented)
LabelChange = 'LabelChange',
}

// @public (undocumented)
Expand Down
4 changes: 4 additions & 0 deletions packages/tools/src/enums/ChangeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ enum ChangeTypes {
* so as to cause it to be drawn on the change, or removed if it is no longer visible.
*/
MetadataReferenceModified = 'MetadataReferenceModified',
/**
* Occurs when an annotation label is updated.
*/
LabelChange = 'LabelChange',
}

export default ChangeTypes;
12 changes: 10 additions & 2 deletions packages/tools/src/tools/annotation/LengthTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Events } from '../../enums';
import { Events, ChangeTypes } from '../../enums';
import {
getEnabledElement,
utilities as csUtils,
Expand Down Expand Up @@ -481,6 +481,14 @@ class LengthTool extends AnnotationTool {
this.editData.hasMoved = true;

triggerAnnotationRenderForViewportIds(viewportIdsToRender);

if (annotation.invalidated) {
triggerAnnotationModified(
annotation,
element,
ChangeTypes.HandlesUpdated
);
}
};

cancel = (element: HTMLDivElement) => {
Expand Down Expand Up @@ -888,7 +896,7 @@ class LengthTool extends AnnotationTool {
annotation.invalidated = false;

// Dispatching annotation modified
triggerAnnotationModified(annotation, element);
triggerAnnotationModified(annotation, element, ChangeTypes.StatsUpdated);

return cachedStats;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/tools/src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const roundNumber = utilities.roundNumber;
import normalizeViewportPlane from './normalizeViewportPlane';
import IslandRemoval from './segmentation/islandRemoval';
import { getPixelValueUnits } from './getPixelValueUnits';
import setAnnotationLabel from './setAnnotationLabel';

export {
math,
Expand Down Expand Up @@ -96,4 +97,5 @@ export {
pointInSurroundingSphereCallback,
normalizeViewportPlane,
IslandRemoval,
setAnnotationLabel,
};
12 changes: 12 additions & 0 deletions packages/tools/src/utilities/setAnnotationLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Annotation } from '../types/AnnotationTypes';
import { triggerAnnotationModified } from '../stateManagement/annotation/helpers/state';
import { ChangeTypes } from '../enums';

export default function setAnnotationLabel(
annotation: Annotation,
element: HTMLDivElement,
updatedLabel: string
) {
annotation.data.label = updatedLabel;
triggerAnnotationModified(annotation, element, ChangeTypes.LabelChange);
}