forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterop-feature-chart.js
215 lines (193 loc) · 6.98 KB
/
interop-feature-chart.js
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**
* Copyright 2023 The WPT Dashboard Project. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
import '../node_modules/@polymer/paper-button/paper-button.js';
import '../node_modules/@polymer/paper-dialog/paper-dialog.js';
import '../node_modules/@polymer/paper-input/paper-input.js';
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
// InteropFeatureChart is a wrapper around a Google Charts chart. We cannot
// use the polymer google-chart element as it does not support setting tooltip
// actions, which we rely on to let users load a changelog between subsequent
// versions of the same browser.
class InteropFeatureChart extends PolymerElement {
static get template() {
return html`
<style>
.chart {
/* Reserve vertical space to avoid layout shift. Should be kept in sync
with the JavaScript defined height. */
height: 350px;
margin: 0 auto;
display: flex;
justify-content: center;
}
paper-dialog {
max-width: 600px;
}
</style>
<div id="failuresChart" class="chart"></div>
<paper-dialog with-backdrop id="firefoxNightlyDialog">
<h2>Firefox Nightly Changelogs</h2>
<div>
Nightly builds of Firefox are all given the same sub-version,
<code>0a1</code>, so we cannot automatically determine the changelog.
To find the changelog of a specific Nightly release, locate the
corresponding revision on the
<a href="https://hg.mozilla.org/mozilla-central/firefoxreleases"
target="_blank">release page</a>, enter them below, and click "Go".
<paper-input id="firefoxNightlyDialogFrom" label="From revision"></paper-input>
<paper-input id="firefoxNightlyDialogTo" label="To revision"></paper-input>
</div>
<div class="buttons">
<paper-button dialog-dismiss>Cancel</paper-button>
<paper-button dialog-confirm on-click="clickFirefoxNightlyDialogGoButton">Go</paper-button>
</div>
</paper-dialog>
<paper-dialog with-backdrop id="safariDialog">
<h2>Safari Changelogs</h2>
<template is="dom-if" if="[[stable]]">
<div>
Stable releases of Safari do not publish changelogs, but some insight
may be gained from the
<a href="https://developer.apple.com/documentation/safari-release-notes"
target="_blank">Release Notes</a>.
</div>
</template>
<template is="dom-if" if="[[!stable]]">
<div>
For Safari Technology Preview releases, release notes can be found on
the <a href="https://webkit.org/blog/" target="_blank">WebKit Blog</a>.
Each post usually contains a revision changelog link - look for the
text "This release covers WebKit revisions ...".
</div>
</template>
<div class="buttons">
<paper-button dialog-dismiss>Dismiss</paper-button>
</div>
</paper-dialog>
`;
}
static get properties() {
return {
year: String,
dataManager: Object,
stable: Boolean,
feature: String,
};
}
static get observers() {
return [
'updateChart(feature, stable)'
];
}
static get is() {
return 'interop-feature-chart';
}
ready() {
super.ready();
// Google Charts is not responsive, even if one sets a percentage-width, so
// we add a resize observer to redraw the chart if the size changes.
window.addEventListener('resize', () => {
this.updateChart(this.feature, this.stable);
});
}
getYearProp(prop) {
return this.dataManager.getYearProp(prop);
}
async updateChart(feature, stable) {
// Our observer may be called before the feature is set, so debounce that.
if (!feature) {
return;
}
// Fetching the datatable first ensures that Google Charts has been loaded.
const dataTable = await this.dataManager.getDataTable(feature, stable);
const div = this.$.failuresChart;
const chart = new window.google.visualization.LineChart(div);
chart.draw(dataTable, this.getChartOptions(div, feature));
}
getChromeChangelogUrl(fromVersion, toVersion) {
// Strip off the 'dev' suffix if there.
fromVersion = fromVersion.split(' ')[0];
toVersion = toVersion.split(' ')[0];
return `https://chromium.googlesource.com/chromium/src/+log/${fromVersion}..${toVersion}?pretty=fuller&n=10000`;
}
getFirefoxStableChangelogUrl(fromVersion, toVersion) {
// The version numbers are reported as XX.Y.Z, but pushlog wants
// 'FIREFOX_XX_Y_Z_RELEASE'.
const fromParts = fromVersion.split('.');
const fromRelease = `FIREFOX_${fromParts.join('_')}_RELEASE`;
const toParts = toVersion.split('.');
const toRelease = `FIREFOX_${toParts.join('_')}_RELEASE`;
return `https://hg.mozilla.org/mozilla-unified/pushloghtml?fromchange=${fromRelease}&tochange=${toRelease}`;
}
clickFirefoxNightlyDialogGoButton() {
const fromSha = this.$.firefoxNightlyDialogFrom.value;
const toSha = this.$.firefoxNightlyDialogTo.value;
const url = `https://hg.mozilla.org/mozilla-unified/pushloghtml?fromchange=${fromSha}&tochange=${toSha}`;
window.open(url);
}
getChartOptions(containerDiv, feature) {
// Show only the scores from this year on the charts.
// The max date shown on the X-axis is the end of this year.
const year = parseInt(this.year);
const maxDate = new Date(year + 1, 0, 1);
const ticks = [];
for (let month = 0; month < 12; month++) {
// Show month ticks in the middle of the month on the graph (15th day).
ticks.push(new Date(year, month, 15));
}
const focusAreas = this.getYearProp('focusAreas');
const summaryFeatureName = this.getYearProp('summaryFeatureName');
if (feature !== summaryFeatureName && !(feature in focusAreas)) {
feature = summaryFeatureName;
}
const options = {
height: 350,
fontSize: 14,
tooltip: {
trigger: 'both',
},
hAxis: {
format: 'MMM',
viewWindow: {
max: maxDate
},
ticks: ticks,
slantedText: true,
slantedTextAngle: 90,
showTextEvery: 1,
gridlines: {
count: 13,
}
},
vAxis: {
format: 'percent',
viewWindow: {
min: 0,
max: 1,
}
},
explorer: {
actions: ['dragToZoom', 'rightClickToReset'],
axis: 'horizontal',
keepInBounds: true,
maxZoomIn: 4.0,
},
// Line chart color definitions for [Chrome, Firefox, Safari, Interop].
colors: ['#fbc013', '#fc7a3a', '#148cda', '#2c6f07'],
};
options.width = '100%';
options.legend = {
position: 'top',
alignment: 'center',
};
options.chartArea = {
left: 75,
width: '80%',
};
return options;
}
}
export { InteropFeatureChart };