-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (123 loc) · 3.71 KB
/
script.js
File metadata and controls
132 lines (123 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
document.addEventListener(
"command",
(e) => {
if (e.command === "--expand" || e.command == "--collapse") {
const open = e.command === "--expand";
for (const d of e.target.querySelectorAll("details")) d.open = open;
}
},
true,
);
document.addEventListener(
"toggle",
(e) => {
const root = e.target.closest("table");
const btn = document.querySelector(`button[commandfor='${root.id}']`);
const globalButton = document.querySelector('button[commandfor="results"]');
for (const d of root.querySelectorAll("details")) {
if (!d.open) {
globalButton.textContent = btn.textContent = "Expand all";
globalButton.command = btn.command = "--expand";
return;
}
}
globalButton.textContent = btn.textContent = "Collapse all";
globalButton.command = btn.command = "--collapse";
},
true,
);
function openHash() {
const hash = location.hash.slice(1) || "";
const el = document.getElementById(hash);
const row = el?.closest("tr");
if (!row) return;
const details = row.nextElementSibling?.querySelector("details");
if (details) details.open = true;
el.scrollIntoView();
}
openHash();
window.addEventListener("hashchange", openHash);
// Historical trend chart
(function () {
const el = document.getElementById("pass-rate-chart");
if (!el || typeof ApexCharts === "undefined") return;
const data = window.historyData;
if (!data || data.length < 2) return;
const reversed = [...data].reverse();
const minifierNames = Object.keys(reversed[0].minifiers);
const series = minifierNames.map((name) => ({
name,
data: reversed
.map((entry) => {
const m = entry.minifiers[name];
if (!m || m.total === 0) return null;
return {
x: new Date(entry.date).getTime(),
y: Math.round((m.pass / m.total) * 1000) / 10,
};
})
.filter(Boolean),
}));
const isDark =
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
const chart = new ApexCharts(el, {
series,
chart: {
type: "line",
height: 400,
background: isDark ? "#0f0f0f" : "#ffffff",
zoom: { enabled: true },
toolbar: { show: true },
animations: { enabled: false },
},
stroke: { curve: "straight", width: 2 },
dataLabels: { enabled: false },
xaxis: {
type: "datetime",
title: { text: "Date" },
labels: {
datetimeUTC: false,
},
},
yaxis: {
title: { text: "Pass Rate (%)" },
min: 0,
max: 100,
decimalsInFloat: 1,
},
tooltip: {
shared: true,
intersect: false,
x: { format: "MMM dd, yyyy" },
y: {
formatter(y, { seriesIndex, dataPointIndex, w }) {
if (typeof y !== "number" || isNaN(y)) return y;
const name = w.config.series[seriesIndex].name;
const entry = reversed[dataPointIndex];
const m = entry && entry.minifiers[name];
const extra = m ? ` (${m.pass}/${m.total} v${m.version})` : "";
return y.toFixed(1) + "%" + extra;
},
},
},
legend: { position: "bottom" },
grid: {
borderColor: isDark ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.2)",
},
theme: isDark ? { mode: "dark", palette: "palette4" } : { mode: "light" },
});
chart.render();
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => {
const dark = e.matches;
chart.updateOptions({
chart: { background: dark ? "#0f0f0f" : "#ffffff" },
grid: {
borderColor: dark ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.2)",
},
theme: dark ? { mode: "dark", palette: "palette4" } : { mode: "light" },
});
});
})();