@@ -110,6 +110,23 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
110
110
}
111
111
}
112
112
113
+ function getLabelWidth ( type , text , elem ) {
114
+ var labelWidth = 0 ;
115
+ if ( ! rootScope . labelWidthCache ) {
116
+ rootScope . labelWidthCache = { } ;
117
+ }
118
+ if ( ! rootScope . labelWidthCache [ type ] ) {
119
+ rootScope . labelWidthCache [ type ] = { } ;
120
+ }
121
+ if ( rootScope . labelWidthCache [ type ] [ text ] ) {
122
+ labelWidth = rootScope . labelWidthCache [ type ] [ text ] ;
123
+ } else {
124
+ labelWidth = elem . width ( ) ;
125
+ rootScope . labelWidthCache [ type ] [ text ] = labelWidth ;
126
+ }
127
+ return labelWidth ;
128
+ }
129
+
113
130
function drawHook ( plot ) {
114
131
// Update legend values
115
132
var yaxis = plot . getYAxes ( ) ;
@@ -138,7 +155,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
138
155
. text ( panel . yaxes [ 0 ] . label )
139
156
. appendTo ( elem ) ;
140
157
141
- yaxisLabel . css ( "margin-top" , yaxisLabel . width ( ) / 2 ) ;
158
+ yaxisLabel [ 0 ] . style . marginTop = ( getLabelWidth ( 'left' , panel . yaxes [ 0 ] . label , yaxisLabel ) / 2 ) + 'px' ;
142
159
}
143
160
144
161
// add right axis labels
@@ -147,7 +164,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
147
164
. text ( panel . yaxes [ 1 ] . label )
148
165
. appendTo ( elem ) ;
149
166
150
- rightLabel . css ( "margin-top" , rightLabel . width ( ) / 2 ) ;
167
+ rightLabel [ 0 ] . style . marginTop = ( getLabelWidth ( 'right' , panel . yaxes [ 1 ] . label , rightLabel ) / 2 ) + 'px' ;
151
168
}
152
169
}
153
170
0 commit comments