Skip to content

Commit 487b208

Browse files
committed
cache label width
1 parent b28368c commit 487b208

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
110110
}
111111
}
112112

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+
113130
function drawHook(plot) {
114131
// Update legend values
115132
var yaxis = plot.getYAxes();
@@ -138,7 +155,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
138155
.text(panel.yaxes[0].label)
139156
.appendTo(elem);
140157

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

144161
// add right axis labels
@@ -147,7 +164,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
147164
.text(panel.yaxes[1].label)
148165
.appendTo(elem);
149166

150-
rightLabel.css("margin-top", rightLabel.width() / 2);
167+
rightLabel[0].style.marginTop = (getLabelWidth('right', panel.yaxes[1].label, rightLabel) / 2) + 'px';
151168
}
152169
}
153170

0 commit comments

Comments
 (0)