-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios.html
142 lines (136 loc) · 4.38 KB
/
ios.html
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
133
134
135
136
137
138
139
140
141
142
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script
type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"
></script>
<meta charset="UTF-8" />
</head>
<body>
<div>
<div style="text-align: center">
<label for="commits">Commits:</label>
<select name="commits" id="commits" onchange="updateChart()">
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="0" selected>ALL</option>
</select>
</div>
<canvas id="myChart"></canvas>
</div>
<script>
let allBundleSizeData;
let myDataChart;
async function renderChart(labels, bundleSizeData) {
const data = {
labels: labels,
datasets: [
{
label: "ios bundle size in bytes",
data: bundleSizeData,
backgroundColor: [
"rgba(255, 99, 132, 0.2)",
"rgba(255, 159, 64, 0.2)",
"rgba(255, 205, 86, 0.2)",
"rgba(75, 192, 192, 0.2)",
"rgba(54, 162, 235, 0.2)",
"rgba(153, 102, 255, 0.2)",
"rgba(201, 203, 207, 0.2)",
],
borderColor: [
"rgb(255, 99, 132)",
"rgb(255, 159, 64)",
"rgb(255, 205, 86)",
"rgb(75, 192, 192)",
"rgb(54, 162, 235)",
"rgb(153, 102, 255)",
"rgb(201, 203, 207)",
],
borderWidth: 1,
},
],
};
const config = {
type: "bar",
data: data,
options: {
onClick: (_, [raw]) => {
const commit = raw?.element?.$context?.raw?.x;
if (commit) {
window.open(
`https://github.com/MetaMask/metamask-mobile/commit/${commit}`,
"_blank"
);
}
},
scales: {
y: {
beginAtZero: true,
},
},
plugins: {
tooltip: {
callbacks: {
label: function (tooltipItems) {
return `Bundle Size: ${
tooltipItems.formattedValue
} Time: ${new Date(
tooltipItems.raw.timestamp
).toLocaleString()}`;
},
},
},
},
},
};
myDataChart = new Chart(document.getElementById("myChart"), config);
}
function loadJS(url, implementationCode, location) {
const scriptTag = document.createElement("script");
scriptTag.src = url;
scriptTag.onload = implementationCode;
location.appendChild(scriptTag);
}
function readBundleSizeData() {
const size = parseInt(document.getElementById("commits").value);
allBundleSizeData = Object.entries(data || {})
.map(([commit, d]) => ({
timestamp: d.timestamp,
x: commit,
y: d.ios,
}))
.sort((a, b) => a.timestamp - b.timestamp);
const bundleSizeData =
size > 0
? allBundleSizeData.slice(allBundleSizeData.length - size)
: allBundleSizeData;
const labels = bundleSizeData.map((name) => name.x);
renderChart(labels, bundleSizeData);
}
function updateChart() {
const size = parseInt(document.getElementById("commits").value);
const bundleSizeData =
size > 0
? allBundleSizeData.slice(allBundleSizeData.length - size)
: allBundleSizeData;
const labels = bundleSizeData.map((name) => name.x);
myDataChart.data.labels = labels;
myDataChart.data.datasets[0].data = bundleSizeData;
myDataChart.update();
}
const basePath = document.location.pathname
.split("/")
.slice(0, -1)
.join("/");
// random timestamp query param to prevent file from being cached
loadJS(
`${basePath}/stats/bundle_size_data.js?timestamp=${Date.now()}`,
readBundleSizeData,
document.head
);
</script>
</body>
</html>