Skip to content

Commit e59ad5e

Browse files
authored
Merge pull request #36 from gisce/80812/add-progressbar-to-indicator
Add progressbar property to indicator result
2 parents 81173e3 + c87299b commit e59ad5e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

ooui/graph/indicator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ 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+
self._progressbar = parse_bool_attribute(
28+
element.get('progressbar')) if element.get('progressbar') else False
2729
self.domain_parse_values = {}
2830

2931
@property
@@ -42,6 +44,10 @@ def total_domain(self):
4244
def show_percent(self):
4345
return self._show_percent
4446

47+
@property
48+
def progressbar(self):
49+
return self._progressbar
50+
4551
@property
4652
def suffix(self):
4753
return self._suffix
@@ -61,7 +67,11 @@ def process(self, value, total=0):
6167
res['color'] = self.color.eval(res)
6268
if self.icon:
6369
res['icon'] = self.icon.eval(res)
64-
if not self.show_percent:
70+
if self.progressbar:
71+
res['progressbar'] = self.progressbar
72+
if self.show_percent:
73+
res['showPercent'] = self.show_percent
74+
if not self.show_percent and not self.progressbar:
6575
res.pop('percent', None)
6676
return res
6777

spec/graph/graph_spec.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,46 @@
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.progressbar).to(be_false)
3637
expect(graph.suffix).to(equal('kW'))
3738

39+
with it('should support progressbar attribute'):
40+
xml = """<?xml version="1.0"?>
41+
<graph string="My indicator" progressbar="1" type="indicator" />
42+
"""
43+
graph = parse_graph(xml)
44+
expect(graph.progressbar).to(be_true)
45+
expect(graph.show_percent).to(be_false)
46+
47+
with it('should calculate percent when progressbar is true'):
48+
xml = """<?xml version="1.0"?>
49+
<graph string="My indicator" progressbar="1" type="indicator" />
50+
"""
51+
graph = parse_graph(xml)
52+
result = graph.process(50, 100)
53+
expect(result).to(have_key('percent', 50.0))
54+
expect(result).to(have_key('progressbar', True))
55+
expect(result).not_to(have_key('showPercent'))
56+
57+
with it('should calculate percent when showPercent is true'):
58+
xml = """<?xml version="1.0"?>
59+
<graph string="My indicator" showPercent="1" type="indicator" />
60+
"""
61+
graph = parse_graph(xml)
62+
result = graph.process(50, 100)
63+
expect(result).to(have_key('percent', 50.0))
64+
expect(result).to(have_key('showPercent', True))
65+
66+
with it('should not include percent when both progressbar and showPercent are false'):
67+
xml = """<?xml version="1.0"?>
68+
<graph string="My indicator" type="indicator" />
69+
"""
70+
graph = parse_graph(xml)
71+
result = graph.process(50, 100)
72+
expect(result).not_to(have_key('percent'))
73+
expect(result).not_to(have_key('progressbar'))
74+
expect(result).not_to(have_key('showPercent'))
75+
3876
with it("should parse a chart graph XML with type line"):
3977
xml = """<?xml version="1.0"?>
4078
<graph type="line" y_range="auto">

0 commit comments

Comments
 (0)