Skip to content

Commit eed0d9c

Browse files
committed
feat(graph performance): graph performance tweaks, refactoring grafana#5297
1 parent bf82fdb commit eed0d9c

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

public/app/core/profiler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export class Profiler {
3636
}
3737

3838
refresh() {
39-
if (this.panels.length > 0) {
39+
this.panels = [];
40+
41+
setTimeout(() => {
4042
var totalRender = 0;
4143
var totalQuery = 0;
4244

@@ -49,8 +51,7 @@ export class Profiler {
4951
console.log('total query: ' + totalQuery);
5052
console.log('total render: ' + totalRender);
5153
console.log('avg render: ' + totalRender / this.panels.length);
52-
}
53-
this.$rootScope.panels = [];
54+
}, 5000);
5455
}
5556

5657
dashboardFetched() {

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

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
1818
'use strict';
1919

2020
var module = angular.module('grafana.directives');
21+
var labelWidthCache = {};
22+
var panelWidthCache = {};
2123

2224
module.directive('grafanaGraph', function($rootScope, timeSrv) {
2325
return {
@@ -110,20 +112,13 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
110112
}
111113
}
112114

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();
126120
}
121+
127122
return labelWidth;
128123
}
129124

@@ -155,7 +150,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
155150
.text(panel.yaxes[0].label)
156151
.appendTo(elem);
157152

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';
159154
}
160155

161156
// add right axis labels
@@ -164,7 +159,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
164159
.text(panel.yaxes[1].label)
165160
.appendTo(elem);
166161

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';
168163
}
169164
}
170165

@@ -177,14 +172,9 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
177172

178173
// Function for rendering panel
179174
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();
188178
}
189179

190180
if (shouldAbortRender()) {

0 commit comments

Comments
 (0)