-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathinterop.js
1408 lines (1256 loc) · 48.5 KB
/
interop.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2022 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 { load } from '../node_modules/@google-web-components/google-chart/google-chart-loader.js';
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 '../node_modules/@polymer/polymer/lib/elements/dom-if.js';
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
import { CountUp } from '../node_modules/countup.js/dist/countUp.js';
// InteropDataManager encapsulates the loading of the CSV data that backs
// both the summary scores and graphs shown on the Interop dashboard. It
// fetches the CSV data, processes it into sets of datatables, and then caches
// those tables for later use by the dashboard.
class InteropDataManager {
constructor(year) {
this.year = year;
// The data is loaded when the year data is obtained and the csv is loaded and parsed.
this._dataLoaded = this.fetchYearData()
// The year data is needed for parsing the csv.
.then(async() => {
await load();
return Promise.all([this._loadCsv('stable'), this._loadCsv('experimental')]);
});
}
async fetchYearData() {
// prepare all year-specific info for reference.
const resp = await fetch('/static/interop-data_v2.json');
const paramsByYear = await resp.json();
const yearInfo = paramsByYear[this.year];
const previousYear = String(parseInt(this.year) - 1);
// Calc and save investigation scores.
this.investigationScores = yearInfo.investigation_scores;
this.investigationWeight = yearInfo.investigation_weight;
// If the previous year has an investigation score, save it for later reference.
if (paramsByYear[previousYear]) {
this.previousInvestigationScores = paramsByYear[previousYear].investigation_scores;
}
if (this.previousInvestigationScores) {
this.previousInvestigationTotalScore =
this.#calcInvestigationTotalScore(this.previousInvestigationScores);
}
if (this.investigationScores) {
this.investigationTotalScore =
this.#calcInvestigationTotalScore(this.investigationScores);
}
this.focusAreas = yearInfo.focus_areas;
// Focus areas are iterated through often, so keep a list of all of them.
this.focusAreasList = Object.keys(this.focusAreas);
this.summaryFeatureName = yearInfo.summary_feature_name;
this.csvURL = yearInfo.csv_url;
this.tableSections = yearInfo.table_sections;
// Keep a list of years we have interop data prepared for.
this.validYears = Object.keys(paramsByYear);
}
// Fetches the datatable for the given feature and stable/experimental state.
// This will wait as needed for the underlying CSV data to be loaded and
// processed before returning the datatable.
async getDataTable(feature, stable) {
await this._dataLoaded;
return stable ?
this.stableDatatables.get(feature) :
this.experimentalDatatables.get(feature);
}
// Calculates the investigation score to be displayed in the summary bubble
// and saves it as an instance variable for easy reference.
#calcInvestigationTotalScore(investigationScores) {
if (!investigationScores) {
return undefined;
}
// Get the last listed score for each category and sum them.
const totalScore = investigationScores.reduce((sum, area) => {
if (area.scores_over_time.length > 0) {
return sum + area.scores_over_time[area.scores_over_time.length - 1].score;
}
return sum;
}, 0.0);
return totalScore / investigationScores.length;
}
// Fetches the most recent scores from the datatables for display as summary
// numbers and tables. Scores are represented as an array of objects, where
// the object is a feature->score mapping.
async getMostRecentScores(stable) {
await this._dataLoaded;
// TODO: Don't get the data from the data tables (which are for the graphs)
// but instead extract it separately when parsing the CSV.
const dataTables = stable ? this.stableDatatables : this.experimentalDatatables;
const scores = [{}, {}, {}, {}];
for (const feature of [
this.summaryFeatureName, ...this.focusAreasList]) {
const dataTable = dataTables.get(feature);
// Assumption: The rows are ordered by dates with the most recent entry last.
const lastRowIndex = dataTable.getNumberOfRows() - 1;
// The order of these needs to be in sync with the markup.
scores[0][feature] = dataTable.getValue(lastRowIndex, dataTable.getColumnIndex('Chrome/Edge')) * 1000;
scores[1][feature] = dataTable.getValue(lastRowIndex, dataTable.getColumnIndex('Firefox')) * 1000;
scores[2][feature] = dataTable.getValue(lastRowIndex, dataTable.getColumnIndex('Safari')) * 1000;
scores[3][feature] = dataTable.getValue(lastRowIndex, dataTable.getColumnIndex('Interop')) * 1000;
}
return scores;
}
// Fetches a list of browser versions for stable or experimental. This is a
// helper method for building tooltip actions; the returned list has one
// entry per row in the corresponding datatables.
async getBrowserVersions(stable) {
await this._dataLoaded;
return stable ?
this.stableBrowserVersions :
this.experimentalBrowserVersions;
}
// Loads the unified CSV file for either stable or experimental, and
// processes it into the set of datatables provided by this class. Will
// ultimately set either this.stableDatatables or this.experimentalDatatables
// with a map of {feature name --> datatable}.
async _loadCsv(label) {
const url = this.csvURL.replace('{stable|experimental}', label);
const csvLines = await fetchCsvContents(url);
const features = [this.summaryFeatureName,
...this.focusAreasList];
const dataTables = new Map(features.map(feature => {
const dataTable = new window.google.visualization.DataTable();
dataTable.addColumn('date', 'Date');
dataTable.addColumn('number', 'Chrome/Edge');
dataTable.addColumn({ type: 'string', role: 'tooltip' });
dataTable.addColumn('number', 'Firefox');
dataTable.addColumn({ type: 'string', role: 'tooltip' });
dataTable.addColumn('number', 'Safari');
dataTable.addColumn({ type: 'string', role: 'tooltip' });
dataTable.addColumn('number', 'Interop');
dataTable.addColumn({type: 'string', role: 'tooltip'});
return [feature, dataTable];
}));
// We list Chrome/Edge on the legend, but when creating the tooltip we
// include the version information and so should be clear about which browser
// exactly gave the results.
const tooltipBrowserNames = [
'Chrome',
'Firefox',
'Safari',
'Interop',
];
// We store a lookup table of browser versions to help with the
// 'Show browser changelog' tooltip action.
const browserVersions = [[], [], [], []];
const numFocusAreas = this.focusAreasList.length;
// Extract the label headers in order.
const headers = csvLines[0]
.split(',')
// Ignore the date and browser version.
.slice(2, 2 + numFocusAreas)
// Remove the browser prefix (e.g. chrome-css-grid becomes css-grid).
.map(label => label.slice(label.indexOf('-') + 1));
// Drop the headers to prepare for aggregation.
csvLines.shift();
csvLines.forEach(line => {
// The format is:
// date, [browser-version, browser-feature-a, browser-feature-b, ...]+
const csvValues = line.split(',');
// JavaScript Date objects use 0-indexed months whilst the CSV is
// 1-indexed, so adjust for that.
const dateParts = csvValues[0].split('-').map(x => parseInt(x));
const date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
// Initialize a new row for each feature, with the date column set.
const newRows = new Map(features.map(feature => {
return [feature, [date]];
}));
// Now handle each of the browsers. For each there is a version column,
// then the scores for each of the features.
for (let i = 1; i < csvValues.length; i += (numFocusAreas + 1)) {
const browserIdx = Math.floor(i / (numFocusAreas + 1));
const browserName = tooltipBrowserNames[browserIdx];
const version = csvValues[i];
browserVersions[browserIdx].push(version);
let testScore = 0.0;
headers.forEach((feature, j) => {
let score = 0;
score = parseInt(csvValues[i + 1 + j]);
if (!(score >= 0 && score <= 1000)) {
throw new Error(`Expected score in 0-1000 range, got ${score}`);
}
const tooltip = this.createTooltip(browserName, version, score);
newRows.get(feature).push(score / 1000);
newRows.get(feature).push(tooltip);
// Only aggregate the score to the total score if it's a category that
// counts toward the total browser score.
if (this.focusAreas[feature].countsTowardScore) {
testScore += score;
}
});
// Count up the number of focus areas that count toward the browser score
// to handle averaging.
const numCountedFocusAreas = this.focusAreasList.filter(
k => this.focusAreas[k].countsTowardScore).length;
testScore /= numCountedFocusAreas;
// Handle investigation scoring if applicable.
const [investigationScore, investigationWeight] =
this.#getInvestigationScoreAndWeight(date);
// Factor in the the investigation score and weight as specified.
const summaryScore = Math.floor(testScore * (1 - investigationWeight) +
investigationScore * investigationWeight);
const summaryTooltip = this.createTooltip(browserName, version, summaryScore);
newRows.get(this.summaryFeatureName).push(summaryScore / 1000);
newRows.get(this.summaryFeatureName).push(summaryTooltip);
}
// Push the new rows onto the corresponding datatable.
newRows.forEach((row, feature) => {
dataTables.get(feature).addRow(row);
});
});
// The datatables are now complete, so assign them to the appropriate
// member variable.
if (label === 'stable') {
this.stableDatatables = dataTables;
this.stableBrowserVersions = browserVersions;
} else {
this.experimentalDatatables = dataTables;
this.experimentalBrowserVersions = browserVersions;
}
}
#getInvestigationScoreAndWeight(date) {
if (!this.investigationScores) {
return [0, 0];
}
let totalInvestigationScore = 0;
for (const info of this.investigationScores) {
// Find the investigation score at the given date.
const entry = info.scores_over_time.findLast(
entry => date >= new Date(entry.date));
if (entry) {
totalInvestigationScore += entry.score;
}
}
totalInvestigationScore /= this.investigationScores.length;
return [totalInvestigationScore, this.investigationWeight];
}
createTooltip(browser, version, score) {
// The score is an integer in the range 0-1000, representing a percentage
// with one decimal point.
return `${score / 10}% passing \n${browser} ${version}`;
}
// Data Manager holds all year-specific properties. This method is a generic
// accessor for those properties.
getYearProp(prop) {
if (prop in this) {
return this[prop];
}
return '';
}
}
// InteropDashboard is a custom element that holds the overall interop dashboard.
// The dashboard breaks down into top-level summary scores, a small description,
// graphs per feature, and a table of currently tracked tests.
class InteropDashboard extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
max-width: 1400px;
/* Override wpt.fyi's automatically injected common.css */
margin: 0 auto !important;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
a {
color: #0d5de6;
text-decoration: none;
}
h1, h2 {
text-align: center;
}
.grid-container {
margin: 0 2em;
display: grid;
grid-template-columns: 9fr 11fr;
column-gap: 75px;
grid-template-areas:
"header scores"
"summary scores"
"description scores"
"graph scores"
"bottom-desc scores";
}
.grid-item-header {
grid-area: header;
}
.grid-item-scores {
grid-area: scores;
}
.grid-item-description {
grid-area: description;
}
.grid-item-graph {
grid-area: graph;
}
.grid-item-bottom-desc {
grid-area: bottom-desc;
}
.channel-area {
display: flex;
max-width: fit-content;
margin-inline: auto;
margin-block-start: 25px;
margin-bottom: 35px;
border-radius: 3px;
box-shadow: var(--shadow-elevation-2dp_-_box-shadow);
}
.channel-area > paper-button {
margin: 0;
}
.channel-area > paper-button:first-of-type {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.channel-area > paper-button:last-of-type {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.unselected {
background-color: white;
}
.selected {
background-color: #1D79F2;
color: white;
}
.focus-area-section {
padding: 15px;
}
.focus-area {
font-size: 24px;
text-align: center;
margin-block: 0 10px;
}
.prose {
max-inline-size: 42ch;
margin-inline: auto;
text-align: center;
}
.table-card {
height: 100%;
}
.score-table {
width: 100%;
border-collapse: collapse;
margin-top: 2.5em;
}
.score-table caption {
font-size: 20px;
font-weight: bold;
}
.score-table thead > .section-header {
vertical-align: bottom;
height: 50px;
}
.score-table thead th {
text-align: left;
border-bottom: 3px solid GrayText;
padding-bottom: .25em;
}
.score-table thead th:not(:last-of-type) {
padding-right: .5em;
}
.score-table td {
padding: .125em .5em;
line-height: 28px;
min-width: 6ch;
font-variant-numeric: tabular-nums;
}
.score-table .browser-icons {
display: flex;
justify-content: flex-end;
}
.score-table .single-browser-icon {
padding-right: .5em;
}
.score-table tr > th:first-of-type {
width: 30ch;
}
.score-table tr > :is(td,th):not(:first-of-type) {
text-align: right;
}
.score-table tbody > tr:nth-child(odd) {
background: hsl(0 0% 0% / 5%);
}
.subtotal-row {
border-top: 1px solid GrayText;
background: hsl(0 0% 0% / 5%);
}
.interop-years {
text-align: center;
}
.interop-year-text {
display: inline-block;
padding: 0 5px;
}
#featureSelect {
padding: 0.5rem;
font-size: 16px;
}
#featureReferenceList {
display: flex;
gap: 2ch;
place-content: center;
color: GrayText;
}
.compat-footer {
text-align: center;
place-items: center;
}
@media only screen and (max-width: 1400px) {
.grid-container {
column-gap: 20px;
display: grid;
grid-auto-columns: minmax(auto, 600px);
}
.grid-item-graph {
max-width: 600px;
}
}
@media only screen and (max-width: 1200px) {
.grid-container {
display: block;
}
.grid-item-graph {
max-width: none;
}
.compat-footer {
width: 100%;
transform: none;
}
}
@media only screen and (max-width: 800px) {
.grid-container {
margin: 0 1em;
}
}
/* TODO(danielrsmith): This is a workaround to avoid the text scaling that
* happens for p tags on mobile, but not for any other text (like the focus area table).
* Remove this when deeper mobile functionality has been added. */
p {
text-size-adjust: none;
}
</style>
<div class="grid-container">
<div class="grid-item grid-item-header">
<h1>Interop [[year]] Dashboard</h1>
<div class="channel-area">
<paper-button id="toggleStable" class\$="[[stableButtonClass(stable)]]" on-click="clickStable">Stable</paper-button>
<paper-button id="toggleExperimental" class\$="[[experimentalButtonClass(stable)]]" on-click="clickExperimental">Experimental</paper-button>
</div>
</div>
<div class="grid-item grid-item-summary">
<interop-summary year="[[year]]" data-manager="[[dataManager]]" scores="[[scores]]" stable="[[stable]]"></interop-summary>
</div>
<div class="grid-item grid-item-description">
<p>Interop [[year]] is a cross-browser effort to improve the interoperability of the web —
to reach a state where each technology works exactly the same in every browser.</p>
</div>
<div class="grid-item-bottom-desc">
<div class="extra-description">
<p>This is accomplished by encouraging browsers to precisely match the web standards for
<a href="https://www.w3.org/Style/CSS/Overview.en.html" target="_blank" rel="noreferrer noopener">CSS</a>,
<a href="https://html.spec.whatwg.org/multipage/" target="_blank" rel="noreferrer noopener">HTML</a>,
<a href="https://tc39.es" target="_blank" rel="noreferrer noopener">JS</a>,
<a href="https://www.w3.org/standards/" target="_blank" rel="noreferrer noopener">Web API</a>,
and more. A suite of automated tests evaluate conformance to web standards in 26 Focus Areas.
The results of those tests are listed in the table, linked to the list of specific tests.
The “Interop” column represents the percentage of tests that pass in all browsers, to assess overall interoperability.
</p>
<p>Investigation Projects are group projects chosen by the Interop team to be taken on this year.
They involve doing the work of moving the web standards or web platform tests community
forward regarding a particularly tricky issue. The percentage represents the amount of
progress made towards project goals. Project titles link to Git repos where work is happening.
Read the issues for details.</p>
</div>
<p>Focus Area scores are calculated based on test pass rates. No test
suite is perfect and improvements are always welcome. Please feel free
to contribute improvements to
<a href="https://github.com/web-platform-tests/wpt" target="_blank">WPT</a>
and then
<a href="[[getYearProp('issueURL')]]" target="_blank">file an issue</a>
to request updating the set of tests used for scoring. You're also
welcome to
<a href="https://matrix.to/#/#interop20xx:matrix.org?web-instance%5Belement.io%5D=app.element.io" target="_blank">join
the conversation on Matrix</a>!</p>
</div>
<div class="grid-item grid-item-scores">
<div class="table-card">
<template is="dom-repeat" items="{{getYearProp('tableSections')}}" as="section">
<table class="score-table">
<thead>
<tr class="section-header">
<th>{{section.name}}</th>
<template is="dom-if" if="[[section.score_as_group]]">
<th colspan=4>Group Progress</th>
</template>
<template is="dom-if" if="[[showBrowserIcons(itemsIndex, section.score_as_group)]]">
<th>
<template is="dom-if" if="[[stable]]">
<div class="browser-icons">
<img src="/static/chrome_64x64.png" width="32" alt="Chrome" title="Chrome" />
<img src="/static/edge_64x64.png" width="32" alt="Edge" title="Edge" />
</div>
</template>
<template is="dom-if" if="[[!stable]]">
<div class="browser-icons">
<img src="/static/chrome-dev_64x64.png" width="32" alt="Chrome Dev" title="Chrome Dev" />
<img src="/static/edge-dev_64x64.png" width="32" alt="Edge Dev" title="Edge Dev" />
</div>
</template>
</th>
<th>
<template is="dom-if" if="[[stable]]">
<div class="browser-icons single-browser-icon">
<img src="/static/firefox_64x64.png" width="32" alt="Firefox" title="Firefox" />
</div>
</template>
<template is="dom-if" if="[[!stable]]">
<div class="browser-icons single-browser-icon">
<img src="/static/firefox-nightly_64x64.png" width="32" alt="Firefox Nightly" title="Firefox Nightly" />
</div>
</template>
</th>
<th>
<template is="dom-if" if="[[stable]]">
<div class="browser-icons single-browser-icon">
<img src="/static/safari_64x64.png" width="32" alt="Safari" title="Safari" />
</div>
</template>
<template is="dom-if" if="[[!stable]]">
<div class="browser-icons single-browser-icon">
<img src="/static/safari-preview_64x64.png" width="32" alt="Safari Technology Preview" title="Safari Technology Preview" />
</div>
</template>
</th>
<th>INTEROP</th>
</template>
<template is="dom-if" if="[[showNoOtherColumns(section.score_as_group, itemsIndex)]]">
<th></th>
<th></th>
<th></th>
<th></th>
</template>
</tr>
</thead>
<template is="dom-if" if="[[!section.score_as_group]]">
<tbody>
<template is="dom-repeat" items="{{section.rows}}" as="rowName">
<tr data-feature$="[[rowName]]">
<td>
<a href$="[[getRowInfo(rowName, 'tests')]]">[[getRowInfo(rowName, 'description')]]</a>
</td>
<td>[[getBrowserScoreForFeature(0, rowName, stable)]]</td>
<td>[[getBrowserScoreForFeature(1, rowName, stable)]]</td>
<td>[[getBrowserScoreForFeature(2, rowName, stable)]]</td>
<td>[[getBrowserScoreForFeature(3, rowName, stable)]]</td>
</tr>
</template>
</tbody>
<tfoot>
<tr class="subtotal-row">
<td><strong>TOTAL</strong></td>
<td>[[getSubtotalScore(0, section, stable)]]</td>
<td>[[getSubtotalScore(1, section, stable)]]</td>
<td>[[getSubtotalScore(2, section, stable)]]</td>
<td>[[getSubtotalScore(3, section, stable)]]</td>
</tr>
</tfoot>
</template>
<template is="dom-if" if="[[section.score_as_group]]">
<tbody>
<template is="dom-repeat" items="{{section.rows}}" as="rowName">
<tr>
<td colspan=4>[[rowName]]</td>
<td>[[getInvestigationScore(rowName, section.previous_investigation)]]</td>
</tr>
</template>
</tbody>
<tfoot>
<tr class="subtotal-row">
<td><strong>TOTAL</strong></td>
<td colspan=3></td>
<td>[[getInvestigationScoreSubtotal(section.previous_investigation)]]</td>
</tr>
</tfoot>
</template>
</table>
</template>
</div>
</div>
<div class="grid-item grid-item-graph">
<section class="focus-area-section">
<div class="focus-area">
<select id="featureSelect">
<option value="summary">{{getSummaryOptionText()}}</option>
<template is="dom-repeat" items="{{getYearProp('tableSections')}}" as="section" filter="{{filterGroupSections()}}">
<optgroup label="[[section.name]]">
<template is="dom-repeat" items={{section.rows}} as="focusArea">
<option value$="[[focusArea]]" selected="[[isSelected(focusArea)]]">
[[getRowInfo(focusArea, 'description')]]
</option>
</template>
</optgroup>
</template>
</select>
</div>
<div id="featureReferenceList">
<template is="dom-repeat" items="[[featureLinks(feature)]]">
<template is="dom-if" if="[[item.href]]">
<a href$="[[item.href]]">[[item.text]]</a>
</template>
<template is="dom-if" if="[[!item.href]]">
<span>[[item.text]]</span>
</template>
</template>
</div>
<interop-feature-chart year="[[year]]"
data-manager="[[dataManager]]"
stable="[[stable]]"
feature="{{feature}}">
</interop-feature-chart>
</section>
</div>
</div>
<footer class="compat-footer">
<div class="interop-years">
<div class="interop-year-text">
<p>View by year: </p>
</div>
<template is="dom-repeat" items={{getAllYears()}} as="interopYear">
<div class="interop-year-text">
<a href="interop-[[interopYear]]">[[interopYear]]</a>
</div>
</template>
</div>
</footer>
`;
}
static get is() {
return 'interop-dashboard';
}
static get properties() {
return {
year: String,
embedded: Boolean,
stable: Boolean,
feature: String,
features: {
type: Array,
notify: true
},
dataManager: Object,
scores: Object,
totalChromium: {
type: String,
value: '0%'
},
totalFirefox: {
type: String,
value: '0%'
},
totalSafari: {
type: String,
value: '0%'
},
};
}
static get observers() {
return [
'updateUrlParams(embedded, stable, feature)',
'updateTotals(features, stable)'
];
}
async ready() {
const params = (new URL(document.location)).searchParams;
this.stable = params.get('stable') !== null;
this.dataManager = new InteropDataManager(this.year);
this.scores = {};
this.scores.experimental = await this.dataManager.getMostRecentScores(false);
this.scores.stable = await this.dataManager.getMostRecentScores(true);
this.features = Object.entries(this.getYearProp('focusAreas'))
.map(([id, info]) => Object.assign({ id }, info));
super.ready();
this.embedded = params.get('embedded') !== null;
// The default view of the page is the summary scores graph for
// experimental releases of browsers.
this.feature = params.get('feature') || this.getYearProp('summaryFeatureName');
this.$.featureSelect.value = this.feature;
this.$.featureSelect.addEventListener('change', () => {
this.feature = this.$.featureSelect.value;
});
this.$.toggleStable.setAttribute('aria-pressed', this.stable);
this.$.toggleExperimental.setAttribute('aria-pressed', !this.stable);
// Keep the block-level design for interop 2021-2022
if (this.year !== '2023') {
const gridContainerDiv = this.shadowRoot.querySelector('.grid-container');
gridContainerDiv.style.display = 'block';
gridContainerDiv.style.width = '700px';
gridContainerDiv.style.margin = 'auto';
// 2023 also displays a special description which is not displayed in previous years.
const extraDescriptionDiv = this.shadowRoot.querySelector('.extra-description');
extraDescriptionDiv.style.display = 'none';
}
}
isSelected(feature) {
return feature === this.feature;
}
featureLinks(feature) {
const data = this.getYearProp('focusAreas')[feature];
return [
{ text: 'Spec', href: data?.spec },
{ text: 'MDN', href: data?.mdn },
{ text: 'Tests', href: data?.tests },
];
}
filterGroupSections() {
return (section) => !section.score_as_group;
}
getRowInfo(name, prop) {
return this.getYearProp('focusAreas')[name][prop];
}
getInvestigationScore(rowName, isPreviousYear) {
const yearProp = (isPreviousYear) ? 'previousInvestigationScores' : 'investigationScores';
const scores = this.getYearProp(yearProp);
for (let i = 0; i < scores.length; i++) {
const area = scores[i];
if (area.name === rowName && area.scores_over_time.length > 0) {
const score = area.scores_over_time[area.scores_over_time.length - 1].score;
return `${(score / 10).toFixed(1)}%`;
}
}
return '0.0%';
}
getInvestigationScoreSubtotal(isPreviousYear) {
const yearProp = (isPreviousYear) ? 'previousInvestigationTotalScore' : 'investigationTotalScore';
const total = this.getYearProp(yearProp);
if (!total) {
return '0.0%';
}
return `${(total / 10).toFixed(1)}%`;
}
getSubtotalScore(browserIndex, section, stable) {
const scores = stable ? this.scores.stable : this.scores.experimental;
const totalScore = section.rows.reduce((sum, rowName) => {
return sum + scores[browserIndex][rowName];
}, 0);
const avg = Math.floor(totalScore / section.rows.length) / 10;
// Don't display decimal places for a 100% score.
if (avg >= 100) {
return '100%';
}
return `${avg.toFixed(1)}%`;
}
getSummaryOptionText() {
// Show "Active" in graph summary text if it is the current interop year.
if (parseInt(this.year) === new Date().getFullYear()) {
return 'All Active Focus Areas';
}
return 'All Focus Areas';
}
showBrowserIcons(index, scoreAsGroup) {
return index === 0 || !scoreAsGroup;
}
showNoOtherColumns(scoreAsGroup, index) {
return !scoreAsGroup && !this.showBrowserIcons(index);
}
getBrowserScoreForFeature(browserIndex, feature) {
const scores = this.stable ? this.scores.stable : this.scores.experimental;
const score = scores[browserIndex][feature];
// Don't display decimal places for a 100% score.
if (score / 10 >= 100) {
return '100%';
}
return `${(score / 10).toFixed(1)}%`;
}
getBrowserScoreTotal(browserIndex) {
return this.totals[browserIndex];
}
getAllYears() {
return this.dataManager.getYearProp('validYears').sort();
}
getYearProp(prop) {
return this.dataManager.getYearProp(prop);
}
updateTotals(features) {
if (!features) {
return;
}
const summaryFeatureName = this.getYearProp('summaryFeatureName');
this.totalChromium = this.getBrowserScoreForFeature(0, summaryFeatureName);
this.totalFirefox = this.getBrowserScoreForFeature(1, summaryFeatureName);
this.totalSafari = this.getBrowserScoreForFeature(2, summaryFeatureName);
}
updateUrlParams(embedded, stable, feature) {
// Our observer may be called before the feature is set, so debounce that.
if (feature === undefined) {
return;
}
const params = [];
if (feature && feature !== this.getYearProp('summaryFeatureName')) {
params.push(`feature=${feature}`);
}
if (stable) {
params.push('stable');
}
if (embedded) {
params.push('embedded');
}
let url = location.pathname;
if (params.length) {
url += `?${params.join('&')}`;
}
history.pushState('', '', url);
}
experimentalButtonClass(stable) {
return stable ? 'unselected' : 'selected';
}
stableButtonClass(stable) {
return stable ? 'selected' : 'unselected';
}
clickExperimental() {
if (!this.stable) {
return;
}
this.stable = false;
this.$.toggleStable.setAttribute('aria-pressed', false);
this.$.toggleExperimental.setAttribute('aria-pressed', true);
}
clickStable() {
if (this.stable) {
return;
}
this.stable = true;
this.$.toggleStable.setAttribute('aria-pressed', true);
this.$.toggleExperimental.setAttribute('aria-pressed', false);
}
}
window.customElements.define(InteropDashboard.is, InteropDashboard);
class InteropSummary extends PolymerElement {
static get template() {
return html`
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400&display=swap" rel="stylesheet">
<style>
#summaryNumberRow {
display: flex;
justify-content: center;
gap: 30px;
margin-bottom: 20px;
}
.summary-container {
min-height: 470px;
}
.summary-number {
font-size: 4.5em;
width: 3ch;
height: 3ch;
padding: 10px;
font-family: 'Roboto Mono', monospace;
display: grid;
place-content: center;
aspect-ratio: 1;
border-radius: 50%;
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
}
.summary-browser-name {
text-align: center;
display: flex;
place-content: center;
justify-content: space-around;
gap: 2ch;
}
.summary-title {
margin: 10px 0;
text-align: center;
font-size: 1em;
}
.summary-browser-name > figure {