@@ -768,6 +768,14 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
768
768
afterNextRender ( this , this . addSortEvents ) ;
769
769
}
770
770
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
+ */
771
779
calculateColor ( score ) {
772
780
const gradient = [
773
781
// Red.
@@ -801,16 +809,16 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
801
809
] ;
802
810
}
803
811
804
- getSubtotalScoreStyle ( section , stable ) {
812
+ getSubtotalScoreStyle ( section , isStable ) {
805
813
const interopIndex = this . dataManager . getYearProp ( 'numBrowsers' ) ;
806
- const score = this . getNumericalSubtotalScore ( interopIndex , section , stable ) ;
814
+ const score = this . getNumericalSubtotalScore ( interopIndex , section , isStable ) ;
807
815
const colors = this . calculateColor ( score ) ;
808
816
return `color: color-mix(in lch, ${ colors [ 0 ] } 70%, black); background-color: ${ colors [ 1 ] } ` ;
809
817
}
810
818
811
- getScoreStyle ( feature , stable ) {
819
+ getScoreStyle ( feature , isStable ) {
812
820
const interopIndex = this . dataManager . getYearProp ( 'numBrowsers' ) ;
813
- const score = this . getNumericalBrowserScoreByFeature ( interopIndex , feature , stable ) ;
821
+ const score = this . getNumericalBrowserScoreByFeature ( interopIndex , feature , isStable ) ;
814
822
const colors = this . calculateColor ( score ) ;
815
823
return `color: color-mix(in lch, ${ colors [ 0 ] } 70%, black); background-color: ${ colors [ 1 ] } ` ;
816
824
}
@@ -825,10 +833,10 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
825
833
return feature === this . feature ;
826
834
}
827
835
828
- featureLinks ( feature , stable ) {
836
+ featureLinks ( feature , isStable ) {
829
837
const data = this . getYearProp ( 'focusAreas' ) [ feature ] ;
830
838
const rawURL = ( this . isMobileScoresView ) ? data ?. mobile_tests : data ?. tests ;
831
- const testsURL = this . formatTestsURL ( rawURL , stable ) ;
839
+ const testsURL = this . formatTestsURL ( rawURL , isStable ) ;
832
840
833
841
return [
834
842
{ text : 'Spec' , href : data ?. spec } ,
@@ -846,7 +854,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
846
854
}
847
855
848
856
// Add the stable or experimental label to a tests URL depending on the view.
849
- formatTestsURL ( testsURL , stable ) {
857
+ formatTestsURL ( testsURL , isStable ) {
850
858
// Don't try to add a label if the URL is undefined or empty.
851
859
if ( ! testsURL ) {
852
860
return '' ;
@@ -863,7 +871,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
863
871
// Remove any existing stable or experimental label param.
864
872
const newLabels = existingLabels . filter ( val => val !== 'stable' && val !== 'experimental' ) ;
865
873
// Add the stable/experimental label depending on the dashboard view.
866
- newLabels . push ( stable ? 'stable' : 'experimental' ) ;
874
+ newLabels . push ( isStable ? 'stable' : 'experimental' ) ;
867
875
// Delete the existing label params and re-add them.
868
876
url . searchParams . delete ( 'label' ) ;
869
877
for ( const labelValue of newLabels ) {
@@ -874,9 +882,9 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
874
882
}
875
883
876
884
// Get the tests URL for a row and add the stable/experimental label.
877
- getTestsURL ( name , stable ) {
885
+ getTestsURL ( name , isStable ) {
878
886
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 ) ;
880
888
}
881
889
882
890
getInvestigationScore ( rowName , isPreviousYear ) {
@@ -915,17 +923,16 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
915
923
return `${ ( total / 10 ) . toFixed ( 1 ) } %` ;
916
924
}
917
925
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 ;
920
928
const totalScore = section . rows . reduce ( ( sum , rowName ) => {
921
929
return sum + scores [ browserIndex ] [ rowName ] ;
922
930
} , 0 ) ;
923
- const avg = Math . floor ( totalScore / section . rows . length ) / 10 ;
924
- return avg ;
931
+ return Math . floor ( totalScore / section . rows . length ) / 10 ;
925
932
}
926
933
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 ) ;
929
936
// Don't display decimal places for a 100% score.
930
937
if ( score >= 100 ) {
931
938
return '100%' ;
@@ -954,8 +961,8 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
954
961
return ! scoreAsGroup && ! this . showBrowserIcons ( index ) ;
955
962
}
956
963
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 ;
959
966
const score = scores [ browserIndex ] [ feature ] ;
960
967
// Don't display decimal places for a 100% score.
961
968
if ( score / 10 >= 100 ) {
@@ -964,15 +971,15 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
964
971
return `${ ( score / 10 ) . toFixed ( 1 ) } %` ;
965
972
}
966
973
967
- getInteropScoreForFeature ( feature , stable ) {
974
+ getInteropScoreForFeature ( feature , isStable ) {
968
975
const numBrowsers = this . getYearProp ( 'numBrowsers' ) ;
969
- return this . getBrowserScoreForFeature ( numBrowsers , feature , stable ) ;
976
+ return this . getBrowserScoreForFeature ( numBrowsers , feature , isStable ) ;
970
977
}
971
978
972
979
// getNumericalBrowserScoreByFeature returns the same score as
973
980
// 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 ;
976
983
const score = scores [ browserIndex ] [ feature ] ;
977
984
const roundedScore = Math . round ( score * 100 ) / 100 ;
978
985
return roundedScore / 10 ;
@@ -1001,7 +1008,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
1001
1008
this . totalSafari = this . getBrowserScoreForFeature ( 2 , summaryFeatureName , this . stable ) ;
1002
1009
}
1003
1010
1004
- updateUrlParams ( embedded , stable , feature , isMobileScoresView ) {
1011
+ updateUrlParams ( embedded , isStable , feature , isMobileScoresView ) {
1005
1012
// Our observer may be called before the feature is set, so debounce that.
1006
1013
if ( feature === undefined ) {
1007
1014
return ;
@@ -1011,7 +1018,7 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
1011
1018
if ( feature && feature !== this . getYearProp ( 'summaryFeatureName' ) ) {
1012
1019
params . push ( `feature=${ feature } ` ) ;
1013
1020
}
1014
- if ( stable ) {
1021
+ if ( isStable ) {
1015
1022
params . push ( 'stable' ) ;
1016
1023
}
1017
1024
if ( embedded ) {
@@ -1075,12 +1082,12 @@ class InteropDashboard extends WPTFlags(PolymerElement) {
1075
1082
this . toggleMobileView ( true , false ) ;
1076
1083
}
1077
1084
1078
- toggleMobileView ( showMobileScores , stable ) {
1085
+ toggleMobileView ( showMobileScores , isStable ) {
1079
1086
let queryString = '' ;
1080
1087
if ( showMobileScores ) {
1081
1088
queryString += 'mobile-view' ;
1082
1089
}
1083
- if ( stable ) {
1090
+ if ( isStable ) {
1084
1091
queryString += ( queryString . length ) ? '&stable' : 'stable' ;
1085
1092
}
1086
1093
if ( queryString . length ) {
0 commit comments