@@ -545,7 +545,10 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
545
545
< td >
546
546
< div class ="card-header-mobile ">
547
547
< 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 >
549
552
</ div >
550
553
</ td >
551
554
< template is ="dom-repeat " items ="{{getYearProp('browserInfo')}} " as ="browserInfo ">
@@ -659,10 +662,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
659
662
return {
660
663
year : String ,
661
664
embedded : Boolean ,
662
- stable : {
663
- type : Boolean ,
664
- observer : '_stableChanged' ,
665
- } ,
665
+ stable : Boolean ,
666
666
feature : String ,
667
667
features : {
668
668
type : Array ,
@@ -768,33 +768,50 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
768
768
afterNextRender ( this , this . addSortEvents ) ;
769
769
}
770
770
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
+ ] ;
774
782
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
+ }
784
790
}
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 ] } ` ;
798
815
}
799
816
800
817
// Add the on-click handlers for sorting by a specific table header.
@@ -942,9 +959,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
942
959
return `${ ( score / 10 ) . toFixed ( 1 ) } %` ;
943
960
}
944
961
945
- getInteropScoreForFeature ( feature , isStable ) {
962
+ getInteropScoreForFeature ( feature , stable ) {
946
963
const numBrowsers = this . getYearProp ( 'numBrowsers' ) ;
947
- return this . getBrowserScoreForFeature ( numBrowsers , feature , isStable ) ;
964
+ return this . getBrowserScoreForFeature ( numBrowsers , feature ) ;
948
965
}
949
966
950
967
// getNumericalBrowserScoreByFeature returns the same score as
0 commit comments