From 3c9aa50449681efc5b4bcc680a6200c964d45804 Mon Sep 17 00:00:00 2001 From: Dipalee Bhalodia Date: Thu, 28 Jun 2018 18:21:11 +0530 Subject: [PATCH] [FIX] web: Graph: group by two fields on line chart Before this commit, when we applied two or more groupbys in line graph, the groups displayed on the X axis where shifted to the left, and the first one wasn't displayed at all. related task: #1848289 Closes: #25037 --- .../src/js/views/graph/graph_renderer.js | 2 +- addons/web/static/tests/views/graph_tests.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js index 58ce4b2fc39..2b193bbdccb 100644 --- a/addons/web/static/src/js/views/graph/graph_renderer.js +++ b/addons/web/static/src/js/views/graph/graph_renderer.js @@ -313,7 +313,7 @@ return AbstractRenderer.extend({ }; } data_dict[serie].values.push({ - x: tick, y: this.state.data[i].value, + x: tick - 1, y: this.state.data[i].value, }); data = _.map(data_dict, identity); } diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js index f7d22f27a64..1e5edef4df3 100644 --- a/addons/web/static/tests/views/graph_tests.js +++ b/addons/web/static/tests/views/graph_tests.js @@ -154,6 +154,29 @@ QUnit.module('Views', { }); }); + QUnit.test('displaying line chart data with multiple groupbys', function (assert) { + // this test makes sure the line chart shows all data labels (X axis) when + // it is grouped by several fields + assert.expect(3); + + var graph = createView({ + View: GraphView, + model: 'foo', + data: this.data, + arch: '', + groupBy: ['product_id', 'bar'], + }); + + assert.strictEqual(graph.$('.nv-x text:contains(xphone)').length, 1, + "should contain a text element with product xphone on X axis"); + assert.strictEqual(graph.$('.nv-x text:contains(xpad)').length, 1, + "should contain a text element with product xpad on X axis"); + assert.strictEqual(graph.$('text:contains(true)').length, 1, + "should have an entry for each value of field 'bar' in the legend"); + + graph.destroy(); + }); + QUnit.test('switching measures', function (assert) { var done = assert.async(); assert.expect(4);