Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ooui/graph/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions spec/graph/graph_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """<?xml version="1.0"?>
<graph type="bar">
<field name="time" axis="x"/>
<field name="value" operator="+" axis="y" label="name" stacked="name"/>
</graph>"""
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'},
]))
Loading