Skip to content

Commit

Permalink
feat(event-display): delete label on empty value and change add label…
Browse files Browse the repository at this point in the history
… icon
  • Loading branch information
9inpachi committed Feb 8, 2021
1 parent 79e6d7c commit 3756330
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
7 changes: 7 additions & 0 deletions packages/phoenix-event-display/src/event-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,13 @@ export class EventDisplay {
*/
public addLabelToObject(label: string, collection: string, indexInCollection: number, uuid: string) {
const labelId = this.configuration.eventDataLoader.addLabelToEventObject(label, collection, indexInCollection);

// Remove the label if the string is empty
if (!label) {
this.ui.removeLabel(labelId);
return;
}

this.ui.addLabel(labelId);
this.graphicsLibrary.addLabelToObject(label, uuid, labelId);
}
Expand Down
28 changes: 22 additions & 6 deletions packages/phoenix-event-display/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,34 @@ export class UIManager {
labelNode.addConfig('button', {
label: 'Remove',
onClick: () => {
labelNode.remove();
this.three.getSceneManager().removeLabel(labelId);
const objectKeys = labelId.split(' > ');
// this.labelsObject[EventDataType][Collection][Index]
const labelsObject = this.configuration.eventDataLoader?.getLabelsObject();
delete labelsObject?.[objectKeys[0]]?.[objectKeys[1]]?.[objectKeys[2]];
this.removeLabel(labelId, labelNode);
}
});
}
}
}

/**
* Remove label from UI, scene and event data loader if it exists.
* @param labelId A unique label ID string.
* @param labelNode Phoenix menu node of the label if any.
*/
public removeLabel(labelId: string, labelNode?: PhoenixMenuNode) {
if (!labelNode) {
labelNode = this.labelsFolderPM?.children.find((singleLabelNode) => singleLabelNode.name === labelId);
}

if (labelNode) {
this.three.getSceneManager().removeLabel(labelId);
const objectKeys = labelId.split(' > ');
// labelsObject[EventDataType][Collection][Index]
const labelsObject = this.configuration.eventDataLoader?.getLabelsObject();
delete labelsObject?.[objectKeys[0]]?.[objectKeys[1]]?.[objectKeys[2]];

labelNode.remove();
}
}

/**
* Rotate the clipping on detector geometry.
* @param angle Angle of rotation of the clipping.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
<input class="form-control form-control-sm" type="text" [id]="'label' + i" />
</div>
<div class="col-2 p-0 pl-2 text-center icon-wrapper">
<div class="object-select" matTooltip="Add label to object" (click)="addLabel(i, object.uuid)">
<div class="object-select" matTooltip="Add / update / remove object label" (click)="addLabel(i, object.uuid)">
<svg>
<use href="assets/icons/add-icon.svg#add-icon"></use>
<use href="assets/icons/update.svg#update"></use>
</svg>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class CollectionsInfoOverlayComponent implements OnInit {

addLabel(index: number, uuid: string) {
const labelValue = this.elementRef.nativeElement.querySelector(`#label${index}`).value;
if (labelValue && this.selectedCollection) {
if (this.selectedCollection) {
// Empty labelValue will remove the label object
this.eventDisplay.addLabelToObject(labelValue, this.selectedCollection, index, uuid);
}
}
Expand Down

0 comments on commit 3756330

Please sign in to comment.