Skip to content

Commit 4106f13

Browse files
committed
Add progressbar property to indicator result
- Include progressbar in result when it's set to True - Update tests to verify progressbar property in result
1 parent 81173e3 commit 4106f13

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

ooui/graph/indicator.py

Lines changed: 9 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,9 @@ 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 not self.show_percent and not self.progressbar:
6573
res.pop('percent', None)
6674
return res
6775

spec/graph/graph_spec.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,43 @@
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+
56+
with it('should calculate percent when showPercent is true'):
57+
xml = """<?xml version="1.0"?>
58+
<graph string="My indicator" showPercent="1" type="indicator" />
59+
"""
60+
graph = parse_graph(xml)
61+
result = graph.process(50, 100)
62+
expect(result).to(have_key('percent', 50.0))
63+
64+
with it('should not include percent when both progressbar and showPercent are false'):
65+
xml = """<?xml version="1.0"?>
66+
<graph string="My indicator" type="indicator" />
67+
"""
68+
graph = parse_graph(xml)
69+
result = graph.process(50, 100)
70+
expect(result).not_to(have_key('percent'))
71+
expect(result).not_to(have_key('progressbar'))
72+
3873
with it("should parse a chart graph XML with type line"):
3974
xml = """<?xml version="1.0"?>
4075
<graph type="line" y_range="auto">

0 commit comments

Comments
 (0)