Skip to content

Commit ba63939

Browse files
author
DanielRyanSmith
committed
changes suggested by @jcscottiii
1 parent 2fb2fe4 commit ba63939

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

webapp/components/interop-dashboard.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
768768
afterNextRender(this, this.addSortEvents);
769769
}
770770

771+
/**
772+
* Generates a font and background color based on a score from 0 to 100.
773+
* The colors are calculated on a gradient from red to green.
774+
*
775+
* @param {number} score - The score, ranging from 0 to 100.
776+
* @returns {[string, string]} An array containing the font color as an RGB
777+
* string and the background color as an RGBA string with 15% opacity.
778+
*/
771779
calculateColor(score) {
772780
const gradient = [
773781
// Red.
@@ -801,16 +809,16 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
801809
];
802810
}
803811

804-
getSubtotalScoreStyle(section, stable) {
812+
getSubtotalScoreStyle(section, isStable) {
805813
const interopIndex = this.dataManager.getYearProp('numBrowsers');
806-
const score = this.getNumericalSubtotalScore(interopIndex, section, stable);
814+
const score = this.getNumericalSubtotalScore(interopIndex, section, isStable);
807815
const colors = this.calculateColor(score);
808816
return `color: color-mix(in lch, ${colors[0]} 70%, black); background-color: ${colors[1]}`;
809817
}
810818

811-
getScoreStyle(feature, stable) {
819+
getScoreStyle(feature, isStable) {
812820
const interopIndex = this.dataManager.getYearProp('numBrowsers');
813-
const score = this.getNumericalBrowserScoreByFeature(interopIndex, feature, stable);
821+
const score = this.getNumericalBrowserScoreByFeature(interopIndex, feature, isStable);
814822
const colors = this.calculateColor(score);
815823
return `color: color-mix(in lch, ${colors[0]} 70%, black); background-color: ${colors[1]}`;
816824
}
@@ -825,10 +833,10 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
825833
return feature === this.feature;
826834
}
827835

828-
featureLinks(feature, stable) {
836+
featureLinks(feature, isStable) {
829837
const data = this.getYearProp('focusAreas')[feature];
830838
const rawURL = (this.isMobileScoresView) ? data?.mobile_tests : data?.tests;
831-
const testsURL = this.formatTestsURL(rawURL, stable);
839+
const testsURL = this.formatTestsURL(rawURL, isStable);
832840

833841
return [
834842
{ text: 'Spec', href: data?.spec },
@@ -846,7 +854,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
846854
}
847855

848856
// Add the stable or experimental label to a tests URL depending on the view.
849-
formatTestsURL(testsURL, stable) {
857+
formatTestsURL(testsURL, isStable) {
850858
// Don't try to add a label if the URL is undefined or empty.
851859
if (!testsURL) {
852860
return '';
@@ -863,7 +871,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
863871
// Remove any existing stable or experimental label param.
864872
const newLabels = existingLabels.filter(val => val !== 'stable' && val !== 'experimental');
865873
// Add the stable/experimental label depending on the dashboard view.
866-
newLabels.push(stable ? 'stable' : 'experimental');
874+
newLabels.push(isStable ? 'stable' : 'experimental');
867875
// Delete the existing label params and re-add them.
868876
url.searchParams.delete('label');
869877
for (const labelValue of newLabels) {
@@ -874,9 +882,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
874882
}
875883

876884
// Get the tests URL for a row and add the stable/experimental label.
877-
getTestsURL(name, stable) {
885+
getTestsURL(name, isStable) {
878886
const urlKey = (this.isMobileScoresView) ? 'mobile_tests' : 'tests';
879-
return this.formatTestsURL(this.getRowInfo(name, urlKey), stable);
887+
return this.formatTestsURL(this.getRowInfo(name, urlKey), isStable);
880888
}
881889

882890
getInvestigationScore(rowName, isPreviousYear) {
@@ -915,17 +923,16 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
915923
return `${(total / 10).toFixed(1)}%`;
916924
}
917925

918-
getNumericalSubtotalScore(browserIndex, section, stable) {
919-
const scores = stable ? this.scores.stable : this.scores.experimental;
926+
getNumericalSubtotalScore(browserIndex, section, isStable) {
927+
const scores = isStable ? this.scores.stable : this.scores.experimental;
920928
const totalScore = section.rows.reduce((sum, rowName) => {
921929
return sum + scores[browserIndex][rowName];
922930
}, 0);
923-
const avg = Math.floor(totalScore / section.rows.length) / 10;
924-
return avg;
931+
return Math.floor(totalScore / section.rows.length) / 10;
925932
}
926933

927-
getSubtotalScore(browserIndex, section, stable) {
928-
const score = this.getNumericalSubtotalScore(browserIndex, section, stable);
934+
getSubtotalScore(browserIndex, section, isStable) {
935+
const score = this.getNumericalSubtotalScore(browserIndex, section, isStable);
929936
// Don't display decimal places for a 100% score.
930937
if (score >= 100) {
931938
return '100%';
@@ -954,8 +961,8 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
954961
return !scoreAsGroup && !this.showBrowserIcons(index);
955962
}
956963

957-
getBrowserScoreForFeature(browserIndex, feature, stable) {
958-
const scores = stable ? this.scores.stable : this.scores.experimental;
964+
getBrowserScoreForFeature(browserIndex, feature, isStable) {
965+
const scores = isStable ? this.scores.stable : this.scores.experimental;
959966
const score = scores[browserIndex][feature];
960967
// Don't display decimal places for a 100% score.
961968
if (score / 10 >= 100) {
@@ -964,15 +971,15 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
964971
return `${(score / 10).toFixed(1)}%`;
965972
}
966973

967-
getInteropScoreForFeature(feature, stable) {
974+
getInteropScoreForFeature(feature, isStable) {
968975
const numBrowsers = this.getYearProp('numBrowsers');
969-
return this.getBrowserScoreForFeature(numBrowsers, feature, stable);
976+
return this.getBrowserScoreForFeature(numBrowsers, feature, isStable);
970977
}
971978

972979
// getNumericalBrowserScoreByFeature returns the same score as
973980
// getBrowserScoreForFeature but as a number instead of a string
974-
getNumericalBrowserScoreByFeature(browserIndex, feature, stable) {
975-
const scores = stable ? this.scores.stable : this.scores.experimental;
981+
getNumericalBrowserScoreByFeature(browserIndex, feature, isStable) {
982+
const scores = isStable ? this.scores.stable : this.scores.experimental;
976983
const score = scores[browserIndex][feature];
977984
const roundedScore = Math.round(score * 100) / 100;
978985
return roundedScore / 10;
@@ -1001,7 +1008,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
10011008
this.totalSafari = this.getBrowserScoreForFeature(2, summaryFeatureName, this.stable);
10021009
}
10031010

1004-
updateUrlParams(embedded, stable, feature, isMobileScoresView) {
1011+
updateUrlParams(embedded, isStable, feature, isMobileScoresView) {
10051012
// Our observer may be called before the feature is set, so debounce that.
10061013
if (feature === undefined) {
10071014
return;
@@ -1011,7 +1018,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
10111018
if (feature && feature !== this.getYearProp('summaryFeatureName')) {
10121019
params.push(`feature=${feature}`);
10131020
}
1014-
if (stable) {
1021+
if (isStable) {
10151022
params.push('stable');
10161023
}
10171024
if (embedded) {
@@ -1075,12 +1082,12 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
10751082
this.toggleMobileView(true, false);
10761083
}
10771084

1078-
toggleMobileView(showMobileScores, stable) {
1085+
toggleMobileView(showMobileScores, isStable) {
10791086
let queryString = '';
10801087
if (showMobileScores) {
10811088
queryString += 'mobile-view';
10821089
}
1083-
if (stable) {
1090+
if (isStable) {
10841091
queryString += (queryString.length) ? '&stable' : 'stable';
10851092
}
10861093
if (queryString.length) {

webapp/components/interop-summary.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ import '../node_modules/@polymer/polymer/lib/elements/dom-if.js';
99
import { html, PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js';
1010
import {afterNextRender} from '../node_modules/@polymer/polymer/lib/utils/render-status.js';
1111

12-
// This min-height is added to this section to ensure that the section below
13-
// is not moved after the user selects between STABLE and EXPERIMENTAL
14-
// (experimental browser names are longer and add additional lines).
15-
// Different years have different initial heights for these sections.
16-
const SUMMARY_CONTAINER_MIN_HEIGHTS = {
17-
'2021': '275px',
18-
'2022': '470px',
19-
'2023': '470px',
20-
'2024': '380px',
21-
'2025': '380px',
22-
};
23-
2412

2513
class InteropSummary extends PolymerElement {
2614
static get template() {
@@ -29,6 +17,9 @@ class InteropSummary extends PolymerElement {
2917
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400&display=swap" rel="stylesheet">
3018
3119
<style>
20+
#interopSummary[data-year="2021"] {
21+
display: none;
22+
}
3223
.summary-number-row {
3324
display: flex;
3425
justify-content: center;
@@ -37,7 +28,7 @@ class InteropSummary extends PolymerElement {
3728
}
3829
3930
.summary-container {
40-
min-height: 470px;
31+
min-height: 380px;
4132
}
4233
4334
.summary-number {
@@ -93,6 +84,15 @@ class InteropSummary extends PolymerElement {
9384
display: none;
9485
}
9586
87+
.summary-container[data-year="2021"] {
88+
min-height: 275px;
89+
}
90+
91+
.summary-container[data-year="2022"],
92+
.summary-container[data-year="2023"] {
93+
min-height: 470px;
94+
}
95+
9696
@media (max-width: 768px) {
9797
.summary-container {
9898
min-height: 340px;
@@ -118,10 +118,10 @@ class InteropSummary extends PolymerElement {
118118
}
119119
}
120120
</style>
121-
<div class="summary-container">
121+
<div class="summary-container" data-year$="[[year]]">
122122
<div class="summary-number-row" id="totalSummaryRow">
123123
<!-- Interop -->
124-
<div id="interopSummary" class="summary-flex-item" tabindex="0">
124+
<div id="interopSummary" class="summary-flex-item" tabindex="0" data-year$="[[year]]">
125125
<div class="summary-number score-number smaller-summary-number">--</div>
126126
<h3 class="summary-title">INTEROP</h3>
127127
</div>
@@ -233,10 +233,6 @@ class InteropSummary extends PolymerElement {
233233
investigationDiv.style.display = 'none';
234234
}
235235

236-
const summaryDiv = this.shadowRoot.querySelector('.summary-container');
237-
if (window.innerWidth > 800) {
238-
summaryDiv.style.minHeight = SUMMARY_CONTAINER_MIN_HEIGHTS[this.year] || '470px';
239-
}
240236
// Don't display the interop score for Interop 2021.
241237
if (this.year === '2021') {
242238
const interopDiv = this.shadowRoot.querySelector('#interopSummary');

0 commit comments

Comments
 (0)