Skip to content

Commit 80007d6

Browse files
committed
__updateAnnotationPositionFromDiff
1 parent 2fd7335 commit 80007d6

File tree

1 file changed

+42
-14
lines changed
  • services/static-webserver/client/source/class/osparc/data/model

1 file changed

+42
-14
lines changed

services/static-webserver/client/source/class/osparc/data/model/StudyUI.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,22 @@ qx.Class.define("osparc.data.model.StudyUI", {
167167
const node = currentStudy.getWorkbench().getNode(nodeId);
168168
if ("position" in uiDiff["workbench"][nodeId]) {
169169
const positionDiff = uiDiff["workbench"][nodeId]["position"];
170-
this.__updatePositionFromDiff(node, positionDiff);
170+
this.__updateNodePositionFromDiff(node, positionDiff);
171171
}
172172
if ("marker" in uiDiff["workbench"][nodeId]) {
173173
const markerDiff = uiDiff["workbench"][nodeId]["marker"];
174-
this.__updateMarkerFromDiff(node, markerDiff);
174+
this.__updateNodeMarkerFromDiff(node, markerDiff);
175175
}
176176
});
177177
}
178-
} else if ("annotations" in uiDiff) {
179-
const annotationsDiff = uiDiff["annotations"];
180-
this.__updateAnnotationsFromDiff(annotationsDiff);
178+
}
179+
if (uiDiff["annotations"]) {
180+
const annotationsData = uiDiff["annotations"];
181+
this.__updateAnnotationsFromDiff(annotationsData);
181182
}
182183
},
183184

184-
__updatePositionFromDiff: function(node, positionDiff) {
185+
__updateNodePositionFromDiff: function(node, positionDiff) {
185186
if (node) {
186187
const newPos = node.getPosition();
187188
if ("x" in positionDiff) {
@@ -194,7 +195,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
194195
}
195196
},
196197

197-
__updateMarkerFromDiff: function(node, markerDiff) {
198+
__updateNodeMarkerFromDiff: function(node, markerDiff) {
198199
if (node) {
199200
if (markerDiff instanceof Array) {
200201
if (markerDiff.length === 1) {
@@ -212,21 +213,48 @@ qx.Class.define("osparc.data.model.StudyUI", {
212213
}
213214
},
214215

216+
__updateAnnotationPositionFromDiff: function(annotation, positionDiff) {
217+
if (annotation) {
218+
const newPos = annotation.getPosition();
219+
if ("x" in positionDiff) {
220+
newPos.x = positionDiff["x"][1];
221+
}
222+
if ("y" in positionDiff) {
223+
newPos.y = positionDiff["y"][1];
224+
}
225+
annotation.setPosition(newPos.x, newPos.y);
226+
}
227+
},
228+
215229
__updateAnnotationsFromDiff: function(annotationsData) {
216230
// check if annotation data is an object or an array
217-
if (annotationsData instanceof Object) {
218-
Object.entries(annotationsData).forEach(([annotationId, annotationData]) => {
219-
if (annotationData.length === 1) {
231+
const annotations = this.getAnnotations();
232+
Object.entries(annotationsData).forEach(([annotationId, annotationDiff]) => {
233+
if (annotationsData instanceof Array) {
234+
if (annotationDiff.length === 1) {
220235
// it was added
221-
const annotation = this.addAnnotation(annotationData[0], annotationId);
236+
const annotation = this.addAnnotation(annotationDiff[0], annotationId);
222237
this.fireDataEvent("annotationAdded", annotation);
223-
} else if (annotationData.length === 3 && annotationData[1] === null) {
238+
} else if (annotationDiff.length === 3 && annotationDiff[1] === 0) {
224239
// it was removed
225240
this.removeAnnotation(annotationId);
226241
this.fireDataEvent("annotationRemoved", annotationId);
227242
}
228-
});
229-
}
243+
} else if (annotationsData instanceof Object) {
244+
// it was updated
245+
if (annotationId in annotations) {
246+
const annotation = annotations[annotationId];
247+
if ("attributes" in annotationDiff) {
248+
this.__updateAnnotationPositionFromDiff(annotation, annotationDiff["attributes"]);
249+
}
250+
if ("color" in annotationDiff) {
251+
annotation.setColor(annotationDiff["color"][1]);
252+
}
253+
} else {
254+
console.warn(`Annotation with id ${annotationId} not found`);
255+
}
256+
}
257+
});
230258
},
231259

232260
listenToChanges: function() {

0 commit comments

Comments
 (0)