@@ -160,6 +160,10 @@ class Compat2021 extends PolymerElement {
160
160
return html `
161
161
< style >
162
162
: host {
163
+ dis play: block;
164
+ max- width: 700px;
165
+ /* Override wpt.fyi's automatically injected common.css */
166
+ margin: 0 auto !important ;
163
167
font- family: system- ui, sans- serif;
164
168
line-height: 1.5;
165
169
}
@@ -551,6 +555,8 @@ class Compat2021FeatureChart extends PolymerElement {
551
555
with the JavaScript defined height. */
552
556
height : 350px ;
553
557
margin : 0 auto;
558
+ display : flex;
559
+ justify-content : center;
554
560
}
555
561
556
562
paper-dialog {
@@ -622,6 +628,16 @@ class Compat2021FeatureChart extends PolymerElement {
622
628
return 'compat-2021-feature-chart' ;
623
629
}
624
630
631
+ ready ( ) {
632
+ super . ready ( ) ;
633
+
634
+ // Google Charts is not responsive, even if one sets a percentage-width, so
635
+ // we add a resize observer to redraw the chart if the size changes.
636
+ window . addEventListener ( 'resize' , ( ) => {
637
+ this . updateChart ( this . feature , this . stable ) ;
638
+ } ) ;
639
+ }
640
+
625
641
async updateChart ( feature , stable ) {
626
642
// Our observer may be called before the feature is set, so debounce that.
627
643
if ( ! feature ) {
@@ -677,7 +693,7 @@ class Compat2021FeatureChart extends PolymerElement {
677
693
} ,
678
694
} ) ;
679
695
680
- chart . draw ( dataTable , this . getChartOptions ( feature ) ) ;
696
+ chart . draw ( dataTable , this . getChartOptions ( div , feature ) ) ;
681
697
}
682
698
683
699
getChromeChangelogUrl ( fromVersion , toVersion ) {
@@ -704,13 +720,10 @@ class Compat2021FeatureChart extends PolymerElement {
704
720
window . open ( url ) ;
705
721
}
706
722
707
- getChartOptions ( feature ) {
723
+ getChartOptions ( containerDiv , feature ) {
708
724
const options = {
709
- width : 800 ,
710
725
height : 350 ,
711
- chartArea : {
712
- height : '80%' ,
713
- } ,
726
+ fontSize : 14 ,
714
727
tooltip : {
715
728
trigger : 'both' ,
716
729
} ,
@@ -750,6 +763,27 @@ class Compat2021FeatureChart extends PolymerElement {
750
763
} ;
751
764
}
752
765
766
+ // We draw the chart in two ways, depending on the viewport width. In
767
+ // 'full' mode the legend is on the right and we limit the chart size to
768
+ // 700px wide. In 'mobile' mode the legend is on the top and we use all the
769
+ // space we can get for the chart.
770
+ if ( containerDiv . clientWidth >= 700 ) {
771
+ options . width = 700 ;
772
+ options . chartArea = {
773
+ height : '80%'
774
+ } ;
775
+ } else {
776
+ options . width = '100%' ;
777
+ options . legend = {
778
+ position : 'top' ,
779
+ alignment : 'center' ,
780
+ } ;
781
+ options . chartArea = {
782
+ left : 75 ,
783
+ width : '80%' ,
784
+ } ;
785
+ }
786
+
753
787
return options ;
754
788
}
755
789
}
0 commit comments