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
12 changes: 11 additions & 1 deletion 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._progressbar = parse_bool_attribute(
element.get('progressbar')) if element.get('progressbar') else False
self.domain_parse_values = {}

@property
Expand All @@ -42,6 +44,10 @@ def total_domain(self):
def show_percent(self):
return self._show_percent

@property
def progressbar(self):
return self._progressbar

@property
def suffix(self):
return self._suffix
Expand All @@ -61,7 +67,11 @@ def process(self, value, total=0):
res['color'] = self.color.eval(res)
if self.icon:
res['icon'] = self.icon.eval(res)
if not self.show_percent:
if self.progressbar:
res['progressbar'] = self.progressbar
if self.show_percent:
res['showPercent'] = self.show_percent
if not self.show_percent and not self.progressbar:
res.pop('percent', None)
return res

Expand Down
38 changes: 38 additions & 0 deletions spec/graph/graph_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,46 @@
expect(graph.fields).to(contain_only('potencia'))
expect(graph.total_domain).to(be_none)
expect(graph.show_percent).to(be_true)
expect(graph.progressbar).to(be_false)
expect(graph.suffix).to(equal('kW'))

with it('should support progressbar attribute'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" progressbar="1" type="indicator" />
"""
graph = parse_graph(xml)
expect(graph.progressbar).to(be_true)
expect(graph.show_percent).to(be_false)

with it('should calculate percent when progressbar is true'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" progressbar="1" type="indicator" />
"""
graph = parse_graph(xml)
result = graph.process(50, 100)
expect(result).to(have_key('percent', 50.0))
expect(result).to(have_key('progressbar', True))
expect(result).not_to(have_key('showPercent'))

with it('should calculate percent when showPercent is true'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" showPercent="1" type="indicator" />
"""
graph = parse_graph(xml)
result = graph.process(50, 100)
expect(result).to(have_key('percent', 50.0))
expect(result).to(have_key('showPercent', True))

with it('should not include percent when both progressbar and showPercent are false'):
xml = """<?xml version="1.0"?>
<graph string="My indicator" type="indicator" />
"""
graph = parse_graph(xml)
result = graph.process(50, 100)
expect(result).not_to(have_key('percent'))
expect(result).not_to(have_key('progressbar'))
expect(result).not_to(have_key('showPercent'))

with it("should parse a chart graph XML with type line"):
xml = """<?xml version="1.0"?>
<graph type="line" y_range="auto">
Expand Down