lib/society/formatter/report/templates/components/society-assets/society.js in society-1.5.2 vs lib/society/formatter/report/templates/components/society-assets/society.js in society-1.6

- old
+ new

@@ -49,19 +49,24 @@ .attr('height', this.diameter) .append('g') .attr('transform', 'translate(' + this.radius + ',' + this.radius + ')'); this.linkAnchor = this.svg.append('g'); this.nodeAnchor = this.svg.append('g'); + $("#class-names").on('keydown', this.toggleFilteredNodes.bind(this)); this.render(); d3.select(self.frameElement).style('height', this.diameter + 'px'); }; NetworkGraph.prototype.toggleIsolatedNodes = function() { this.includeIsolatedNodes = !this.includeIsolatedNodes; this.render(); }; + NetworkGraph.prototype.toggleFilteredNodes = function () { + this.render(); + }; + NetworkGraph.prototype.hideIsolatedNodes = function() { this.includeIsolatedNodes = false; this.render(); }; @@ -70,13 +75,13 @@ this.render(); }; NetworkGraph.prototype.getData = function() { if (this.includeIsolatedNodes) { - return this.data; + return filterByAutocomplete(this.data); } else { - return filterIsolatedNodes(this.data); + return filterByAutocomplete(filterIsolatedNodes(this.data)); } }; NetworkGraph.prototype.render = function() { var nodeAnchor = this.nodeAnchor; @@ -231,9 +236,48 @@ }); return map[""]; }; + function filterByAutocomplete(data) { + filter = $('#class-names').val() + if (filter === "") { + return data; + }; + + var json = data.slice(); + var filtered = []; + var names = json.map(function(klass) { + return klass.name; + }); + + json.forEach(function(klass) { + klass.relations.forEach(function(edge) { + if (klass.name === edge) return; + json[names.indexOf(edge)]._HAS_INCOMING_ = true; + }); + }); + + json.forEach(function(klass) { + var re = new RegExp(filter, "i"); + if (klass.name.search(re) !== -1) { + filtered.push(klass); + klass.relations.forEach(function(edge) { + filtered.push( + { + "name": edge, + "relations": [ klass.name ] + } + ); + }); + }; + }); + if (filtered.length > 0) { + return filtered; + } else { + return data; + } + }; function filterIsolatedNodes(data) { var json = data.slice(); var filtered = []; var names = json.map(function(klass) {