From 53a7fd91cdd192457e54c725b57a22728018de8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Wed, 11 Nov 2026 16:42:57 +0100 Subject: [PATCH] fix(graph): stack all series when stacked equals label Refs gisce/webclient#4323 --- ooui/graph/chart.py | 2 +- spec/graph/graph_spec.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ooui/graph/chart.py b/ooui/graph/chart.py index 7babf3a..815158f 100644 --- a/ooui/graph/chart.py +++ b/ooui/graph/chart.py @@ -92,7 +92,7 @@ def process(self, values, fields, options=None): 'stacked': y_field.stacked }) else: - if y_field.stacked in fields: + if y_field.stacked in fields and y_field.stacked != y_field.label: values_grouped_by_y_label = get_values_grouped_by_fields( [y_field.label, y_field.stacked], fields, diff --git a/spec/graph/graph_spec.py b/spec/graph/graph_spec.py index ff993d4..622fcdf 100644 --- a/spec/graph/graph_spec.py +++ b/spec/graph/graph_spec.py @@ -368,3 +368,30 @@ "value": 1.0 }] })) + with description("A bar graph stacked by its own label field"): + with it("should stack every label in a single stack"): + xml = """ + + + + """ + graph = parse_graph(xml) + fields = { + 'time': {'type': 'char', 'string': 'Time'}, + 'value': {'type': 'integer', 'string': 'Value'}, + 'name': {'type': 'char', 'string': 'Name', 'size': 64}, + } + values = [ + {'id': 1, 'time': '00:00', 'name': 'cnc_active', 'value': 30}, + {'id': 2, 'time': '00:00', 'name': 'cnc_other', 'value': 5}, + {'id': 3, 'time': '00:15', 'name': 'cnc_active', 'value': 32}, + {'id': 4, 'time': '00:15', 'name': 'cnc_other', 'value': 4}, + ] + result = graph.process(values, fields) + expect(result['isStack']).to(be_true) + expect(result['data']).to(equal([ + {'x': '00:00', 'value': 30, 'type': 'cnc_active', 'operator': '+', 'stacked': 'name'}, + {'x': '00:00', 'value': 5, 'type': 'cnc_other', 'operator': '+', 'stacked': 'name'}, + {'x': '00:15', 'value': 32, 'type': 'cnc_active', 'operator': '+', 'stacked': 'name'}, + {'x': '00:15', 'value': 4, 'type': 'cnc_other', 'operator': '+', 'stacked': 'name'}, + ]))