[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: Georg Neis <neis@chromium.org> Cr-Commit-Position: refs/heads/master@{#58781}
This commit is contained in:
parent
84dc3c2234
commit
78baec66ba
@ -31,7 +31,7 @@ interface GraphState {
|
||||
export class GraphView extends View implements PhaseView {
|
||||
divElement: 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;
|
||||
selectionHandler: NodeSelectionHandler & ClearableHandler;
|
||||
graphElement: d3.Selection<any, any, any, any>;
|
||||
@ -43,6 +43,7 @@ export class GraphView extends View implements PhaseView {
|
||||
transitionTimout: number;
|
||||
graph: Graph;
|
||||
broker: SelectionBroker;
|
||||
phaseName: string;
|
||||
|
||||
createViewElement() {
|
||||
const pane = document.createElement('div');
|
||||
@ -56,6 +57,7 @@ export class GraphView extends View implements PhaseView {
|
||||
this.broker = broker;
|
||||
this.showPhaseByName = showPhaseByName;
|
||||
this.divElement = d3.select(this.divNode);
|
||||
this.phaseName = "";
|
||||
const svg = this.divElement.append("svg")
|
||||
.attr('version', '2.0')
|
||||
.attr("width", "100%")
|
||||
@ -67,7 +69,7 @@ export class GraphView extends View implements PhaseView {
|
||||
// to be important even if it does nothing.
|
||||
svg
|
||||
.attr("focusable", false)
|
||||
.on("focus", e => {})
|
||||
.on("focus", e => { })
|
||||
.on("keydown", e => { view.svgKeyDown(); });
|
||||
|
||||
view.svg = svg;
|
||||
@ -229,7 +231,8 @@ export class GraphView extends View implements PhaseView {
|
||||
d3.select("#hide-selected").on("click", partial(this.hideSelectedAction, this));
|
||||
d3.select("#zoom-selection").on("click", partial(this.zoomSelectionAction, 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);
|
||||
|
||||
if (rememberedSelection != null) {
|
||||
@ -555,21 +558,27 @@ export class GraphView extends View implements PhaseView {
|
||||
selectOrigins() {
|
||||
const state = this.state;
|
||||
const origins = [];
|
||||
let phase = null;
|
||||
let phase = this.phaseName;
|
||||
const selection = new Set<any>();
|
||||
for (const n of state.selection) {
|
||||
const origin = n.nodeLabel.origin;
|
||||
if (origin) {
|
||||
const node = this.graph.nodeMap[origin.nodeId];
|
||||
origins.push(node);
|
||||
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) {
|
||||
state.selection.clear();
|
||||
state.selection.select(origins, true);
|
||||
if (phase) {
|
||||
this.showPhaseByName(phase);
|
||||
}
|
||||
// Only go through phase reselection if we actually need
|
||||
// to display another phase.
|
||||
if (selection.size > 0 && phase !== this.phaseName) {
|
||||
this.showPhaseByName(phase, selection);
|
||||
} else if (origins.length > 0) {
|
||||
this.selectionHandler.clear();
|
||||
this.selectionHandler.select(origins, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ export class GraphMultiView extends View {
|
||||
}
|
||||
});
|
||||
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.sequence = new SequenceView(this.divNode, selectionBroker);
|
||||
this.selectMenu = toolbox.querySelector("#display-selector") as HTMLSelectElement;
|
||||
@ -86,8 +86,9 @@ export class GraphMultiView extends View {
|
||||
view.selectMenu.add(optionElement);
|
||||
});
|
||||
this.selectMenu.onchange = function (this: HTMLSelectElement) {
|
||||
window.sessionStorage.setItem("lastSelectedPhase", this.selectedIndex.toString());
|
||||
view.displayPhase(view.sourceResolver.getPhase(this.selectedIndex));
|
||||
const phaseIndex = this.selectedIndex;
|
||||
window.sessionStorage.setItem("lastSelectedPhase", phaseIndex.toString());
|
||||
view.displayPhase(view.sourceResolver.getPhase(phaseIndex));
|
||||
};
|
||||
}
|
||||
|
||||
@ -102,27 +103,27 @@ export class GraphMultiView extends View {
|
||||
|
||||
initializeContent() { }
|
||||
|
||||
displayPhase(phase) {
|
||||
displayPhase(phase, selection?: Set<any>) {
|
||||
if (phase.type == "graph") {
|
||||
this.displayPhaseView(this.graph, phase.data);
|
||||
this.displayPhaseView(this.graph, phase, selection);
|
||||
} else if (phase.type == "schedule") {
|
||||
this.displayPhaseView(this.schedule, phase);
|
||||
this.displayPhaseView(this.schedule, phase, selection);
|
||||
} else if (phase.type == "sequence") {
|
||||
this.displayPhaseView(this.sequence, phase);
|
||||
this.displayPhaseView(this.sequence, phase, selection);
|
||||
}
|
||||
}
|
||||
|
||||
displayPhaseView(view, data) {
|
||||
const rememberedSelection = this.hideCurrentPhase();
|
||||
displayPhaseView(view, data, selection?: Set<any>) {
|
||||
const rememberedSelection = selection ? selection : this.hideCurrentPhase();
|
||||
view.show(data, rememberedSelection);
|
||||
this.divNode.classList.toggle("scrollable", view.isScrollable());
|
||||
this.currentPhaseView = view;
|
||||
}
|
||||
|
||||
displayPhaseByName(phaseName) {
|
||||
displayPhaseByName(phaseName, selection?: Set<any>) {
|
||||
const phaseId = this.sourceResolver.getPhaseIdByName(phaseName);
|
||||
this.selectMenu.selectedIndex = phaseId - 1;
|
||||
this.displayPhase(this.sourceResolver.getPhase(phaseId));
|
||||
this.selectMenu.selectedIndex = phaseId;
|
||||
this.displayPhase(this.sourceResolver.getPhase(phaseId), selection);
|
||||
}
|
||||
|
||||
hideCurrentPhase() {
|
||||
|
@ -6,7 +6,7 @@ export class InfoView extends View {
|
||||
super(idOrContainer);
|
||||
}
|
||||
|
||||
initializeContent(data: any, rememberedSelection: Selection): void {
|
||||
initializeContent(data: any, rememberedSelection: Set<any>): void {
|
||||
fetch("/info-view.html")
|
||||
.then(response => response.text())
|
||||
.then(htmlText => this.divNode.innerHTML = htmlText);
|
||||
|
@ -50,10 +50,7 @@ export class MySelection {
|
||||
}
|
||||
|
||||
detachSelection() {
|
||||
const result = new Set();
|
||||
for (const i of this.selection.keys()) {
|
||||
result.add(i);
|
||||
}
|
||||
const result = this.selectedKeys();
|
||||
this.clear();
|
||||
return result;
|
||||
}
|
||||
|
@ -449,12 +449,12 @@ export class SourceResolver {
|
||||
this.disassemblyPhase = phase;
|
||||
break;
|
||||
case 'schedule':
|
||||
this.phases.push(this.parseSchedule(phase));
|
||||
this.phaseNames.set(phase.name, this.phases.length);
|
||||
this.phases.push(this.parseSchedule(phase));
|
||||
break;
|
||||
case 'sequence':
|
||||
this.phases.push(this.parseSequence(phase));
|
||||
this.phaseNames.set(phase.name, this.phases.length);
|
||||
this.phases.push(this.parseSequence(phase));
|
||||
break;
|
||||
case 'instructions':
|
||||
if (phase.nodeIdToInstructionRange) {
|
||||
@ -469,11 +469,11 @@ export class SourceResolver {
|
||||
break;
|
||||
case 'graph':
|
||||
const graphPhase: GraphPhase = Object.assign(phase, { highestNodeId: 0 });
|
||||
this.phaseNames.set(graphPhase.name, this.phases.length);
|
||||
this.phases.push(graphPhase);
|
||||
this.recordOrigins(graphPhase);
|
||||
this.internNodeLabels(graphPhase, nodeLabelMap);
|
||||
graphPhase.nodeLabelMap = nodeLabelMap.slice();
|
||||
this.phaseNames.set(graphPhase.name, this.phases.length);
|
||||
break;
|
||||
default:
|
||||
throw "Unsupported phase type";
|
||||
|
@ -5,7 +5,7 @@
|
||||
export abstract class View {
|
||||
container: HTMLElement;
|
||||
divNode: HTMLElement;
|
||||
abstract initializeContent(data: any, rememberedSelection: Selection): void;
|
||||
abstract initializeContent(data: any, rememberedSelection: Set<any>): void;
|
||||
abstract createViewElement(): HTMLElement;
|
||||
abstract deleteContent(): void;
|
||||
abstract detachSelection(): Set<string>;
|
||||
@ -19,7 +19,7 @@ export abstract class View {
|
||||
return false;
|
||||
}
|
||||
|
||||
show(data: any, rememberedSelection: Selection): void {
|
||||
show(data: any, rememberedSelection: Set<any>): void {
|
||||
this.initializeContent(data, rememberedSelection);
|
||||
this.container.appendChild(this.divNode);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user