[FIX] web: always show the graph view button "Stacked"

With the actual code, some computations are done
in the graph renderer to determine if it is worth
to show the "Stacked" button in the graph view control
panel for the data on hand. It turns out that that
problem is not satisfactorily addressed and is quite
hard from a usability perspective. We prefer to restore
the old behavior as long as we don't have better ideas.

closes odoo/odoo#37188

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2019-09-20 09:23:24 +00:00
parent d0c1db764c
commit 149d2a3d60
3 changed files with 3 additions and 30 deletions
@@ -177,7 +177,7 @@ var GraphController = AbstractController.extend(GroupByMenuMixin,{
.find('.o_graph_button[data-mode="stack"]')
.data('stacked', state.stacked)
.toggleClass('active', state.stacked)
.toggleClass('o_hidden', state.mode !== 'bar' || !this.renderer.isStackable);
.toggleClass('o_hidden', state.mode !== 'bar');
_.each(this.$measureList.find('.dropdown-item'), function (item) {
var $item = $(item);
$item.toggleClass('selected', $item.data('field') === state.measure);
@@ -71,8 +71,6 @@ return AbstractRenderer.extend({
this.chart = null;
this.chartId = _.uniqueId('chart');
// the bar charts are considered stackable a priori
this.isStackable = true;
this.$legendTooltip = null;
this.$tooltip = null;
},
@@ -782,34 +780,9 @@ return AbstractRenderer.extend({
// prepare data
var data = this._prepareData(dataPoints);
// The datapoints (with non zero value) can be grouped by
// their originIndex and associated labels.
// If at least one group formed in that way has two elements
// this.isStackable will be true.
var groupMemberCounts = data.labels.map(function () {
return {};
});
this.isStackable = false;
for (var i = 0; i < data.datasets.length; i++) {
var dataset = data.datasets[i];
var originIndex = dataset.originIndex;
if (this.isStackable) {
break;
}
for (var j = 0; j < dataset.data.length; j++) {
if (dataset.data[j]) {
if (originIndex in groupMemberCounts[j]) {
this.isStackable = true;
break;
} else {
groupMemberCounts[j][originIndex] = 1;
}
}
}
}
data.datasets.forEach(function (dataset, index) {
// used when stacked
dataset.stack = self.isStackable && self.state.stacked ? self.state.origins[dataset.originIndex] : undefined;
dataset.stack = self.state.stacked ? self.state.origins[dataset.originIndex] : undefined;
// set dataset color
var color = self._getColor(index);
dataset.backgroundColor = color;
+1 -1
View File
@@ -133,7 +133,7 @@ QUnit.module('Views', {
data: [3,5],
label: "Count",
originIndex: 0,
stack: undefined,
stack: "",
}
);
assert.checkLegend(graph, 'Count');