[FIX] web: undefined graph when pie chart has no data

Before this commit, a crash occured when the no content
helper was rendered on an pie chart without data.
This commit is contained in:
Adrien Dieudonne
2018-09-25 15:36:29 +02:00
parent 5a439a85ef
commit a8ffbe28b2
2 changed files with 36 additions and 11 deletions
@@ -227,7 +227,10 @@ return AbstractRenderer.extend({
* Helper function to set up data properly for the pieChart model in
* nvd3.
*
* @returns {nvd3 chart}
* returns undefined in the case of an non-embedded pie chart with no data.
* (all zero data included)
*.
* @returns {nvd3 chart|undefined}
*/
_renderPieChart: function (stateData) {
var self = this;
@@ -471,14 +474,16 @@ return AbstractRenderer.extend({
}
var chart = this['_render' + _.str.capitalize(this.state.mode) + 'Chart'](this.state.data);
// FIXME: When 'orient' is right for Y axis, horizontal lines aren't displayed correctly
chart.dispatch.on('renderEnd', function () {
$('.nv-y .tick > line').attr('x2', function (i, value) {
return Math.abs(value);
});
})
if (chart) {
// FIXME: When 'orient' is right for Y axis, horizontal lines aren't displayed correctly
chart.dispatch.on('renderEnd', function () {
$('.nv-y .tick > line').attr('x2', function (i, value) {
return Math.abs(value);
});
})
chartResize(chart);
chartResize(chart);
}
if (this.state.mode === 'pie' && this.isComparison) {
// Render graph title
@@ -496,8 +501,9 @@ return AbstractRenderer.extend({
text: comparisonChartTitle,
}));
chartResize(comparisonChart);
chart.update();
if (chart) {
chart.update();
}
} else if (this.title) {
this.$('.o_graph_svg_container').last().prepend($('<label/>', {
text: this.title,
+20 -1
View File
@@ -225,7 +225,7 @@ QUnit.module('Views', {
});
});
QUnit.test('no content helper', function (assert) {
QUnit.test('no content helper (bar chart)', function (assert) {
assert.expect(2);
this.data.foo.records = [];
@@ -244,6 +244,25 @@ QUnit.module('Views', {
graph.destroy();
});
QUnit.test('no content helper (pie chart)', function (assert) {
assert.expect(2);
this.data.foo.records = []
var graph = createView({
View: GraphView,
model: "foo",
data: this.data,
arch: '<graph type="pie">' +
'<field name="product_id"/>' +
'</graph>',
});
assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 0,
"should not contain a div with a svg element");
assert.strictEqual(graph.$('div.o_view_nocontent').length, 1,
"should display the no content helper");
graph.destroy();
});
QUnit.test('no content helper after update', function (assert) {
var done = assert.async();
assert.expect(4);