@@ -18,6 +18,8 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
18
18
'use strict' ;
19
19
20
20
var module = angular . module ( 'grafana.directives' ) ;
21
+ var labelWidthCache = { } ;
22
+ var panelWidthCache = { } ;
21
23
22
24
module . directive ( 'grafanaGraph' , function ( $rootScope , timeSrv ) {
23
25
return {
@@ -110,20 +112,13 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
110
112
}
111
113
}
112
114
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 ;
115
+ function getLabelWidth ( text , elem ) {
116
+ var labelWidth = labelWidthCache [ text ] ;
117
+
118
+ if ( ! labelWidth ) {
119
+ labelWidth = labelWidthCache [ text ] = elem . width ( ) ;
126
120
}
121
+
127
122
return labelWidth ;
128
123
}
129
124
@@ -155,7 +150,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
155
150
. text ( panel . yaxes [ 0 ] . label )
156
151
. appendTo ( elem ) ;
157
152
158
- yaxisLabel [ 0 ] . style . marginTop = ( getLabelWidth ( 'left' , panel . yaxes [ 0 ] . label , yaxisLabel ) / 2 ) + 'px' ;
153
+ yaxisLabel [ 0 ] . style . marginTop = ( getLabelWidth ( panel . yaxes [ 0 ] . label , yaxisLabel ) / 2 ) + 'px' ;
159
154
}
160
155
161
156
// add right axis labels
@@ -164,7 +159,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
164
159
. text ( panel . yaxes [ 1 ] . label )
165
160
. appendTo ( elem ) ;
166
161
167
- rightLabel [ 0 ] . style . marginTop = ( getLabelWidth ( 'right' , panel . yaxes [ 1 ] . label , rightLabel ) / 2 ) + 'px' ;
162
+ rightLabel [ 0 ] . style . marginTop = ( getLabelWidth ( panel . yaxes [ 1 ] . label , rightLabel ) / 2 ) + 'px' ;
168
163
}
169
164
}
170
165
@@ -177,14 +172,9 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
177
172
178
173
// Function for rendering panel
179
174
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 ;
175
+ panelWidth = panelWidthCache [ panel . span ] ;
176
+ if ( ! panelWidth ) {
177
+ panelWidth = panelWidthCache [ panel . span ] = elem . width ( ) ;
188
178
}
189
179
190
180
if ( shouldAbortRender ( ) ) {
0 commit comments