Skip to content

Commit 862931f

Browse files
authored
Merge pull request #39 from gisce/80812/fix-show-total
Fix show total when total domain is not set
2 parents 50a1703 + faaec8d commit 862931f

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

ooui/graph/indicator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def __init__(self, graph_type, element):
2424
) or None
2525
self._show_percent = parse_bool_attribute(
2626
element.get('showPercent')) if element.get('showPercent') else False
27+
# showTotal is True by default only if totalDomain is defined, otherwise False
28+
default_show_total = bool(self._total_domain)
2729
self._show_total = parse_bool_attribute(
28-
element.get('showTotal')) if element.get('showTotal') else True
30+
element.get('showTotal')) if element.get('showTotal') else default_show_total
2931
self._progressbar = parse_bool_attribute(
3032
element.get('progressbar')) if element.get('progressbar') else False
3133
self.domain_parse_values = {}

spec/graph/graph_spec.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
expect(graph.fields).to(contain_only('potencia'))
3434
expect(graph.total_domain).to(be_none)
3535
expect(graph.show_percent).to(be_true)
36-
expect(graph.show_total).to(be_true)
36+
expect(graph.show_total).to(be_false) # False because no totalDomain
3737
expect(graph.progressbar).to(be_false)
3838
expect(graph.suffix).to(equal('kW'))
3939

@@ -74,11 +74,20 @@
7474
expect(result).not_to(have_key('progressbar'))
7575
expect(result).not_to(have_key('showPercent'))
7676

77-
with it('should include showTotal by default'):
77+
with it('should not include showTotal by default when no totalDomain'):
7878
xml = """<?xml version="1.0"?>
7979
<graph string="My indicator" type="indicator" />
8080
"""
8181
graph = parse_graph(xml)
82+
expect(graph.show_total).to(be_false)
83+
result = graph.process(50, 100)
84+
expect(result).to(have_key('showTotal', False))
85+
86+
with it('should include showTotal=True by default when totalDomain is defined'):
87+
xml = """<?xml version="1.0"?>
88+
<graph string="My indicator" type="indicator" totalDomain="[('user', '=', uid)]" />
89+
"""
90+
graph = parse_graph(xml)
8291
expect(graph.show_total).to(be_true)
8392
result = graph.process(50, 100)
8493
expect(result).to(have_key('showTotal', True))
@@ -101,14 +110,22 @@
101110
result = graph.process(50, 100)
102111
expect(result).to(have_key('showTotal', True))
103112

104-
with it('should always include showTotal in response'):
105-
xml = """<?xml version="1.0"?>
113+
with it('should always include showTotal in response with correct value'):
114+
xml_no_domain = """<?xml version="1.0"?>
106115
<graph string="My indicator" type="indicator" />
107116
"""
108-
graph = parse_graph(xml)
109-
result = graph.process(50, 100)
110-
expect(result).to(have_key('showTotal'))
111-
expect(result['showTotal']).to(be_true)
117+
graph_no_domain = parse_graph(xml_no_domain)
118+
result_no_domain = graph_no_domain.process(50, 100)
119+
expect(result_no_domain).to(have_key('showTotal'))
120+
expect(result_no_domain['showTotal']).to(be_false)
121+
122+
xml_with_domain = """<?xml version="1.0"?>
123+
<graph string="My indicator" type="indicator" totalDomain="[]" />
124+
"""
125+
graph_with_domain = parse_graph(xml_with_domain)
126+
result_with_domain = graph_with_domain.process(50, 100)
127+
expect(result_with_domain).to(have_key('showTotal'))
128+
expect(result_with_domain['showTotal']).to(be_true)
112129

113130
xml_false = """<?xml version="1.0"?>
114131
<graph string="My indicator" showTotal="0" type="indicator" />

spec/graph/processor_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_graph_data(xml, model):
4343
"""
4444
result = get_graph_data(xml, 'polissa')
4545
expect(result).to(have_keys(
46-
value=275.72, color='red'
46+
value=275.72, color='red', showTotal=False # False because no totalDomain
4747
))
4848

4949
with it('should process indicatorField graph'):
@@ -68,7 +68,7 @@ def get_graph_data(xml, model):
6868
icon='slack',
6969
suffix='kW',
7070
type='indicatorField',
71-
showTotal=True,
71+
showTotal=True, # True because totalDomain="[]" is defined
7272
))
7373

7474
with it('should process indicator graph'):

0 commit comments

Comments
 (0)