Commit 9ce6e39e authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Improve types and fix bugs

- Improve typing by introducing PhaseView interface.
- Recalculate scale extent after resizing.
- Fix null sentinel which should have been undefined.

Bug: v8:7327

Change-Id: I06881ac3f5681cb419b5da9c6b8aa3a6b2652088
Reviewed-on: https://chromium-review.googlesource.com/1090914Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53631}
parent 394d53d1
...@@ -83,7 +83,7 @@ class DisassemblyView extends TextView { ...@@ -83,7 +83,7 @@ class DisassemblyView extends TextView {
}; };
const SOURCE_POSITION_HEADER_STYLE = { const SOURCE_POSITION_HEADER_STYLE = {
css: 'com', css: 'com',
currentSourcePosition: null, currentSourcePosition: undefined,
sourcePosition: function (text) { sourcePosition: function (text) {
let matches = view.SOURCE_POSITION_HEADER_REGEX.exec(text); let matches = view.SOURCE_POSITION_HEADER_REGEX.exec(text);
if (!matches) return undefined; if (!matches) return undefined;
......
...@@ -499,4 +499,5 @@ function redetermineGraphBoundingBox(graph) { ...@@ -499,4 +499,5 @@ function redetermineGraphBoundingBox(graph) {
[graph.maxGraphX+width/2, graph.maxGraphY+height/2] [graph.maxGraphX+width/2, graph.maxGraphY+height/2]
]; ];
graph.panZoom.translateExtent(extent); graph.panZoom.translateExtent(extent);
graph.minScale();
} }
...@@ -18,7 +18,7 @@ interface GraphState { ...@@ -18,7 +18,7 @@ interface GraphState {
hideDead: boolean hideDead: boolean
} }
class GraphView extends View { 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: (string) => void; showPhaseByName: (string) => void;
...@@ -474,7 +474,8 @@ class GraphView extends View { ...@@ -474,7 +474,8 @@ class GraphView extends View {
graph.toggleTypes(); graph.toggleTypes();
} }
searchInputAction(graph, searchBar, e: KeyboardEvent) { searchInputAction(searchBar, e: KeyboardEvent) {
const graph = this;
if (e.keyCode == 13) { if (e.keyCode == 13) {
graph.selectionHandler.clear(); graph.selectionHandler.clear();
var query = searchBar.value; var query = searchBar.value;
...@@ -880,7 +881,7 @@ class GraphView extends View { ...@@ -880,7 +881,7 @@ class GraphView extends View {
return minScale; return minScale;
} }
fitGraphViewToWindow() { onresize() {
const trans = d3.zoomTransform(this.svg.node()); const trans = d3.zoomTransform(this.svg.node());
const ctrans = this.panZoom.constrain()(trans, this.getSvgExtent(), this.panZoom.translateExtent()) const ctrans = this.panZoom.constrain()(trans, this.getSvgExtent(), this.panZoom.translateExtent())
this.panZoom.transform(this.svg, ctrans) this.panZoom.transform(this.svg, ctrans)
......
...@@ -10,7 +10,7 @@ class GraphMultiView extends View { ...@@ -10,7 +10,7 @@ class GraphMultiView extends View {
graph: GraphView; graph: GraphView;
schedule: ScheduleView; schedule: ScheduleView;
selectMenu: HTMLSelectElement; selectMenu: HTMLSelectElement;
currentPhaseView: View; currentPhaseView: View & PhaseView;
createViewElement() { createViewElement() {
const pane = document.createElement('div'); const pane = document.createElement('div');
...@@ -23,10 +23,10 @@ class GraphMultiView extends View { ...@@ -23,10 +23,10 @@ class GraphMultiView extends View {
const view = this; const view = this;
view.sourceResolver = sourceResolver; view.sourceResolver = sourceResolver;
view.selectionBroker = selectionBroker; view.selectionBroker = selectionBroker;
const searchInput = document.getElementById("search-input"); const searchInput = document.getElementById("search-input") as HTMLInputElement;
searchInput.addEventListener("keyup", e => { searchInput.addEventListener("keyup", e => {
if (!view.currentPhaseView) return; if (!view.currentPhaseView) return;
view.currentPhaseView.searchInputAction(this.currentPhaseView, searchInput, e) view.currentPhaseView.searchInputAction(searchInput, e)
}); });
searchInput.setAttribute("value", window.sessionStorage.getItem("lastSearch") || ""); searchInput.setAttribute("value", window.sessionStorage.getItem("lastSearch") || "");
this.graph = new GraphView(id, selectionBroker, this.graph = new GraphView(id, selectionBroker,
...@@ -92,7 +92,7 @@ class GraphMultiView extends View { ...@@ -92,7 +92,7 @@ class GraphMultiView extends View {
} }
onresize() { onresize() {
if (this.graph) this.graph.fitGraphViewToWindow(); if (this.currentPhaseView) this.currentPhaseView.onresize();
} }
deleteContent() { deleteContent() {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"use strict"; "use strict";
class ScheduleView extends TextView { class ScheduleView extends TextView implements PhaseView {
schedule: Schedule; schedule: Schedule;
createViewElement() { createViewElement() {
...@@ -145,7 +145,7 @@ class ScheduleView extends TextView { ...@@ -145,7 +145,7 @@ class ScheduleView extends TextView {
return `${node.id}: ${node.label}(${node.inputs.join(", ")})` return `${node.id}: ${node.label}(${node.inputs.join(", ")})`
} }
searchInputAction(view, searchBar, e) { searchInputAction(searchBar, e) {
e.stopPropagation(); e.stopPropagation();
this.selectionHandler.clear(); this.selectionHandler.clear();
const query = searchBar.value; const query = searchBar.value;
...@@ -161,4 +161,6 @@ class ScheduleView extends TextView { ...@@ -161,4 +161,6 @@ class ScheduleView extends TextView {
} }
this.selectionHandler.select(select, true); this.selectionHandler.select(select, true);
} }
onresize() {}
} }
...@@ -42,7 +42,9 @@ interface Phase { ...@@ -42,7 +42,9 @@ interface Phase {
data: any; data: any;
} }
interface Schedule {} interface Schedule {
nodes: Array<any>;
}
interface NodeOrigin { interface NodeOrigin {
nodeId: number; nodeId: number;
......
...@@ -31,3 +31,8 @@ abstract class View { ...@@ -31,3 +31,8 @@ abstract class View {
this.container.removeChild(this.divNode); this.container.removeChild(this.divNode);
} }
} }
interface PhaseView {
onresize();
searchInputAction(searchInput: HTMLInputElement, e:Event);
}
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