@@ -37,6 +37,7 @@ export default class DistributionGraph extends React.Component {
37
37
constructor ( props ) {
38
38
super ( props ) ;
39
39
this . state = { } ;
40
+ this . mobileWidth = 0 ;
40
41
this . graphRef = React . createRef ( ) ;
41
42
}
42
43
@@ -45,7 +46,9 @@ export default class DistributionGraph extends React.Component {
45
46
$scope . desktop = window . innerWidth >= 900 ;
46
47
this . draw ( ) ;
47
48
this . resizeHandle = ( ) => {
48
- if ( window . innerWidth < 900 && $scope . desktop ) {
49
+ if ( window . innerWidth < 900
50
+ && ( $scope . desktop
51
+ || ( this . mobileWidth !== DistributionGraph . getMobileWidthGrapthMeasurements ( ) ) ) ) {
49
52
$scope . desktop = false ;
50
53
this . draw ( ) ;
51
54
} else if ( window . innerWidth >= 900 && ! $scope . desktop ) {
@@ -67,6 +70,13 @@ export default class DistributionGraph extends React.Component {
67
70
window . removeEventListener ( 'resize' , this . resizeHandle ) ;
68
71
}
69
72
73
+ static getMobileWidthGrapthMeasurements ( ) {
74
+ if ( window . innerWidth < 400 ) {
75
+ return 250 ;
76
+ }
77
+ return 370 ;
78
+ }
79
+
70
80
draw ( ) {
71
81
const $scope = this ;
72
82
const { distribution : wrapper , rating } = this . props ;
@@ -87,7 +97,7 @@ export default class DistributionGraph extends React.Component {
87
97
} ;
88
98
89
99
const mobileMeasurements = {
90
- w : 370 ,
100
+ w : 0 ,
91
101
h : 200 ,
92
102
padding : {
93
103
top : 50 ,
@@ -98,7 +108,12 @@ export default class DistributionGraph extends React.Component {
98
108
} ;
99
109
100
110
d3 . select ( $scope . graphRef . current ) . select ( 'svg' ) . remove ( ) ;
101
- const { w, h, padding } = $scope . desktop ? desktopMeasurements : mobileMeasurements ;
111
+ let { w } = $scope . desktop ? desktopMeasurements : mobileMeasurements ;
112
+ const { h, padding } = $scope . desktop ? desktopMeasurements : mobileMeasurements ;
113
+ if ( ! $scope . desktop ) {
114
+ w = DistributionGraph . getMobileWidthGrapthMeasurements ( ) ;
115
+ this . mobileWidth = w ;
116
+ }
102
117
const totalW = w + padding . left + padding . right ;
103
118
const totalH = h + padding . top + padding . bottom ;
104
119
0 commit comments