OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 class GraphView extends View { | 7 class GraphView extends View { |
8 constructor (d3, id, nodes, edges, broker) { | 8 constructor (d3, id, nodes, edges, broker) { |
9 super(id, broker); | 9 super(id, broker); |
10 var graph = this; | 10 var graph = this; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 graph.drag = d3.behavior.drag() | 116 graph.drag = d3.behavior.drag() |
117 .origin(function(d){ | 117 .origin(function(d){ |
118 return {x: d.x, y: d.y}; | 118 return {x: d.x, y: d.y}; |
119 }) | 119 }) |
120 .on("drag", function(args){ | 120 .on("drag", function(args){ |
121 graph.state.justDragged = true; | 121 graph.state.justDragged = true; |
122 graph.dragmove.call(graph, args); | 122 graph.dragmove.call(graph, args); |
123 }) | 123 }) |
124 | 124 |
125 d3.select("#upload").on("click", function(){ | 125 d3.select("#upload").on("click", partial(this.uploadAction, graph)); |
126 document.getElementById("hidden-file-upload").click(); | 126 d3.select("#layout").on("click", partial(this.layoutAction, graph)); |
127 }); | 127 d3.select("#show-all").on("click", partial(this.showAllAction, graph)); |
128 | 128 d3.select("#hide-unselected").on("click", partial(this.hideUnselectedAction,
graph)); |
129 d3.select("#layout").on("click", function(){ | 129 d3.select("#hide-selected").on("click", partial(this.hideSelectedAction, gra
ph)); |
130 graph.updateGraphVisibility(); | 130 d3.select("#zoom-selection").on("click", partial(this.zoomSelectionAction, g
raph)); |
131 graph.layoutGraph(); | 131 d3.select("#toggle-types").on("click", partial(this.toggleTypesAction, graph
)); |
132 graph.updateGraphVisibility(); | 132 d3.select("#search-input").on("keydown", partial(this.searchInputAction, gra
ph)); |
133 graph.viewWholeGraph(); | |
134 }); | |
135 | |
136 d3.select("#show-all").on("click", function(){ | |
137 graph.nodes.filter(function(n) { n.visible = true; }) | |
138 graph.edges.filter(function(e) { e.visible = true; }) | |
139 graph.updateGraphVisibility(); | |
140 graph.viewWholeGraph(); | |
141 }); | |
142 | |
143 d3.select("#hide-unselected").on("click", function() { | |
144 var unselected = graph.visibleNodes.filter(function(n) { | |
145 return !this.classList.contains("selected"); | |
146 }); | |
147 unselected.each(function(n) { | |
148 n.visible = false; | |
149 }); | |
150 graph.updateGraphVisibility(); | |
151 }); | |
152 | |
153 d3.select("#hide-selected").on("click", function() { | |
154 var selected = graph.visibleNodes.filter(function(n) { | |
155 return this.classList.contains("selected"); | |
156 }); | |
157 selected.each(function(n) { | |
158 n.visible = false; | |
159 }); | |
160 graph.state.selection.clear(); | |
161 graph.updateGraphVisibility(); | |
162 }); | |
163 | |
164 d3.select("#zoom-selection").on("click", function() { | |
165 graph.viewSelection(); | |
166 }); | |
167 | |
168 d3.select("#toggle-types").on("click", function() { | |
169 graph.toggleTypes(); | |
170 }); | |
171 | |
172 d3.select("#search-input").on("keydown", function() { | |
173 if (d3.event.keyCode == 13) { | |
174 graph.state.selection.clear(); | |
175 var reg = new RegExp(this.value); | |
176 var filterFunction = function(n) { | |
177 return (reg.exec(n.getDisplayLabel()) != null || | |
178 (graph.state.showTypes && reg.exec(n.getDisplayType())) || | |
179 reg.exec(n.opcode) != null); | |
180 }; | |
181 if (d3.event.ctrlKey) { | |
182 graph.nodes.forEach(function(n, i) { | |
183 if (filterFunction(n)) { | |
184 n.visible = true; | |
185 } | |
186 }); | |
187 graph.updateGraphVisibility(); | |
188 } | |
189 var selected = graph.visibleNodes.each(function(n) { | |
190 if (filterFunction(n)) { | |
191 graph.state.selection.select(this, true); | |
192 } | |
193 }); | |
194 graph.connectVisibleSelectedNodes(); | |
195 graph.updateGraphVisibility(); | |
196 this.blur(); | |
197 graph.viewSelection(); | |
198 } | |
199 d3.event.stopPropagation(); | |
200 }); | |
201 | 133 |
202 // listen for key events | 134 // listen for key events |
203 d3.select(window).on("keydown", function(e){ | 135 d3.select(window).on("keydown", function(e){ |
204 graph.svgKeyDown.call(graph); | 136 graph.svgKeyDown.call(graph); |
205 }) | 137 }) |
206 .on("keyup", function(){ | 138 .on("keyup", function(){ |
207 graph.svgKeyUp.call(graph); | 139 graph.svgKeyUp.call(graph); |
208 }); | 140 }); |
209 svg.on("mousedown", function(d){graph.svgMouseDown.call(graph, d);}); | 141 svg.on("mousedown", function(d){graph.svgMouseDown.call(graph, d);}); |
210 svg.on("mouseup", function(d){graph.svgMouseUp.call(graph, d);}); | 142 svg.on("mouseup", function(d){graph.svgMouseUp.call(graph, d);}); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 453 |
522 selectAllNodes(inEdges, filter) { | 454 selectAllNodes(inEdges, filter) { |
523 var graph = this; | 455 var graph = this; |
524 if (!d3.event.shiftKey) { | 456 if (!d3.event.shiftKey) { |
525 graph.state.selection.clear(); | 457 graph.state.selection.clear(); |
526 } | 458 } |
527 graph.state.selection.select(graph.visibleNodes[0], true); | 459 graph.state.selection.select(graph.visibleNodes[0], true); |
528 graph.updateGraphVisibility(); | 460 graph.updateGraphVisibility(); |
529 } | 461 } |
530 | 462 |
| 463 uploadAction(graph) { |
| 464 document.getElementById("hidden-file-upload").click(); |
| 465 } |
| 466 |
| 467 layoutAction(graph) { |
| 468 graph.updateGraphVisibility(); |
| 469 graph.layoutGraph(); |
| 470 graph.updateGraphVisibility(); |
| 471 graph.viewWholeGraph(); |
| 472 } |
| 473 |
| 474 showAllAction(graph) { |
| 475 graph.nodes.filter(function(n) { n.visible = true; }) |
| 476 graph.edges.filter(function(e) { e.visible = true; }) |
| 477 graph.updateGraphVisibility(); |
| 478 graph.viewWholeGraph(); |
| 479 } |
| 480 |
| 481 hideUnselectedAction(graph) { |
| 482 var unselected = graph.visibleNodes.filter(function(n) { |
| 483 return !this.classList.contains("selected"); |
| 484 }); |
| 485 unselected.each(function(n) { |
| 486 n.visible = false; |
| 487 }); |
| 488 graph.updateGraphVisibility(); |
| 489 } |
| 490 |
| 491 hideSelectedAction(graph) { |
| 492 var selected = graph.visibleNodes.filter(function(n) { |
| 493 return this.classList.contains("selected"); |
| 494 }); |
| 495 selected.each(function(n) { |
| 496 n.visible = false; |
| 497 }); |
| 498 graph.state.selection.clear(); |
| 499 graph.updateGraphVisibility(); |
| 500 } |
| 501 |
| 502 zoomSelectionAction(graph) { |
| 503 graph.viewSelection(); |
| 504 } |
| 505 |
| 506 toggleTypesAction(graph) { |
| 507 graph.toggleTypes(); |
| 508 } |
| 509 |
| 510 searchInputAction(graph) { |
| 511 if (d3.event.keyCode == 13) { |
| 512 graph.state.selection.clear(); |
| 513 var reg = new RegExp(this.value); |
| 514 var filterFunction = function(n) { |
| 515 return (reg.exec(n.getDisplayLabel()) != null || |
| 516 (graph.state.showTypes && reg.exec(n.getDisplayType())) || |
| 517 reg.exec(n.opcode) != null); |
| 518 }; |
| 519 if (d3.event.ctrlKey) { |
| 520 graph.nodes.forEach(function(n, i) { |
| 521 if (filterFunction(n)) { |
| 522 n.visible = true; |
| 523 } |
| 524 }); |
| 525 graph.updateGraphVisibility(); |
| 526 } |
| 527 var selected = graph.visibleNodes.each(function(n) { |
| 528 if (filterFunction(n)) { |
| 529 graph.state.selection.select(this, true); |
| 530 } |
| 531 }); |
| 532 graph.connectVisibleSelectedNodes(); |
| 533 graph.updateGraphVisibility(); |
| 534 this.blur(); |
| 535 graph.viewSelection(); |
| 536 } |
| 537 d3.event.stopPropagation(); |
| 538 } |
| 539 |
531 svgMouseDown() { | 540 svgMouseDown() { |
532 this.state.graphMouseDown = true; | 541 this.state.graphMouseDown = true; |
533 } | 542 } |
534 | 543 |
535 svgMouseUp() { | 544 svgMouseUp() { |
536 var graph = this, | 545 var graph = this, |
537 state = graph.state; | 546 state = graph.state; |
538 if (state.justScaleTransGraph) { | 547 if (state.justScaleTransGraph) { |
539 // Dragged | 548 // Dragged |
540 state.justScaleTransGraph = false; | 549 state.justScaleTransGraph = false; |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 } | 987 } |
979 | 988 |
980 viewWholeGraph() { | 989 viewWholeGraph() { |
981 var graph = this; | 990 var graph = this; |
982 var minScale = graph.minScale(); | 991 var minScale = graph.minScale(); |
983 var translation = [0, 0]; | 992 var translation = [0, 0]; |
984 translation = graph.getVisibleTranslation(translation, minScale); | 993 translation = graph.getVisibleTranslation(translation, minScale); |
985 graph.translateClipped(translation, minScale); | 994 graph.translateClipped(translation, minScale); |
986 } | 995 } |
987 } | 996 } |
OLD | NEW |