Skip to content

Commit d8e8b8a

Browse files
authored
Merge pull request #1647 from Orange-OpenSource/emphasize-edges
ui: Emphasize edges
2 parents 77598ca + a71bb19 commit d8e8b8a

File tree

3 files changed

+72
-22
lines changed

3 files changed

+72
-22
lines changed

statics/js/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var store = new Vuex.Store({
1212
history: null,
1313
currentNode: null,
1414
currentEdge: null,
15-
emphasizedNodes: [],
15+
emphasizedIDs: [],
1616
highlightedNodes: [],
1717
highlightInprogress: new Map(),
1818
notifications: [],
@@ -96,11 +96,11 @@ var store = new Vuex.Store({
9696
},
9797

9898
emphasize: function(state, id) {
99-
if (state.emphasizedNodes.indexOf(id) < 0) state.emphasizedNodes.push(id);
99+
if (state.emphasizedIDs.indexOf(id) < 0) state.emphasizedIDs.push(id);
100100
},
101101

102102
deemphasize: function(state, id) {
103-
state.emphasizedNodes = state.emphasizedNodes.filter(function(_id) {
103+
state.emphasizedIDs = state.emphasizedIDs.filter(function(_id) {
104104
return id !== _id;
105105
});
106106
},

statics/js/components/graph-layout.js

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ var TopologyGraphLayout = function(vm, selector) {
310310
let id = "arrowhead-"+label;
311311
defsMarker(id, marker_refX, marker_refY, marker_black, marker_arrow);
312312
}
313-
313+
314314
networkpolicyMarker("ingress", "deny", "begin");
315315
networkpolicyMarker("ingress", "deny", "end");
316316
networkpolicyMarker("ingress", "allow", "begin");
@@ -812,7 +812,7 @@ TopologyGraphLayout.prototype = {
812812
}
813813
}
814814

815-
if (node.metadata.Capture && node.metadata.Capture.State === "active" &&
815+
if (node.metadata.Capture && node.metadata.Capture.State === "active" &&
816816
(!node._metadata.Capture || node._metadata.Capture.State !== "active")) {
817817
this.captureStarted(node);
818818
} else if (!node.metadata.Capture && node._metadata.Capture) {
@@ -1518,19 +1518,15 @@ TopologyGraphLayout.prototype = {
15181518
.classed("link-label-alert", function(d) { return d.alert; })
15191519
.text(function(d) { return d.text; });
15201520

1521-
this.linkLabel.each(function(d) {
1521+
enter.each(function(d) {
15221522
self.g.select("#link-" + d.link.id)
15231523
.classed("link-label-active", d.active)
15241524
.classed("link-label-warning", d.warning)
15251525
.classed("link-label-alert", d.alert)
15261526
.style("stroke-dasharray", self.styleStrokeDasharray(d))
15271527
.style("stroke-dashoffset", self.styleStrokeDashoffset(d))
1528-
.style("animation", self.styleAnimation(d))
15291528
.style("stroke", self.styleStroke(d));
15301529
});
1531-
1532-
// force a tick
1533-
this.tick();
15341530
},
15351531

15361532
delLinkLabel: function(link) {
@@ -1656,6 +1652,9 @@ TopologyGraphLayout.prototype = {
16561652
.attr("class", this.linkWrapClass)
16571653
.attr("marker-end", function(d) { return self.arrowhead(d.link); });
16581654

1655+
linkWrapEnter.filter(function(d) { return d._emphasized; })
1656+
.each(this.emphasizeEdge.bind(this));
1657+
16591658
this.linkWrap = linkWrapEnter.merge(this.linkWrap);
16601659

16611660
this.group = this.group.data(this.groups, function(d) { return d.id; });
@@ -1674,7 +1673,7 @@ TopologyGraphLayout.prototype = {
16741673
},
16751674

16761675
highlightLink: function(d) {
1677-
if(d.collapse) return;
1676+
if(d.collapse || d._emphasized) return;
16781677
var t = d3.transition()
16791678
.duration(300)
16801679
.ease(d3.easeLinear);
@@ -1683,7 +1682,7 @@ TopologyGraphLayout.prototype = {
16831682
},
16841683

16851684
unhighlightLink: function(d) {
1686-
if(d.collapse) return;
1685+
if(d.collapse || d._emphasized) return;
16871686
var t = d3.transition()
16881687
.duration(300)
16891688
.ease(d3.easeLinear);
@@ -1724,6 +1723,8 @@ TopologyGraphLayout.prototype = {
17241723
emphasizeNodeID: function(id) {
17251724
var self = this;
17261725

1726+
if (!(id in this.nodes) && !(id in this._nodes)) return;
1727+
17271728
if (id in this.nodes) this.nodes[id]._emphasized = true;
17281729
if (id in this._nodes) this._nodes[id]._emphasized = true;
17291730

@@ -1741,17 +1742,52 @@ TopologyGraphLayout.prototype = {
17411742
.attr("r", function(d) { return self.nodeSize(d) + 8; });
17421743
},
17431744

1744-
deemphasizeNodeID: function(id) {
1745+
emphasizeEdgeID: function(id) {
1746+
var self = this;
1747+
1748+
if (!(id in this.links) && !(id in this._links)) return;
1749+
1750+
if (id in this.links) this.links[id]._emphasized = true;
1751+
if (id in this._links) this._links[id]._emphasized = true;
1752+
1753+
var t = d3.transition()
1754+
.duration(300)
1755+
.ease(d3.easeLinear);
1756+
1757+
this.g.select("#link-wrap-" + id).transition(t).style("stroke", "rgba(25, 251, 104, 0.50)");
1758+
this.g.select("#link-" + id).transition(t).style("stroke-width", 2);
1759+
},
1760+
1761+
emphasizeID: function(id) {
1762+
this.emphasizeNodeID(id);
1763+
this.emphasizeEdgeID(id);
1764+
},
1765+
1766+
deemphasizeID: function(id) {
17451767
if (id in this.nodes) this.nodes[id]._emphasized = false;
17461768
if (id in this._nodes) this._nodes[id]._emphasized = false;
17471769

1770+
if (id in this.links) this.links[id]._emphasized = false;
1771+
if (id in this._links) this._links[id]._emphasized = false;
1772+
17481773
this.g.select("#node-emphasize-" + id).remove();
1774+
1775+
var t = d3.transition()
1776+
.duration(300)
1777+
.ease(d3.easeLinear);
1778+
1779+
this.g.select("#link-wrap-" + id).transition(t).style("stroke", null);
1780+
this.g.select("#link-" + id).transition(t).style("stroke-width", null);
17491781
},
17501782

17511783
emphasizeNode: function(d) {
17521784
this.emphasizeNodeID(d.id);
17531785
},
17541786

1787+
emphasizeEdge: function(d) {
1788+
this.emphasizeEdgeID(d.id);
1789+
},
1790+
17551791
nodeClass: function(d) {
17561792
var clazz = "node " + d.metadata.Type;
17571793

statics/js/components/topology.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ var TopologyComponent = {
297297
var emphasizeWatcher = {
298298
onEdgeAdded: this.emphasize,
299299
onNodeAdded: this.emphasize,
300+
onEdgeDeleted: this.emphasize
300301
};
301302
this.graph.addHandler(emphasizeWatcher);
302303

@@ -325,9 +326,9 @@ var TopologyComponent = {
325326
else if (mutation.type === "unhighlight")
326327
self.layout.unhighlightNodeID(mutation.payload);
327328
else if (mutation.type === "emphasize")
328-
self.layout.emphasizeNodeID(mutation.payload);
329+
self.layout.emphasizeID(mutation.payload);
329330
else if (mutation.type === "deemphasize")
330-
self.layout.deemphasizeNodeID(mutation.payload);
331+
self.layout.deemphasizeID(mutation.payload);
331332
});
332333

333334
this.setGremlinFavoritesFromConfig();
@@ -439,7 +440,7 @@ var TopologyComponent = {
439440
if (!this.currentNodeMetadata || !this.currentNode.metadata.K8s || !this.currentNode.metadata.K8s.Extra) return null;
440441
return this.currentNode.metadata.K8s.Extra;
441442
},
442-
443+
443444
currentNodeFeatures: function() {
444445
if (!this.currentNodeMetadata || !this.currentNode.metadata.Features) return null;
445446
return this.currentNode.metadata.Features;
@@ -779,28 +780,41 @@ var TopologyComponent = {
779780
this.isTopologyOptionsVisible = false;
780781
},
781782

782-
emphasizeNodes: function(gremlinExpr) {
783+
emphasizeSubgraph: function(gremlinExpr) {
783784
var self = this;
784785
var i;
785786

786787
this.$topologyQuery(gremlinExpr)
787788
.then(function(data) {
788789
data.forEach(function(sg) {
790+
// nodes
789791
for (i in sg.Nodes) {
790792
self.$store.commit('emphasize', sg.Nodes[i].ID);
791793
}
792794

795+
// edges
796+
for (i in sg.Edges) {
797+
self.$store.commit('emphasize', sg.Edges[i].ID);
798+
}
799+
793800
var toDel = [];
794-
for (i in self.$store.state.emphasizedNodes) {
801+
802+
for (i in self.$store.state.emphasizedIDs) {
795803
var found = false;
796804
for (var j in sg.Nodes) {
797-
if (self.$store.state.emphasizedNodes[i] === sg.Nodes[j].ID) {
805+
if (self.$store.state.emphasizedIDs[i] === sg.Nodes[j].ID) {
806+
found = true;
807+
break;
808+
}
809+
}
810+
for (var j in sg.Edges) {
811+
if (self.$store.state.emphasizedIDs[i] === sg.Edges[j].ID) {
798812
found = true;
799813
break;
800814
}
801815
}
802816
if (!found) {
803-
toDel.push(self.$store.state.emphasizedNodes[i]);
817+
toDel.push(self.$store.state.emphasizedIDs[i]);
804818
}
805819
}
806820

@@ -819,9 +833,9 @@ var TopologyComponent = {
819833
}
820834

821835
var newGremlinExpr = expr + ".SubGraph()";
822-
this.emphasizeNodes(newGremlinExpr);
836+
this.emphasizeSubgraph(newGremlinExpr);
823837
} else {
824-
var ids = this.$store.state.emphasizedNodes.slice();
838+
var ids = this.$store.state.emphasizedIDs.slice();
825839
for (var i in ids) {
826840
this.$store.commit('deemphasize', ids[i]);
827841
}

0 commit comments

Comments
 (0)