Skip to content

Commit 26e5d7a

Browse files
committed
Graph: fixed PNG rendering of panels with legend table to the right, grafana#2185
1 parent cfeba99 commit 26e5d7a

File tree

11 files changed

+26
-7
lines changed

11 files changed

+26
-7
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
- Search HTTP API response has changed (simplified), tags list moved to seperate HTTP resource URI
2929
- Datasource HTTP api breaking change, ADD datasource is now POST /api/datasources/, update is now PUT /api/datasources/:id
3030

31+
**Fixes**
32+
- [Issue #2185](https://github.com/grafana/grafana/issues/2185). Graph: fixed PNG rendering of panels with legend table to the right
33+
3134
# 2.0.3 (unreleased - 2.0.x branch)
3235

3336
**Fixes**

pkg/components/renderer/renderer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func RenderToPng(params *RenderOpts) (string, error) {
5454
}()
5555

5656
select {
57-
case <-time.After(10 * time.Second):
57+
case <-time.After(15 * time.Second):
5858
if err := cmd.Process.Kill(); err != nil {
5959
log.Error(4, "failed to kill: %v", err)
6060
}

public/app/features/dashboard/dashboardCtrl.js

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function (angular, $, config) {
8484
};
8585

8686
$scope.broadcastRefresh = function() {
87+
$rootScope.performance.panelsRendered = 0;
8788
$rootScope.$broadcast('refresh');
8889
};
8990

public/app/features/dashboard/dynamicDashboardSrv.js

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function (angular, _) {
164164

165165
_.each(selected, function(option, index) {
166166
var copy = self.getPanelClone(panel, row, index);
167+
copy.span = 12 / selected.length;
167168
copy.scopedVars = copy.scopedVars || {};
168169
copy.scopedVars[variable.name] = option;
169170
});

public/app/features/panel/panelSrv.js

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ function (angular, _, config) {
8686
return datasourceSrv.get($scope.panel.datasource);
8787
};
8888

89+
$scope.panelRenderingComplete = function() {
90+
$rootScope.performance.panelsRendered++;
91+
};
92+
8993
$scope.get_data = function() {
9094
if ($scope.otherPanelInFullscreenMode()) { return; }
9195

public/app/panels/dashlist/module.js

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function (angular, app, _, config, PanelMeta) {
6666

6767
return backendSrv.search(params).then(function(result) {
6868
$scope.dashList = result;
69+
$scope.panelRenderingComplete();
6970
});
7071
};
7172

public/app/panels/graph/graph.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,26 @@ function (angular, $, kbn, moment, _, GraphTooltip) {
247247

248248
sortedSeries = _.sortBy(data, function(series) { return series.zindex; });
249249

250-
function callPlot() {
250+
function callPlot(incrementRenderCounter) {
251251
try {
252252
$.plot(elem, sortedSeries, options);
253253
} catch (e) {
254254
console.log('flotcharts error', e);
255255
}
256+
257+
if (incrementRenderCounter) {
258+
scope.panelRenderingComplete();
259+
}
256260
}
257261

258262
if (shouldDelayDraw(panel)) {
259263
// temp fix for legends on the side, need to render twice to get dimensions right
260-
callPlot();
261-
setTimeout(callPlot, 50);
264+
callPlot(false);
265+
setTimeout(function() { callPlot(true); }, 50);
262266
legendSideLastValue = panel.legend.rightSide;
263267
}
264268
else {
265-
callPlot();
269+
callPlot(true);
266270
}
267271
}
268272

public/app/panels/singlestat/singleStatPanel.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function (angular, app, _, $) {
2020

2121
scope.$on('render', function() {
2222
render();
23+
scope.panelRenderingComplete();
2324
});
2425

2526
function setElementHeight() {

public/app/panels/text/module.js

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function (angular, app, _, require, PanelMeta) {
6161
else if ($scope.panel.mode === 'text') {
6262
$scope.renderText($scope.panel.content);
6363
}
64+
$scope.panelRenderingComplete();
6465
};
6566

6667
$scope.renderText = function(content) {

public/test/specs/graph-specs.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ define([
3636
}
3737
};
3838

39+
scope.panelRenderingComplete = sinon.spy();
3940
scope.appEvent = sinon.spy();
4041
scope.onAppEvent = sinon.spy();
4142
scope.hiddenSeries = {};

vendor/phantomjs/render.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ page.open(params.url, function (status) {
3434

3535
function checkIsReady() {
3636
var canvas = page.evaluate(function() {
37-
return $('canvas').length > 0;
37+
var body = angular.element(document.body); // 1
38+
var rootScope = body.scope().$root;
39+
return rootScope.performance.panelsRendered > 0;
3840
});
3941

40-
if (canvas || tries === 100) {
42+
if (canvas || tries === 1000) {
4143
page.render(params.png);
4244
phantom.exit();
4345
}

0 commit comments

Comments
 (0)