Skip to content

Commit 04ba672

Browse files
authored
✨ Tooltip on node links (ITISFoundation#3441)
1 parent 9b0024d commit 04ba672

File tree

4 files changed

+80
-30
lines changed

4 files changed

+80
-30
lines changed

services/static-webserver/client/source/class/osparc/component/widget/NodesSlidesTree.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ qx.Class.define("osparc.component.widget.NodesSlidesTree", {
218218
fnct = this.__moveDown;
219219
break;
220220
}
221-
this.changeSelectedNode(item.getModel().getNodeId());
222221
if (fnct.call(this, item.getModel())) {
223222
this.__tree.refresh();
224223
}

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ qx.Class.define("osparc.component.workbench.EdgeUI", {
4444
this.setEdge(edge);
4545
this.setRepresentation(representation);
4646

47+
const hint = new osparc.ui.hint.Hint(null, "");
48+
representation.hint = hint;
49+
4750
if (edge.getInputNode()) {
48-
edge.getInputNode().getStatus().addListener("changeModified", () => {
49-
this.__updateEdgeColor();
50-
});
51+
edge.getInputNode().getStatus().addListener("changeModified", () => this.__updateEdgeState());
5152
}
52-
this.__updateEdgeColor();
53+
edge.addListener("changePortConnected", () => this.__updateEdgeState());
54+
55+
this.__updateEdgeState();
5356

5457
this.subscribeToFilterGroup("workbench");
5558
},
@@ -66,7 +69,7 @@ qx.Class.define("osparc.component.workbench.EdgeUI", {
6669
},
6770

6871
statics: {
69-
getEdgeColor(modified) {
72+
getEdgeColor: function(modified) {
7073
let newColor = null;
7174
if (modified === null) {
7275
newColor = qx.theme.manager.Color.getInstance().resolve("workbench-edge-comp-active");
@@ -75,26 +78,47 @@ qx.Class.define("osparc.component.workbench.EdgeUI", {
7578
}
7679
const colorHex = qx.theme.manager.Color.getInstance().resolve(newColor);
7780
return colorHex;
81+
},
82+
83+
noPortsConnectedText: function(edge) {
84+
return `Connection candidate.<br>Check the ${edge.getOutputNode().getLabel()} inputs`;
7885
}
7986
},
8087

8188
members: {
82-
__updateEdgeColor: function() {
83-
let colorHex = this.self().getEdgeColor(false);
84-
if (this.getEdge().getInputNode()) {
85-
const modified = this.getEdge().getInputNode().getStatus()
86-
.getModified();
87-
colorHex = this.self().getEdgeColor(modified);
88-
}
89+
__updateEdgeState: function() {
90+
const inputNode = this.getEdge().getInputNode();
91+
const portConnected = this.getEdge().isPortConnected();
92+
const modified = inputNode ? inputNode.getStatus().getModified() : false;
93+
94+
// color
95+
const colorHex = this.self().getEdgeColor(modified);
8996
osparc.wrapper.Svg.updateCurveColor(this.getRepresentation(), colorHex);
97+
98+
// shape
99+
osparc.wrapper.Svg.updateCurveDashes(this.getRepresentation(), !portConnected);
100+
101+
// tooltip
102+
const hint = this.getHint();
103+
if (this.getEdge().isPortConnected() === false) {
104+
hint.setText(this.self().noPortsConnectedText(this.getEdge()));
105+
} else if (modified) {
106+
hint.setText("Out-of-date");
107+
} else {
108+
hint.setText(null);
109+
}
110+
},
111+
112+
getHint: function() {
113+
return this.getRepresentation().hint;
90114
},
91115

92116
setSelected: function(selected) {
93117
if (selected) {
94118
const selectedColor = qx.theme.manager.Color.getInstance().resolve("workbench-edge-selected");
95119
osparc.wrapper.Svg.updateCurveColor(this.getRepresentation(), selectedColor);
96120
} else {
97-
this.__updateEdgeColor();
121+
this.__updateEdgeState();
98122
}
99123
},
100124

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -730,25 +730,41 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
730730
const y2 = pointList[1] ? pointList[1][1] : 0;
731731
const edgeRepresentation = this.__svgLayer.drawCurve(x1, y1, x2, y2, !edge.isPortConnected());
732732

733-
edge.addListener("changePortConnected", e => {
734-
const portConnected = e.getData();
735-
osparc.wrapper.Svg.updateCurveDashes(edgeRepresentation, !portConnected);
736-
}, this);
737-
738733
const edgeUI = new osparc.component.workbench.EdgeUI(edge, edgeRepresentation);
739734
this.__edgesUI.push(edgeUI);
740735

736+
const hint = edgeUI.getHint();
741737
const that = this;
742-
edgeUI.getRepresentation().widerCurve.node.addEventListener("click", e => {
743-
// this is needed to get out of the context of svg
744-
that.__selectedItemChanged(edgeUI.getEdgeId()); // eslint-disable-line no-underscore-dangle
745-
e.stopPropagation();
746-
}, this);
747-
edgeUI.getRepresentation().node.addEventListener("click", e => {
748-
// this is needed to get out of the context of svg
749-
that.__selectedItemChanged(edgeUI.getEdgeId()); // eslint-disable-line no-underscore-dangle
750-
e.stopPropagation();
751-
}, this);
738+
[
739+
edgeRepresentation.widerCurve.node,
740+
edgeRepresentation.node
741+
].forEach(svgEl => {
742+
svgEl.addEventListener("click", e => {
743+
// this is needed to get out of the context of svg
744+
that.__selectedItemChanged(edgeUI.getEdgeId()); // eslint-disable-line no-underscore-dangle
745+
e.stopPropagation();
746+
}, this);
747+
748+
const topOffset = 20;
749+
[
750+
"mouseover",
751+
"mousemove"
752+
].forEach(ev => {
753+
svgEl.addEventListener(ev, e => {
754+
const leftOffset = -(parseInt(hint.getHintBounds().width/2));
755+
const properties = {
756+
top: e.clientY + topOffset,
757+
left: e.clientX + leftOffset
758+
};
759+
hint.setLayoutProperties(properties);
760+
if (hint.getText()) {
761+
hint.show();
762+
}
763+
}, this);
764+
});
765+
});
766+
edgeUI.getRepresentation().widerCurve.node.addEventListener("mouseout", () => hint.exclude(), this);
767+
this.__svgLayer.addListener("mouseout", () => hint.exclude(), this);
752768
}
753769
},
754770

services/static-webserver/client/source/class/osparc/ui/hint/Hint.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ qx.Class.define("osparc.ui.hint.Hint", {
127127
}
128128
},
129129

130+
getText: function() {
131+
if (this.__label) {
132+
return this.__label.getValue();
133+
}
134+
return null;
135+
},
136+
130137
setText: function(text) {
131138
if (this.__label) {
132139
this.__label.setValue(text);
@@ -145,7 +152,7 @@ qx.Class.define("osparc.ui.hint.Hint", {
145152
width,
146153
height
147154
} = qx.bom.element.Dimension.getSize(element);
148-
const selfBounds = this.getBounds() || this.getSizeHint();
155+
const selfBounds = this.getHintBounds();
149156
let properties = {};
150157
switch (this.getOrientation()) {
151158
case this.self().orientation.TOP:
@@ -169,6 +176,10 @@ qx.Class.define("osparc.ui.hint.Hint", {
169176
}
170177
},
171178

179+
getHintBounds: function() {
180+
return this.getBounds() || this.getSizeHint();
181+
},
182+
172183
_applyOrientation: function() {
173184
this.__createWidget();
174185
this.__updatePosition();

0 commit comments

Comments
 (0)