Commit 78baec66 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Fix bugs in 'select origin' graph command

Notry: true
Bug: v8:7327
Change-Id: I440578b6b790f7f5f4cb41147572f32459fb59e5
Reviewed-on: https://chromium-review.googlesource.com/c/1407052
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58781}
parent 84dc3c22
...@@ -31,7 +31,7 @@ interface GraphState { ...@@ -31,7 +31,7 @@ interface GraphState {
export class GraphView extends View implements PhaseView { export class GraphView extends View implements PhaseView {
divElement: d3.Selection<any, any, any, any>; divElement: d3.Selection<any, any, any, any>;
svg: d3.Selection<any, any, any, any>; svg: d3.Selection<any, any, any, any>;
showPhaseByName: (s: string) => void; showPhaseByName: (p: string, s: Set<any>) => void;
state: GraphState; state: GraphState;
selectionHandler: NodeSelectionHandler & ClearableHandler; selectionHandler: NodeSelectionHandler & ClearableHandler;
graphElement: d3.Selection<any, any, any, any>; graphElement: d3.Selection<any, any, any, any>;
...@@ -43,6 +43,7 @@ export class GraphView extends View implements PhaseView { ...@@ -43,6 +43,7 @@ export class GraphView extends View implements PhaseView {
transitionTimout: number; transitionTimout: number;
graph: Graph; graph: Graph;
broker: SelectionBroker; broker: SelectionBroker;
phaseName: string;
createViewElement() { createViewElement() {
const pane = document.createElement('div'); const pane = document.createElement('div');
...@@ -56,6 +57,7 @@ export class GraphView extends View implements PhaseView { ...@@ -56,6 +57,7 @@ export class GraphView extends View implements PhaseView {
this.broker = broker; this.broker = broker;
this.showPhaseByName = showPhaseByName; this.showPhaseByName = showPhaseByName;
this.divElement = d3.select(this.divNode); this.divElement = d3.select(this.divNode);
this.phaseName = "";
const svg = this.divElement.append("svg") const svg = this.divElement.append("svg")
.attr('version', '2.0') .attr('version', '2.0')
.attr("width", "100%") .attr("width", "100%")
...@@ -67,7 +69,7 @@ export class GraphView extends View implements PhaseView { ...@@ -67,7 +69,7 @@ export class GraphView extends View implements PhaseView {
// to be important even if it does nothing. // to be important even if it does nothing.
svg svg
.attr("focusable", false) .attr("focusable", false)
.on("focus", e => {}) .on("focus", e => { })
.on("keydown", e => { view.svgKeyDown(); }); .on("keydown", e => { view.svgKeyDown(); });
view.svg = svg; view.svg = svg;
...@@ -229,7 +231,8 @@ export class GraphView extends View implements PhaseView { ...@@ -229,7 +231,8 @@ export class GraphView extends View implements PhaseView {
d3.select("#hide-selected").on("click", partial(this.hideSelectedAction, this)); d3.select("#hide-selected").on("click", partial(this.hideSelectedAction, this));
d3.select("#zoom-selection").on("click", partial(this.zoomSelectionAction, this)); d3.select("#zoom-selection").on("click", partial(this.zoomSelectionAction, this));
d3.select("#toggle-types").on("click", partial(this.toggleTypesAction, this)); d3.select("#toggle-types").on("click", partial(this.toggleTypesAction, this));
this.createGraph(data, rememberedSelection); this.phaseName = data.name;
this.createGraph(data.data, rememberedSelection);
this.broker.addNodeHandler(this.selectionHandler); this.broker.addNodeHandler(this.selectionHandler);
if (rememberedSelection != null) { if (rememberedSelection != null) {
...@@ -555,21 +558,27 @@ export class GraphView extends View implements PhaseView { ...@@ -555,21 +558,27 @@ export class GraphView extends View implements PhaseView {
selectOrigins() { selectOrigins() {
const state = this.state; const state = this.state;
const origins = []; const origins = [];
let phase = null; let phase = this.phaseName;
const selection = new Set<any>();
for (const n of state.selection) { for (const n of state.selection) {
const origin = n.nodeLabel.origin; const origin = n.nodeLabel.origin;
if (origin) { if (origin) {
const node = this.graph.nodeMap[origin.nodeId];
origins.push(node);
phase = origin.phase; phase = origin.phase;
const node = this.graph.nodeMap[origin.nodeId];
if (phase === this.phaseName && node) {
origins.push(node);
} else {
selection.add(`${origin.nodeId}`);
}
} }
} }
if (origins.length) { // Only go through phase reselection if we actually need
state.selection.clear(); // to display another phase.
state.selection.select(origins, true); if (selection.size > 0 && phase !== this.phaseName) {
if (phase) { this.showPhaseByName(phase, selection);
this.showPhaseByName(phase); } else if (origins.length > 0) {
} this.selectionHandler.clear();
this.selectionHandler.select(origins, true);
} }
} }
......
...@@ -67,7 +67,7 @@ export class GraphMultiView extends View { ...@@ -67,7 +67,7 @@ export class GraphMultiView extends View {
} }
}); });
searchInput.setAttribute("value", window.sessionStorage.getItem("lastSearch") || ""); searchInput.setAttribute("value", window.sessionStorage.getItem("lastSearch") || "");
this.graph = new GraphView(this.divNode, selectionBroker, phaseName => view.displayPhaseByName(phaseName)); this.graph = new GraphView(this.divNode, selectionBroker, view.displayPhaseByName.bind(this));
this.schedule = new ScheduleView(this.divNode, selectionBroker); this.schedule = new ScheduleView(this.divNode, selectionBroker);
this.sequence = new SequenceView(this.divNode, selectionBroker); this.sequence = new SequenceView(this.divNode, selectionBroker);
this.selectMenu = toolbox.querySelector("#display-selector") as HTMLSelectElement; this.selectMenu = toolbox.querySelector("#display-selector") as HTMLSelectElement;
...@@ -86,8 +86,9 @@ export class GraphMultiView extends View { ...@@ -86,8 +86,9 @@ export class GraphMultiView extends View {
view.selectMenu.add(optionElement); view.selectMenu.add(optionElement);
}); });
this.selectMenu.onchange = function (this: HTMLSelectElement) { this.selectMenu.onchange = function (this: HTMLSelectElement) {
window.sessionStorage.setItem("lastSelectedPhase", this.selectedIndex.toString()); const phaseIndex = this.selectedIndex;
view.displayPhase(view.sourceResolver.getPhase(this.selectedIndex)); window.sessionStorage.setItem("lastSelectedPhase", phaseIndex.toString());
view.displayPhase(view.sourceResolver.getPhase(phaseIndex));
}; };
} }
...@@ -102,27 +103,27 @@ export class GraphMultiView extends View { ...@@ -102,27 +103,27 @@ export class GraphMultiView extends View {
initializeContent() { } initializeContent() { }
displayPhase(phase) { displayPhase(phase, selection?: Set<any>) {
if (phase.type == "graph") { if (phase.type == "graph") {
this.displayPhaseView(this.graph, phase.data); this.displayPhaseView(this.graph, phase, selection);
} else if (phase.type == "schedule") { } else if (phase.type == "schedule") {
this.displayPhaseView(this.schedule, phase); this.displayPhaseView(this.schedule, phase, selection);
} else if (phase.type == "sequence") { } else if (phase.type == "sequence") {
this.displayPhaseView(this.sequence, phase); this.displayPhaseView(this.sequence, phase, selection);
} }
} }
displayPhaseView(view, data) { displayPhaseView(view, data, selection?: Set<any>) {
const rememberedSelection = this.hideCurrentPhase(); const rememberedSelection = selection ? selection : this.hideCurrentPhase();
view.show(data, rememberedSelection); view.show(data, rememberedSelection);
this.divNode.classList.toggle("scrollable", view.isScrollable()); this.divNode.classList.toggle("scrollable", view.isScrollable());
this.currentPhaseView = view; this.currentPhaseView = view;
} }
displayPhaseByName(phaseName) { displayPhaseByName(phaseName, selection?: Set<any>) {
const phaseId = this.sourceResolver.getPhaseIdByName(phaseName); const phaseId = this.sourceResolver.getPhaseIdByName(phaseName);
this.selectMenu.selectedIndex = phaseId - 1; this.selectMenu.selectedIndex = phaseId;
this.displayPhase(this.sourceResolver.getPhase(phaseId)); this.displayPhase(this.sourceResolver.getPhase(phaseId), selection);
} }
hideCurrentPhase() { hideCurrentPhase() {
......
...@@ -6,7 +6,7 @@ export class InfoView extends View { ...@@ -6,7 +6,7 @@ export class InfoView extends View {
super(idOrContainer); super(idOrContainer);
} }
initializeContent(data: any, rememberedSelection: Selection): void { initializeContent(data: any, rememberedSelection: Set<any>): void {
fetch("/info-view.html") fetch("/info-view.html")
.then(response => response.text()) .then(response => response.text())
.then(htmlText => this.divNode.innerHTML = htmlText); .then(htmlText => this.divNode.innerHTML = htmlText);
......
...@@ -50,10 +50,7 @@ export class MySelection { ...@@ -50,10 +50,7 @@ export class MySelection {
} }
detachSelection() { detachSelection() {
const result = new Set(); const result = this.selectedKeys();
for (const i of this.selection.keys()) {
result.add(i);
}
this.clear(); this.clear();
return result; return result;
} }
......
...@@ -449,12 +449,12 @@ export class SourceResolver { ...@@ -449,12 +449,12 @@ export class SourceResolver {
this.disassemblyPhase = phase; this.disassemblyPhase = phase;
break; break;
case 'schedule': case 'schedule':
this.phases.push(this.parseSchedule(phase));
this.phaseNames.set(phase.name, this.phases.length); this.phaseNames.set(phase.name, this.phases.length);
this.phases.push(this.parseSchedule(phase));
break; break;
case 'sequence': case 'sequence':
this.phases.push(this.parseSequence(phase));
this.phaseNames.set(phase.name, this.phases.length); this.phaseNames.set(phase.name, this.phases.length);
this.phases.push(this.parseSequence(phase));
break; break;
case 'instructions': case 'instructions':
if (phase.nodeIdToInstructionRange) { if (phase.nodeIdToInstructionRange) {
...@@ -469,11 +469,11 @@ export class SourceResolver { ...@@ -469,11 +469,11 @@ export class SourceResolver {
break; break;
case 'graph': case 'graph':
const graphPhase: GraphPhase = Object.assign(phase, { highestNodeId: 0 }); const graphPhase: GraphPhase = Object.assign(phase, { highestNodeId: 0 });
this.phaseNames.set(graphPhase.name, this.phases.length);
this.phases.push(graphPhase); this.phases.push(graphPhase);
this.recordOrigins(graphPhase); this.recordOrigins(graphPhase);
this.internNodeLabels(graphPhase, nodeLabelMap); this.internNodeLabels(graphPhase, nodeLabelMap);
graphPhase.nodeLabelMap = nodeLabelMap.slice(); graphPhase.nodeLabelMap = nodeLabelMap.slice();
this.phaseNames.set(graphPhase.name, this.phases.length);
break; break;
default: default:
throw "Unsupported phase type"; throw "Unsupported phase type";
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
export abstract class View { export abstract class View {
container: HTMLElement; container: HTMLElement;
divNode: HTMLElement; divNode: HTMLElement;
abstract initializeContent(data: any, rememberedSelection: Selection): void; abstract initializeContent(data: any, rememberedSelection: Set<any>): void;
abstract createViewElement(): HTMLElement; abstract createViewElement(): HTMLElement;
abstract deleteContent(): void; abstract deleteContent(): void;
abstract detachSelection(): Set<string>; abstract detachSelection(): Set<string>;
...@@ -19,7 +19,7 @@ export abstract class View { ...@@ -19,7 +19,7 @@ export abstract class View {
return false; return false;
} }
show(data: any, rememberedSelection: Selection): void { show(data: any, rememberedSelection: Set<any>): void {
this.initializeContent(data, rememberedSelection); this.initializeContent(data, rememberedSelection);
this.container.appendChild(this.divNode); this.container.appendChild(this.divNode);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment