@@ -31,6 +31,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
31
31
var sortedSeries ;
32
32
var legendSideLastValue = null ;
33
33
var rootScope = scope . $root ;
34
+ var panelWidth = 0 ;
34
35
35
36
rootScope . onAppEvent ( 'setCrosshair' , function ( event , info ) {
36
37
// do not need to to this if event is from this panel
@@ -104,11 +105,28 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
104
105
return true ;
105
106
}
106
107
107
- if ( elem . width ( ) === 0 ) {
108
+ if ( panelWidth === 0 ) {
108
109
return true ;
109
110
}
110
111
}
111
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
+
112
130
function drawHook ( plot ) {
113
131
// Update legend values
114
132
var yaxis = plot . getYAxes ( ) ;
@@ -137,7 +155,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
137
155
. text ( panel . yaxes [ 0 ] . label )
138
156
. appendTo ( elem ) ;
139
157
140
- yaxisLabel . css ( "margin-top" , yaxisLabel . width ( ) / 2 ) ;
158
+ yaxisLabel [ 0 ] . style . marginTop = ( getLabelWidth ( 'left' , panel . yaxes [ 0 ] . label , yaxisLabel ) / 2 ) + 'px' ;
141
159
}
142
160
143
161
// add right axis labels
@@ -146,7 +164,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
146
164
. text ( panel . yaxes [ 1 ] . label )
147
165
. appendTo ( elem ) ;
148
166
149
- rightLabel . css ( "margin-top" , rightLabel . width ( ) / 2 ) ;
167
+ rightLabel [ 0 ] . style . marginTop = ( getLabelWidth ( 'right' , panel . yaxes [ 1 ] . label , rightLabel ) / 2 ) + 'px' ;
150
168
}
151
169
}
152
170
@@ -159,6 +177,16 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
159
177
160
178
// Function for rendering panel
161
179
function render_panel ( ) {
180
+ if ( ! rootScope . panelWidthCache ) {
181
+ rootScope . panelWidthCache = { } ;
182
+ }
183
+ if ( rootScope . panelWidthCache [ panel . span ] ) {
184
+ panelWidth = rootScope . panelWidthCache [ panel . span ] ;
185
+ } else {
186
+ panelWidth = elem . width ( ) ;
187
+ rootScope . panelWidthCache [ panel . span ] = panelWidth ;
188
+ }
189
+
162
190
if ( shouldAbortRender ( ) ) {
163
191
return ;
164
192
}
@@ -276,7 +304,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
276
304
}
277
305
278
306
function addTimeAxis ( options ) {
279
- var ticks = elem . width ( ) / 100 ;
307
+ var ticks = panelWidth / 100 ;
280
308
var min = _ . isUndefined ( ctrl . range . from ) ? null : ctrl . range . from . valueOf ( ) ;
281
309
var max = _ . isUndefined ( ctrl . range . to ) ? null : ctrl . range . to . valueOf ( ) ;
282
310
@@ -444,7 +472,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
444
472
}
445
473
446
474
function render_panel_as_graphite_png ( url ) {
447
- url += '&width=' + elem . width ( ) ;
475
+ url += '&width=' + panelWidth ;
448
476
url += '&height=' + elem . css ( 'height' ) . replace ( 'px' , '' ) ;
449
477
url += '&bgcolor=1f1f1f' ; // @grayDarker & @grafanaPanelBackground
450
478
url += '&fgcolor=BBBFC2' ; // @textColor & @grayLighter
0 commit comments