Skip to content

Commit a1d4c2f

Browse files
authored
🎨 [Frontend] Do not change annotations' color when selected (#6048)
1 parent 5a0a74f commit a1d4c2f

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

services/static-webserver/client/source/class/osparc/workbench/Annotation.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ qx.Class.define("osparc.workbench.Annotation", {
130130
}
131131
},
132132

133-
getRepresenationPosition: function() {
133+
getRepresentationPosition: function() {
134134
const representation = this.getRepresentation();
135135
if (representation) {
136136
const attrs = osparc.wrapper.Svg.getRectAttributes(representation);
@@ -183,15 +183,20 @@ qx.Class.define("osparc.workbench.Annotation", {
183183
setSelected: function(selected) {
184184
const representation = this.getRepresentation();
185185
if (representation) {
186-
const selectedColor = qx.theme.manager.Color.getInstance().resolve("busy-orange");
187186
switch (this.getType()) {
188187
case "rect":
189-
osparc.wrapper.Svg.updateItemColor(representation, selected ? selectedColor : this.getColor());
190-
break;
191-
case "note":
192-
case "text":
193-
osparc.wrapper.Svg.updateTextColor(representation, selected ? selectedColor : this.getColor());
188+
case "text": {
189+
if (selected) {
190+
if (!("bBox" in representation.node)) {
191+
const bBox = this.__svgLayer.drawBoundingBox(this);
192+
representation.node["bBox"] = bBox;
193+
}
194+
} else if ("bBox" in representation.node) {
195+
osparc.wrapper.Svg.removeItem(representation.node["bBox"]);
196+
delete representation.node["bBox"];
197+
}
194198
break;
199+
}
195200
}
196201
}
197202
},

services/static-webserver/client/source/class/osparc/workbench/SvgWidget.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ qx.Class.define("osparc.workbench.SvgWidget", {
115115

116116
drawNodeUI: function(width = osparc.workbench.NodeUI.NODE_WIDTH, height = osparc.workbench.NodeUI.NODE_HEIGHT, radius = 4, x = 0, y = 0) {
117117
return osparc.wrapper.Svg.drawNodeUI(this.__canvas, width, height, radius, x, y);
118+
},
119+
120+
drawBoundingBox: function(annotation) {
121+
const offset = 10;
122+
const bBox = annotation.getRepresentation().bbox();
123+
const width = bBox.width + 2*offset;
124+
const height = bBox.height + 2*offset;
125+
const x = bBox.x - offset;
126+
const y = bBox.y - offset;
127+
return osparc.wrapper.Svg.drawDashedRect(this.__canvas, width, height, x, y);
118128
}
119129
}
120130
});

services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
523523
}, this);
524524
annotation.addListener("annotationMoving", () => {
525525
if ("initPos" in annotation) {
526-
const reprPos = annotation.getRepresenationPosition();
526+
const reprPos = annotation.getRepresentationPosition();
527527
const xDiff = reprPos.x - annotation.initPos.x;
528528
const yDiff = reprPos.y - annotation.initPos.y;
529529
this.__itemMoving(annotation.getId(), xDiff, yDiff);

services/static-webserver/client/source/class/osparc/wrapper/Svg.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ qx.Class.define("osparc.wrapper.Svg", {
132132
}
133133
},
134134

135+
/* ANNOTATIONS */
136+
135137
getRectAttributes: function(rect) {
136138
const rectAttrs = rect.node.attributes;
137139
return {
@@ -272,6 +274,29 @@ qx.Class.define("osparc.wrapper.Svg", {
272274
return rect;
273275
},
274276

277+
updateText: function(representation, label) {
278+
if (representation.type === "text") {
279+
representation.text(label);
280+
} else if (representation.type === "svg") {
281+
// nested
282+
representation["textChild"].innerText = label;
283+
}
284+
},
285+
286+
updateTextColor: function(text, color) {
287+
text.font({
288+
fill: color
289+
});
290+
},
291+
292+
updateTextSize: function(text, size) {
293+
text.font({
294+
size: size + "px"
295+
});
296+
},
297+
298+
/* / ANNOTATIONS */
299+
275300
drawDashedRect: function(draw, width, height, x, y) {
276301
const edgeColor = qx.theme.manager.Color.getInstance().getTheme().colors["workbench-edge-comp-active"];
277302
const rect = draw.rect(width, height)
@@ -335,27 +360,6 @@ qx.Class.define("osparc.wrapper.Svg", {
335360
item.remove();
336361
},
337362

338-
updateText: function(representation, label) {
339-
if (representation.type === "text") {
340-
representation.text(label);
341-
} else if (representation.type === "svg") {
342-
// nested
343-
representation["textChild"].innerText = label;
344-
}
345-
},
346-
347-
updateTextColor: function(text, color) {
348-
text.font({
349-
fill: color
350-
});
351-
},
352-
353-
updateTextSize: function(text, size) {
354-
text.font({
355-
size: size + "px"
356-
});
357-
},
358-
359363
updateCurveDashes: function(curve, dashed) {
360364
curve.attr({
361365
"stroke-dasharray": dashed ? 5 : 0

0 commit comments

Comments
 (0)