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