-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathinterop-feature-chart.js
More file actions
286 lines (256 loc) · 9.08 KB
/
Copy pathinterop-feature-chart.js
File metadata and controls
286 lines (256 loc) · 9.08 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
* 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;
}
#customLegend {
display: flex;
flex-wrap: wrap;
justify-content: center;
column-gap: 20px;
padding-bottom: 8px;
}
.legend-item {
display: flex;
align-items: center;
font-size: 14px;
color: #333;
cursor: pointer;
}
.legend-line {
width: 30px;
height: 4px;
border-radius: 2px;
margin-right: 8px;
}
.legend-label {
font-weight: 500;
}
paper-dialog {
max-width: 600px;
}
</style>
<div id="customLegend">
<template is="dom-repeat" items="{{getYearProp('browserInfo')}}" as="browserInfo" index-as="index">
<div class="legend-item" data-index$="[[index]]" on-click="_onLegendItemClick">
<span class="legend-line" style="background-color: [[browserInfo.graphColor]];"></span>
<span class="legend-label">[[browserInfo.tableName]]</span>
</div>
</template>
<div class="legend-item" on-click="_onLegendItemClick">
<span class="legend-line" style="background-color: #123301;"></span>
<span class="legend-label">Interop</span>
</div>
</div>
<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,
chart: {
type: Object,
},
selectedChartIndex: {
type: Number,
value: null,
},
};
}
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);
this.selectedChartIndex = null;
const div = this.$.failuresChart;
this.chart = new window.google.visualization.LineChart(div);
this.chart.draw(dataTable, this.getChartOptions(feature));
}
_onLegendItemClick(e) {
let index = parseInt(e.currentTarget.dataset.index, 10);
// Account for the interop line, since it is not an index in the browsers list.
if (isNaN(index)) {
index = this.getYearProp('browserInfo').length;
}
if (this.selectedChartIndex === index) {
// If the clicked item is already selected, deselect it.
this.selectedChartIndex = null;
this.chart.setSelection([]);
} else {
// Otherwise, select the new item.
this.selectedChartIndex = index;
// Adjust index to ensure we are targeting the correct chart index.
this.chart.setSelection([{ row: null, column: (index + 1) * 2 }]);
}
}
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(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 graphColors = this.getYearProp('browserInfo')
.map(browserInfo => browserInfo.graphColor);
// Add Interop color.
graphColors.push('#123301');
const options = {
height: 350,
width: '100%',
fontSize: 14,
lineWidth: 3,
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,
},
legend: { position: 'none' },
colors: graphColors,
chartArea: {
top: 8,
left: 60,
width: '100%',
height: '80%',
},
};
return options;
}
}
export { InteropFeatureChart };