Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(955)

Side by Side Diff: tools/turbolizer/graph-view.js

Issue 2066313002: [turbolizer] Performance improvements for selection in graph & schedule (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/turbolizer/selection.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 242 }
243 243
244 getNodeHeight(graph) { 244 getNodeHeight(graph) {
245 if (this.state.showTypes) { 245 if (this.state.showTypes) {
246 return DEFAULT_NODE_HEIGHT + TYPE_HEIGHT; 246 return DEFAULT_NODE_HEIGHT + TYPE_HEIGHT;
247 } else { 247 } else {
248 return DEFAULT_NODE_HEIGHT; 248 return DEFAULT_NODE_HEIGHT;
249 } 249 }
250 } 250 }
251 251
252 getEdgeFrontier(nodes, inEdges, edgeFilter) {
253 let frontier = new Set();
254 nodes.forEach(function(element) {
255 var edges = inEdges ? element.__data__.inputs : element.__data__.outputs;
256 var edgeNumber = 0;
257 edges.forEach(function(edge) {
258 if (edgeFilter == undefined || edgeFilter(edge, edgeNumber)) {
259 frontier.add(edge);
260 }
261 ++edgeNumber;
262 });
263 });
264 return frontier;
265 }
266
267 getNodeFrontier(nodes, inEdges, edgeFilter) {
268 let graph = this;
269 var frontier = new Set();
270 var newState = true;
271 var edgeFrontier = graph.getEdgeFrontier(nodes, inEdges, edgeFilter);
272 // Control key toggles edges rather than just turning them on
273 if (d3.event.ctrlKey) {
274 edgeFrontier.forEach(function(edge) {
275 if (edge.visible) {
276 newState = false;
277 }
278 });
279 }
280 edgeFrontier.forEach(function(edge) {
281 edge.visible = newState;
282 if (newState) {
283 var node = inEdges ? edge.source : edge.target;
284 node.visible = true;
285 frontier.add(node);
286 }
287 });
288 graph.updateGraphVisibility();
289 if (newState) {
290 return graph.visibleNodes.filter(function(n) {
291 return frontier.has(n);
292 });
293 } else {
294 return undefined;
295 }
296 }
297
252 dragmove(d) { 298 dragmove(d) {
253 var graph = this; 299 var graph = this;
254 d.x += d3.event.dx; 300 d.x += d3.event.dx;
255 d.y += d3.event.dy; 301 d.y += d3.event.dy;
256 graph.updateGraphVisibility(); 302 graph.updateGraphVisibility();
257 } 303 }
258 304
259 initializeContent(data, rememberedSelection) { 305 initializeContent(data, rememberedSelection) {
260 this.createGraph(data, rememberedSelection); 306 this.createGraph(data, rememberedSelection);
261 if (rememberedSelection != null) { 307 if (rememberedSelection != null) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 var selection = graph.state.selection; 517 var selection = graph.state.selection;
472 selection.select(d3.select(this), selected); 518 selection.select(d3.select(this), selected);
473 }); 519 });
474 } 520 }
475 521
476 selectAllNodes(inEdges, filter) { 522 selectAllNodes(inEdges, filter) {
477 var graph = this; 523 var graph = this;
478 if (!d3.event.shiftKey) { 524 if (!d3.event.shiftKey) {
479 graph.state.selection.clear(); 525 graph.state.selection.clear();
480 } 526 }
481 graph.visibleNodes.each(function(n) { 527 graph.state.selection.select(graph.visibleNodes[0], true);
482 graph.state.selection.select(this, true);
483 });
484 graph.updateGraphVisibility(); 528 graph.updateGraphVisibility();
485 } 529 }
486 530
487 svgMouseDown() { 531 svgMouseDown() {
488 this.state.graphMouseDown = true; 532 this.state.graphMouseDown = true;
489 } 533 }
490 534
491 svgMouseUp() { 535 svgMouseUp() {
492 var graph = this, 536 var graph = this,
493 state = graph.state; 537 state = graph.state;
(...skipping 10 matching lines...) Expand all
504 state.graphMouseDown = false; 548 state.graphMouseDown = false;
505 } 549 }
506 550
507 svgKeyDown() { 551 svgKeyDown() {
508 var state = this.state; 552 var state = this.state;
509 var graph = this; 553 var graph = this;
510 554
511 // Don't handle key press repetition 555 // Don't handle key press repetition
512 if(state.lastKeyDown !== -1) return; 556 if(state.lastKeyDown !== -1) return;
513 557
514 var getEdgeFrontier = function(inEdges, edgeFilter) { 558 var showSelectionFrontierNodes = function(inEdges, filter, select) {
515 var frontierSet = new Set(); 559 var frontier = graph.getNodeFrontier(state.selection.selection, inEdges, f ilter);
516 var newState = true;
517 if (d3.event.ctrlKey) {
518 state.selection.selection.forEach(function(element) {
519 var edges = inEdges ? element.__data__.inputs : element.__data__.outpu ts;
520 var edgeNumber = 0;
521 // Control key toggles edges rather than just turning them on
522 edges.forEach(function(i) {
523 if (edgeFilter == undefined || edgeFilter(i, edgeNumber)) {
524 if (i.visible) {
525 newState = false;
526 }
527 }
528 ++edgeNumber;
529 });
530 });
531 }
532 state.selection.selection.forEach(function(element) {
533 var edges = inEdges ? element.__data__.inputs : element.__data__.outputs ;
534 var edgeNumber = 0;
535 edges.forEach(function(i) {
536 if (edgeFilter == undefined || edgeFilter(i, edgeNumber)) {
537 i.visible = newState;
538 if (newState) {
539 var candidate = inEdges ? i.source : i.target;
540 candidate.visible = true;
541 frontierSet.add(candidate);
542 }
543 }
544 ++edgeNumber;
545 });
546 });
547 graph.updateGraphVisibility();
548 if (newState) {
549 return graph.visibleNodes.filter(function(n) {
550 return frontierSet.has(n);
551 });
552 } else {
553 return undefined;
554 }
555 }
556
557 var selectNodesThroughEdges = function(inEdges, filter, reselect) {
558 var frontier = getEdgeFrontier(inEdges, filter);
559 if (frontier != undefined) { 560 if (frontier != undefined) {
560 if (reselect) { 561 if (select) {
561 if (!d3.event.shiftKey) { 562 if (!d3.event.shiftKey) {
562 state.selection.clear(); 563 state.selection.clear();
563 } 564 }
564 frontier.each(function(n) { 565 state.selection.select(frontier[0], true);
565 state.selection.select(this, true);
566 });
567 } 566 }
568 graph.updateGraphVisibility(); 567 graph.updateGraphVisibility();
569 } 568 }
570 allowRepetition = false; 569 allowRepetition = false;
571 } 570 }
572 571
573 var allowRepetition = true; 572 var allowRepetition = true;
574 var eventHandled = true; // unless the below switch defaults 573 var eventHandled = true; // unless the below switch defaults
575 switch(d3.event.keyCode) { 574 switch(d3.event.keyCode) {
576 case 49: 575 case 49:
577 case 50: 576 case 50:
578 case 51: 577 case 51:
579 case 52: 578 case 52:
580 case 53: 579 case 53:
581 case 54: 580 case 54:
582 case 55: 581 case 55:
583 case 56: 582 case 56:
584 case 57: 583 case 57:
585 // '1'-'9' 584 // '1'-'9'
586 selectNodesThroughEdges(true, 585 showSelectionFrontierNodes(true,
587 (edge, index) => { return index == (d3.event.keyCo de - 49); }, 586 (edge, index) => { return index == (d3.event.keyCode - 49); },
588 false); 587 false);
589 break; 588 break;
590 case 67: 589 case 67:
591 // 'c' 590 // 'c'
592 selectNodesThroughEdges(true, 591 showSelectionFrontierNodes(true,
593 (edge, index) => { return edge.type == 'control'; }, 592 (edge, index) => { return edge.type == 'control'; },
594 false); 593 false);
595 break; 594 break;
596 case 69: 595 case 69:
597 // 'e' 596 // 'e'
598 selectNodesThroughEdges(true, 597 showSelectionFrontierNodes(true,
599 (edge, index) => { return edge.type == 'effect'; } , 598 (edge, index) => { return edge.type == 'effect'; },
600 false); 599 false);
601 break; 600 break;
602 case 79: 601 case 79:
603 // 'o' 602 // 'o'
604 selectNodesThroughEdges(false, undefined, false); 603 showSelectionFrontierNodes(false, undefined, false);
605 break; 604 break;
606 case 73: 605 case 73:
607 // 'i' 606 // 'i'
608 selectNodesThroughEdges(true, undefined, false); 607 showSelectionFrontierNodes(true, undefined, false);
609 break; 608 break;
610 case 65: 609 case 65:
611 // 'a' 610 // 'a'
612 graph.selectAllNodes(); 611 graph.selectAllNodes();
613 allowRepetition = false; 612 allowRepetition = false;
614 break; 613 break;
615 case 38: 614 case 38:
616 case 40: { 615 case 40: {
617 selectNodesThroughEdges(d3.event.keyCode == 38, undefined, true); 616 showSelectionFrontierNodes(d3.event.keyCode == 38, undefined, true);
618 break; 617 break;
619 } 618 }
620 default: 619 default:
621 eventHandled = false; 620 eventHandled = false;
622 break; 621 break;
623 } 622 }
624 if (eventHandled) { 623 if (eventHandled) {
625 d3.event.preventDefault(); 624 d3.event.preventDefault();
626 } 625 }
627 if (!allowRepetition) { 626 if (!allowRepetition) {
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 } 978 }
980 979
981 viewWholeGraph() { 980 viewWholeGraph() {
982 var graph = this; 981 var graph = this;
983 var minScale = graph.minScale(); 982 var minScale = graph.minScale();
984 var translation = [0, 0]; 983 var translation = [0, 0];
985 translation = graph.getVisibleTranslation(translation, minScale); 984 translation = graph.getVisibleTranslation(translation, minScale);
986 graph.translateClipped(translation, minScale); 985 graph.translateClipped(translation, minScale);
987 } 986 }
988 } 987 }
OLDNEW
« no previous file with comments | « no previous file | tools/turbolizer/selection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698