Skip to content

Commit ba2eaa7

Browse files
committed
PR Feedback - hoist all graph code to a .vue file
1 parent 0584f5f commit ba2eaa7

File tree

4 files changed

+218
-251
lines changed

4 files changed

+218
-251
lines changed

site/frontend/src/pages/dashboard.ts

Lines changed: 0 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,198 +1,6 @@
1-
import Highcharts from "highcharts";
21
import {createApp} from "vue";
3-
import {DASHBOARD_DATA_URL} from "../urls";
42
import Dashboard from "./dashboard/page.vue";
53
import WithSuspense from "../components/with-suspense.vue";
6-
import {getUrlParams} from "../utils/navigation";
7-
import {getApi} from "../utils/requests";
8-
9-
type ScaleKind = "linear" | "log";
10-
let scale: ScaleKind = "linear";
11-
12-
const buttons = Array.from(
13-
document.querySelectorAll<HTMLInputElement>("#scale-select-form input")
14-
);
15-
16-
buttons.map((button) => {
17-
button.addEventListener("change", () => {
18-
if (button.checked) {
19-
scale = button.value as ScaleKind;
20-
make_data();
21-
}
22-
});
23-
});
24-
25-
interface DashboardCompileBenchmarkCases {
26-
clean_averages: [number];
27-
base_incr_averages: [number];
28-
clean_incr_averages: [number];
29-
println_incr_averages: [number];
30-
}
31-
32-
interface DashboardResponse {
33-
versions: [string];
34-
check: DashboardCompileBenchmarkCases;
35-
debug: DashboardCompileBenchmarkCases;
36-
opt: DashboardCompileBenchmarkCases;
37-
doc: DashboardCompileBenchmarkCases;
38-
runtime: [number];
39-
}
40-
41-
type Profile = "check" | "debug" | "opt" | "doc";
42-
43-
function render(
44-
element: string,
45-
name: Profile,
46-
data: DashboardCompileBenchmarkCases,
47-
versions: [string]
48-
) {
49-
let articles = {check: "a", debug: "a", opt: "an", doc: "a"};
50-
51-
Highcharts.chart({
52-
chart: {
53-
renderTo: element,
54-
zooming: {
55-
type: "xy",
56-
},
57-
type: "line",
58-
},
59-
title: {
60-
text: `Average time for ${articles[name]} ${name} build`,
61-
},
62-
yAxis: {
63-
title: {text: "Seconds"},
64-
min: scale === "linear" ? 0 : undefined,
65-
type: scale === "log" ? "logarithmic" : undefined,
66-
},
67-
xAxis: {
68-
categories: versions,
69-
title: {text: "Version"},
70-
},
71-
series: [
72-
{
73-
type: "line",
74-
name: "full",
75-
animation: false,
76-
data: data.clean_averages,
77-
},
78-
{
79-
type: "line",
80-
name: "incremental full",
81-
animation: false,
82-
data: data.base_incr_averages,
83-
},
84-
{
85-
type: "line",
86-
name: "incremental unchanged",
87-
animation: false,
88-
data: data.clean_incr_averages,
89-
},
90-
{
91-
type: "line",
92-
name: "incremental patched: println",
93-
animation: false,
94-
data: data.println_incr_averages,
95-
},
96-
],
97-
});
98-
}
99-
100-
function renderRuntime(element: string, data: [number], versions: [string]) {
101-
// Remove null and convert nanoseconds to miliseconds
102-
// The null values, which indicate that the runtime data is missing, are only present at the beginning of the array.
103-
const formattedData = data
104-
.filter((data) => data != null)
105-
.map((data) => data / 1_000_000);
106-
const nullCount = data.length - formattedData.length;
107-
108-
Highcharts.chart({
109-
chart: {
110-
renderTo: element,
111-
zooming: {
112-
type: "xy",
113-
},
114-
type: "line",
115-
},
116-
title: {
117-
text: `Average time for a runtime benchmark`,
118-
},
119-
yAxis: {
120-
title: {text: "Miliseconds"},
121-
min: scale === "linear" ? 0 : undefined,
122-
type: scale === "log" ? "logarithmic" : undefined,
123-
},
124-
xAxis: {
125-
categories: versions.slice(nullCount),
126-
title: {text: "Version"},
127-
},
128-
series: [
129-
{
130-
showInLegend: false,
131-
type: "line",
132-
animation: false,
133-
data: formattedData,
134-
},
135-
],
136-
});
137-
}
138-
139-
function populate_data(response: DashboardResponse) {
140-
const data = response;
141-
render("check-average-times", "check", data.check, data.versions);
142-
render("debug-average-times", "debug", data.debug, data.versions);
143-
render("opt-average-times", "opt", data.opt, data.versions);
144-
render("doc-average-times", "doc", data.doc, data.versions);
145-
renderRuntime("runtime-average-times", data.runtime, data.versions);
146-
}
147-
148-
let response: DashboardResponse | null = null;
149-
150-
async function make_data() {
151-
// As we are not really rendering HTML on this page in the traditional VUE
152-
// sense - to handle an error we render and empty chart where the title of
153-
// the chart is the error.
154-
if (!response) {
155-
const urlParams = getUrlParams();
156-
const apiResponse = await getApi(DASHBOARD_DATA_URL, urlParams);
157-
if (apiResponse.ok) {
158-
response = (await apiResponse.json()) as DashboardResponse;
159-
populate_data(response);
160-
} else {
161-
const responseText = await apiResponse.text();
162-
Highcharts.chart({
163-
chart: {
164-
renderTo: "check-average-times",
165-
zooming: {
166-
type: "xy",
167-
},
168-
type: "line",
169-
},
170-
title: {
171-
text: `${responseText}`,
172-
},
173-
yAxis: {
174-
title: {text: "Error"},
175-
min: scale === "linear" ? 0 : undefined,
176-
type: scale === "log" ? "logarithmic" : undefined,
177-
},
178-
xAxis: {
179-
categories: [],
180-
title: {text: "Error"},
181-
},
182-
series: [
183-
{
184-
showInLegend: false,
185-
type: "line",
186-
animation: false,
187-
data: [],
188-
},
189-
],
190-
});
191-
}
192-
}
193-
}
194-
195-
make_data();
1964

1975
const app = createApp(WithSuspense, {
1986
component: Dashboard,

0 commit comments

Comments
 (0)