diff --git a/addons/web/static/src/views/graph/graph_controller.js b/addons/web/static/src/views/graph/graph_controller.js index 9b69133ffb8..4e2000843fb 100644 --- a/addons/web/static/src/views/graph/graph_controller.js +++ b/addons/web/static/src/views/graph/graph_controller.js @@ -31,11 +31,19 @@ export class GraphController extends Component { getContext() { // expand context object? change keys? const { measure, groupBy, mode } = this.model.metaData; - return { + const context = { graph_measure: measure, graph_mode: mode, graph_groupbys: groupBy.map((gb) => gb.spec), }; + if (mode !== "pie") { + context.graph_order = this.model.metaData.order; + context.graph_stacked = this.model.metaData.stacked; + if (mode === "line") { + context.graph_cumulated = this.model.metaData.cumulated; + } + } + return context; } /** diff --git a/addons/web/static/src/views/graph/graph_model.js b/addons/web/static/src/views/graph/graph_model.js index 87df2bac813..5ec338e7692 100644 --- a/addons/web/static/src/views/graph/graph_model.js +++ b/addons/web/static/src/views/graph/graph_model.js @@ -163,6 +163,13 @@ export class GraphModel extends Model { metaData.measure = context.graph_measure || metaData.measure; metaData.mode = context.graph_mode || metaData.mode; metaData.groupBy = groupBy.length ? groupBy : this.initialGroupBy; + if (metaData.mode !== "pie") { + metaData.order = "graph_order" in context ? context.graph_order : metaData.order; + metaData.stacked = "graph_stacked" in context ? context.graph_stacked : metaData.stacked; + if (metaData.mode === "line") { + metaData.cumulated = "graph_cumulated" in context ? context.graph_cumulated : metaData.cumulated; + } + } this._normalize(metaData); diff --git a/addons/web/static/tests/views/graph_view_tests.js b/addons/web/static/tests/views/graph_view_tests.js index 4c7130af549..0367b40b147 100644 --- a/addons/web/static/tests/views/graph_view_tests.js +++ b/addons/web/static/tests/views/graph_view_tests.js @@ -2479,24 +2479,34 @@ QUnit.module("Views", (hooks) => { graph_mode: "bar", graph_measure: "__count", graph_groupbys: ["product_id"], + graph_order: null, + graph_stacked: true, group_by: [], }, { graph_mode: "bar", graph_measure: "foo", graph_groupbys: ["product_id"], + graph_order: null, + graph_stacked: true, group_by: [], }, { graph_mode: "line", graph_measure: "foo", + graph_cumulated: false, graph_groupbys: ["product_id"], + graph_order: null, + graph_stacked: true, group_by: [], }, { graph_mode: "line", graph_measure: "foo", + graph_cumulated: false, graph_groupbys: ["product_id", "color_id"], + graph_order: null, + graph_stacked: true, group_by: ["product_id", "color_id"], }, ];