Skip to content

Commit 1adf48c

Browse files
author
DanielRyanSmith
committed
add color to interop totals in mobile sections
1 parent 03b8367 commit 1adf48c

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

webapp/components/interop-dashboard.js

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,10 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
545545
<td>
546546
<div class="card-header-mobile">
547547
<a href$="[[getTestsURL(rowName, stable)]]">[[getRowInfo(rowName, 'description')]]</a>
548-
<span class="interop-score-mobile">[[getInteropScoreForFeature(rowName, stable)]]</span>
548+
<span
549+
class="interop-score-mobile"
550+
style$="[[_getScoreStyle(rowName, stable)]]"
551+
>[[getInteropScoreForFeature(rowName, stable)]]</span>
549552
</div>
550553
</td>
551554
<template is="dom-repeat" items="{{getYearProp('browserInfo')}}" as="browserInfo">
@@ -659,10 +662,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
659662
return {
660663
year: String,
661664
embedded: Boolean,
662-
stable: {
663-
type: Boolean,
664-
observer: '_stableChanged',
665-
},
665+
stable: Boolean,
666666
feature: String,
667667
features: {
668668
type: Array,
@@ -768,33 +768,50 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
768768
afterNextRender(this, this.addSortEvents);
769769
}
770770

771-
_stableChanged() {
772-
this.updateSummaryScores();
773-
}
771+
calculateColor(score) {
772+
const gradient = [
773+
// Red.
774+
{ scale: 0, color: [250, 0, 0] },
775+
// Orange.
776+
{ scale: 33.33, color: [250, 125, 0] },
777+
// Yellow.
778+
{ scale: 66.67, color: [220, 220, 0] },
779+
// Green.
780+
{ scale: 100, color: [0, 160, 0] },
781+
];
774782

775-
async updateSummaryScores() {
776-
const scoreElements = this.shadowRoot.querySelectorAll('.interop-score-mobile');
777-
const scores = this.stable ? this.scores.stable : this.scores.experimental;
778-
const summaryFeatureName = this.dataManager.getYearProp('summaryFeatureName');
779-
console.log(this.scores);
780-
// If the elements have not rendered yet, don't update the scores.
781-
if ((!this.isMobileScoresView && scoreElements.length !== scores.length) ||
782-
(this.isMobileScoresView && scoreElements.length !== scores.length + 1)) {
783-
return;
783+
let color1, color2;
784+
for (let i = 1; i < gradient.length; i++) {
785+
if (score <= gradient[i].scale) {
786+
color1 = gradient[i - 1];
787+
color2 = gradient[i];
788+
break;
789+
}
784790
}
785-
// // Update interop summary number first.
786-
// this.updateSummaryScore(scoreElements[0], scores[scores.length - 1][summaryFeatureName]);
787-
// // Update the rest of the browser scores.
788-
// for (let i = 1; i < scores.length; i++) {
789-
// this.updateSummaryScore(scoreElements[i], scores[i - 1][summaryFeatureName]);
790-
// }
791-
792-
// // Update investigation summary separately.
793-
// if (this.shouldDisplayInvestigationNumber()) {
794-
// const investigationNumber = this.shadowRoot.querySelector('#investigationNumber');
795-
// this.updateSummaryScore(
796-
// investigationNumber, this.dataManager.getYearProp('investigationTotalScore'));
797-
// }
791+
const colorWeight = ((score - color1.scale) / (color2.scale - color1.scale));
792+
const color = [
793+
Math.round(color1.color[0] * (1 - colorWeight) + color2.color[0] * colorWeight),
794+
Math.round(color1.color[1] * (1 - colorWeight) + color2.color[1] * colorWeight),
795+
Math.round(color1.color[2] * (1 - colorWeight) + color2.color[2] * colorWeight),
796+
];
797+
798+
return [
799+
`rgb(${color[0]}, ${color[1]}, ${color[2]})`,
800+
`rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.15)`,
801+
];
802+
}
803+
804+
/**
805+
* Generates a complete CSS style string for a score badge.
806+
* @param {number} score The numerical score.
807+
* @return {string} A CSS style string.
808+
*/
809+
_getScoreStyle(feature, _stable) {
810+
console.log('getting here?');
811+
const interopIndex = this.dataManager.getYearProp('numBrowsers');
812+
const score = this.getNumericalBrowserScoreByFeature(interopIndex, feature);
813+
const colors = this.calculateColor(score);
814+
return `color: color-mix(in lch, ${colors[0]} 70%, black); background-color: ${colors[1]}`;
798815
}
799816

800817
// Add the on-click handlers for sorting by a specific table header.
@@ -942,9 +959,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
942959
return `${(score / 10).toFixed(1)}%`;
943960
}
944961

945-
getInteropScoreForFeature(feature, isStable) {
962+
getInteropScoreForFeature(feature, stable) {
946963
const numBrowsers = this.getYearProp('numBrowsers');
947-
return this.getBrowserScoreForFeature(numBrowsers, feature, isStable);
964+
return this.getBrowserScoreForFeature(numBrowsers, feature);
948965
}
949966

950967
// getNumericalBrowserScoreByFeature returns the same score as

webapp/components/interop-summary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class InteropSummary extends PolymerElement {
239239
}
240240

241241
const summaryDiv = this.shadowRoot.querySelector('.summary-container');
242-
if (window.innerWidth > 768) {
242+
if (window.innerWidth > 800) {
243243
summaryDiv.style.minHeight = SUMMARY_CONTAINER_MIN_HEIGHTS[this.year] || '470px';
244244
}
245245
// Don't display the interop score for Interop 2021.

0 commit comments

Comments
 (0)