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 16 matching lines...) Expand all Loading... |
27 justScaleTransGraph: false, | 27 justScaleTransGraph: false, |
28 lastKeyDown: -1, | 28 lastKeyDown: -1, |
29 showTypes: false | 29 showTypes: false |
30 }; | 30 }; |
31 | 31 |
32 var selectionHandler = { | 32 var selectionHandler = { |
33 clear: function() { | 33 clear: function() { |
34 broker.clear(selectionHandler); | 34 broker.clear(selectionHandler); |
35 }, | 35 }, |
36 select: function(items, selected) { | 36 select: function(items, selected) { |
37 var ranges = []; | 37 var locations = []; |
38 for (var d of items) { | 38 for (var d of items) { |
39 if (selected) { | 39 if (selected) { |
40 d.classList.add("selected"); | 40 d.classList.add("selected"); |
41 } else { | 41 } else { |
42 d.classList.remove("selected"); | 42 d.classList.remove("selected"); |
43 } | 43 } |
44 var data = d.__data__; | 44 var data = d.__data__; |
45 ranges.push([data.pos, data.pos + 1, data.id]); | 45 locations.push({ pos_start: data.pos, pos_end: data.pos + 1, node_id:
data.id}); |
46 } | 46 } |
47 broker.select(selectionHandler, ranges, selected); | 47 broker.select(selectionHandler, locations, selected); |
48 }, | 48 }, |
49 selectionDifference: function(span1, inclusive1, span2, inclusive2) { | 49 selectionDifference: function(span1, inclusive1, span2, inclusive2) { |
50 // Should not be called | 50 // Should not be called |
51 }, | 51 }, |
52 brokeredSelect: function(ranges, selected) { | 52 brokeredSelect: function(locations, selected) { |
53 var test = [].entries().next(); | 53 var test = [].entries().next(); |
54 var selection = graph.nodes | 54 var selection = graph.nodes |
55 .filter(function(n) { | 55 .filter(function(n) { |
56 var pos = n.pos; | 56 var pos = n.pos; |
57 for (var range of ranges) { | 57 for (var location of locations) { |
58 var start = range[0]; | 58 var start = location.pos_start; |
59 var end = range[1]; | 59 var end = location.pos_end; |
60 var id = range[2]; | 60 var id = location.node_id; |
61 if (end != undefined) { | 61 if (end != undefined) { |
62 if (pos >= start && pos < end) { | 62 if (pos >= start && pos < end) { |
63 return true; | 63 return true; |
64 } | 64 } |
65 } else if (start != undefined) { | 65 } else if (start != undefined) { |
66 if (pos === start) { | 66 if (pos === start) { |
67 return true; | 67 return true; |
68 } | 68 } |
69 } else { | 69 } else { |
70 if (n.id === id) { | 70 if (n.id === id) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 d.x += d3.event.dx; | 233 d.x += d3.event.dx; |
234 d.y += d3.event.dy; | 234 d.y += d3.event.dy; |
235 graph.updateGraphVisibility(); | 235 graph.updateGraphVisibility(); |
236 } | 236 } |
237 | 237 |
238 initializeContent(data, rememberedSelection) { | 238 initializeContent(data, rememberedSelection) { |
239 this.createGraph(data, rememberedSelection); | 239 this.createGraph(data, rememberedSelection); |
240 if (rememberedSelection != null) { | 240 if (rememberedSelection != null) { |
241 this.attachSelection(rememberedSelection); | 241 this.attachSelection(rememberedSelection); |
242 this.connectVisibleSelectedNodes(); | 242 this.connectVisibleSelectedNodes(); |
| 243 this.viewSelection(); |
243 } | 244 } |
244 this.updateGraphVisibility(); | 245 this.updateGraphVisibility(); |
245 } | 246 } |
246 | 247 |
247 deleteContent() { | 248 deleteContent() { |
248 if (this.visibleNodes) { | 249 if (this.visibleNodes) { |
249 this.nodes = []; | 250 this.nodes = []; |
250 this.edges = []; | 251 this.edges = []; |
251 this.nodeMap = []; | 252 this.nodeMap = []; |
252 this.updateGraphVisibility(); | 253 this.updateGraphVisibility(); |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 } | 1011 } |
1011 | 1012 |
1012 viewWholeGraph() { | 1013 viewWholeGraph() { |
1013 var graph = this; | 1014 var graph = this; |
1014 var minScale = graph.minScale(); | 1015 var minScale = graph.minScale(); |
1015 var translation = [0, 0]; | 1016 var translation = [0, 0]; |
1016 translation = graph.getVisibleTranslation(translation, minScale); | 1017 translation = graph.getVisibleTranslation(translation, minScale); |
1017 graph.translateClipped(translation, minScale); | 1018 graph.translateClipped(translation, minScale); |
1018 } | 1019 } |
1019 } | 1020 } |
OLD | NEW |