Skip to content

Commit b28368c

Browse files
committed
cache panel width
1 parent 2f5ae85 commit b28368c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

public/app/plugins/panel/graph/graph.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
3131
var sortedSeries;
3232
var legendSideLastValue = null;
3333
var rootScope = scope.$root;
34+
var panelWidth = 0;
3435

3536
rootScope.onAppEvent('setCrosshair', function(event, info) {
3637
// do not need to to this if event is from this panel
@@ -104,7 +105,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
104105
return true;
105106
}
106107

107-
if (elem.width() === 0) {
108+
if (panelWidth === 0) {
108109
return true;
109110
}
110111
}
@@ -159,6 +160,16 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
159160

160161
// Function for rendering panel
161162
function render_panel() {
163+
if (!rootScope.panelWidthCache) {
164+
rootScope.panelWidthCache = {};
165+
}
166+
if (rootScope.panelWidthCache[panel.span]) {
167+
panelWidth = rootScope.panelWidthCache[panel.span];
168+
} else {
169+
panelWidth = elem.width();
170+
rootScope.panelWidthCache[panel.span] = panelWidth;
171+
}
172+
162173
if (shouldAbortRender()) {
163174
return;
164175
}
@@ -276,7 +287,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
276287
}
277288

278289
function addTimeAxis(options) {
279-
var ticks = elem.width() / 100;
290+
var ticks = panelWidth / 100;
280291
var min = _.isUndefined(ctrl.range.from) ? null : ctrl.range.from.valueOf();
281292
var max = _.isUndefined(ctrl.range.to) ? null : ctrl.range.to.valueOf();
282293

@@ -444,7 +455,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
444455
}
445456

446457
function render_panel_as_graphite_png(url) {
447-
url += '&width=' + elem.width();
458+
url += '&width=' + panelWidth;
448459
url += '&height=' + elem.css('height').replace('px', '');
449460
url += '&bgcolor=1f1f1f'; // @grayDarker & @grafanaPanelBackground
450461
url += '&fgcolor=BBBFC2'; // @textColor & @grayLighter

0 commit comments

Comments
 (0)