Skip to content
Merged
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
7 changes: 7 additions & 0 deletions ooui/graph/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self, graph_type, element):
) or None
self._show_percent = parse_bool_attribute(
element.get('showPercent')) if element.get('showPercent') else False
self._show_total = parse_bool_attribute(
element.get('showTotal')) if element.get('showTotal') else True
self._progressbar = parse_bool_attribute(
element.get('progressbar')) if element.get('progressbar') else False
self.domain_parse_values = {}
Expand All @@ -44,6 +46,10 @@ def total_domain(self):
def show_percent(self):
return self._show_percent

@property
def show_total(self):
return self._show_total

@property
def progressbar(self):
return self._progressbar
Expand Down Expand Up @@ -71,6 +77,7 @@ def process(self, value, total=0):
res['progressbar'] = self.progressbar
if self.show_percent:
res['showPercent'] = self.show_percent
res['showTotal'] = self.show_total

Copilot AI Nov 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent API design: showTotal is always included in the response (line 80), while showPercent (line 78-79) and progressbar (line 76-77) are only included when True. Consider applying the same pattern for consistency - either always include all three boolean flags, or only include them when True. This inconsistency could confuse API consumers.

Suggested change
res['showTotal'] = self.show_total
if self.show_total:
res['showTotal'] = self.show_total

Copilot uses AI. Check for mistakes.
if not self.show_percent and not self.progressbar:
res.pop('percent', None)
return res
Expand Down
45 changes: 45 additions & 0 deletions spec/graph/graph_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
expect(graph.fields).to(contain_only('potencia'))
expect(graph.total_domain).to(be_none)
expect(graph.show_percent).to(be_true)
expect(graph.show_total).to(be_true)
expect(graph.progressbar).to(be_false)
expect(graph.suffix).to(equal('kW'))

Expand Down Expand Up @@ -73,6 +74,50 @@
expect(result).not_to(have_key('progressbar'))
expect(result).not_to(have_key('showPercent'))

with it('should include showTotal by default'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" />
"""
graph = parse_graph(xml)
expect(graph.show_total).to(be_true)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal', True))

with it('should support showTotal="0" to disable'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" showTotal="0" type="indicator" />
"""
graph = parse_graph(xml)
expect(graph.show_total).to(be_false)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal', False))

with it('should support showTotal="1" explicitly'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" showTotal="1" type="indicator" />
"""
graph = parse_graph(xml)
expect(graph.show_total).to(be_true)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal', True))

with it('should always include showTotal in response'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" />
"""
graph = parse_graph(xml)
result = graph.process(50, 100)
expect(result).to(have_key('showTotal'))
expect(result['showTotal']).to(be_true)

Copilot AI Nov 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected. This line should not have trailing whitespace.

Suggested change

Copilot uses AI. Check for mistakes.
xml_false = """<?xml version="1.0"?>
<graph string="My indicator" showTotal="0" type="indicator" />
"""
graph_false = parse_graph(xml_false)
result_false = graph_false.process(50, 100)
expect(result_false).to(have_key('showTotal'))
expect(result_false['showTotal']).to(be_false)

with it("should parse a chart graph XML with type line"):
xml = """<?xml version="1.0"?>
<graph type="line" y_range="auto">
Expand Down
26 changes: 26 additions & 0 deletions spec/graph/processor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_graph_data(xml, model):
icon='slack',
suffix='kW',
type='indicatorField',
showTotal=True,
))

with it('should process indicator graph'):
Expand All @@ -91,6 +92,31 @@ def get_graph_data(xml, model):
type='indicator',
))

with it('should process indicatorField graph with showTotal="0"'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" showPercent="1" showTotal="0" type="indicatorField" color="red:value>0;green:value==0" totalDomain="[]" icon="slack" suffix="kW">
<field name="potencia" operator="+" />
</graph>
"""
total_values = models['polissa'].data
t20A_values = [v for v in total_values if v['tarifa'][1] == "2.0A"]
g = parse_graph(xml)
result = g.process(
t20A_values,
fields=models['polissa'].fields,
total_values=total_values
)
expect(result).to(have_keys(
value=77.72,
percent=28.19,
total=275.72,
color='red',
icon='slack',
suffix='kW',
type='indicatorField',
showTotal=False,
))

# Un test per quan el total sigui 0 no falli al calcular el percentatge
with it('should evaluate percent when total is 0'):
xml = """<?xml version="1.0"?>
Expand Down
Loading