Skip to content

Commit bf82fdb

Browse files
committed
Merge branch 'perf_graph_js' of https://github.com/mtanda/grafana into mtanda-perf_graph_js
2 parents e1e7fbf + 487b208 commit bf82fdb

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

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

Lines changed: 33 additions & 5 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,11 +105,28 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
104105
return true;
105106
}
106107

107-
if (elem.width() === 0) {
108+
if (panelWidth === 0) {
108109
return true;
109110
}
110111
}
111112

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+
112130
function drawHook(plot) {
113131
// Update legend values
114132
var yaxis = plot.getYAxes();
@@ -137,7 +155,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
137155
.text(panel.yaxes[0].label)
138156
.appendTo(elem);
139157

140-
yaxisLabel.css("margin-top", yaxisLabel.width() / 2);
158+
yaxisLabel[0].style.marginTop = (getLabelWidth('left', panel.yaxes[0].label, yaxisLabel) / 2) + 'px';
141159
}
142160

143161
// add right axis labels
@@ -146,7 +164,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
146164
.text(panel.yaxes[1].label)
147165
.appendTo(elem);
148166

149-
rightLabel.css("margin-top", rightLabel.width() / 2);
167+
rightLabel[0].style.marginTop = (getLabelWidth('right', panel.yaxes[1].label, rightLabel) / 2) + 'px';
150168
}
151169
}
152170

@@ -159,6 +177,16 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
159177

160178
// Function for rendering panel
161179
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+
162190
if (shouldAbortRender()) {
163191
return;
164192
}
@@ -276,7 +304,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
276304
}
277305

278306
function addTimeAxis(options) {
279-
var ticks = elem.width() / 100;
307+
var ticks = panelWidth / 100;
280308
var min = _.isUndefined(ctrl.range.from) ? null : ctrl.range.from.valueOf();
281309
var max = _.isUndefined(ctrl.range.to) ? null : ctrl.range.to.valueOf();
282310

@@ -444,7 +472,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
444472
}
445473

446474
function render_panel_as_graphite_png(url) {
447-
url += '&width=' + elem.width();
475+
url += '&width=' + panelWidth;
448476
url += '&height=' + elem.css('height').replace('px', '');
449477
url += '&bgcolor=1f1f1f'; // @grayDarker & @grafanaPanelBackground
450478
url += '&fgcolor=BBBFC2'; // @textColor & @grayLighter

0 commit comments

Comments
 (0)