Skip to content
Permalink
Browse files

[IMP] web: group by more than two fields in graph view

Before this commit: select more than two groupbys
in a graph view would have no impact at all if mode
'bar' or 'line' is selected.

This commit allows to correctly handle more than
two groupbys in all modes.

Task ID: 1917948
  • Loading branch information...
jpr-odoo authored and Polymorphe57 committed Dec 17, 2018
1 parent f5c269d commit 02cfe7e4bc1ac547fe3fcd391a2bdafd5ce4f12e
@@ -174,12 +174,12 @@ return AbstractRenderer.extend({
values = {};
for (var i = 0; i < this.state.data.length; i++) {
label = this.state.data[i].labels[0];
serie = this.state.data[i].labels[1];
serie = this.state.data[i].labels.slice(1).join("/");
value = this.state.data[i].value;
if ((!xlabels.length) || (xlabels[xlabels.length-1] !== label)) {
xlabels.push(label);
}
series.push(this.state.data[i].labels[1]);
series.push(serie);
if (!(serie in values)) {values[serie] = {};}
values[serie][label] = this.state.data[i].value;
}
@@ -403,7 +403,7 @@ return AbstractRenderer.extend({
ticksLabels.push(tickLabel);
tick++;
}
serie = graphData[i].labels[1];
serie = graphData[i].labels.slice(1).join("/");
if (!data_dict[serie]) {
data_dict[serie] = {
values: [],
@@ -179,15 +179,36 @@ QUnit.module('Views', {
model: 'foo',
data: this.data,
arch: '<graph type="line"><field name="foo" /></graph>',
groupBy: ['product_id', 'bar'],
groupBy: ['product_id', 'bar', 'color_id'],
});

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");
assert.strictEqual(graph.$('text.nv-legend-text:contains(true)').length, 2,
"should have an entry for each value of field 'bar' and 'color_id' in the legend");

graph.destroy();
});

QUnit.test('displaying bar chart data with multiple groupbys', function (assert) {
assert.expect(3);

var graph = createView({
View: GraphView,
model: 'foo',
data: this.data,
arch: '<graph type="bar"><field name="foo" /></graph>',
groupBy: ['product_id', 'bar', 'color_id'],
});

assert.containsOnce(graph, '.nv-x text:contains(xphone)',
"should contain a text element with product xphone on X axis");
assert.containsOnce(graph, '.nv-x text:contains(xpad)',
"should contain a text element with product xpad on X axis");
assert.containsOnce(graph, 'text.nv-legend-text:contains(true/red)',
"should have an entry for each value of field 'bar' and 'color_id' in the legend");

graph.destroy();
});

0 comments on commit 02cfe7e

Please sign in to comment.
You can’t perform that action at this time.