diff --git a/ooui/graph/indicator.py b/ooui/graph/indicator.py index 1299284..d307037 100644 --- a/ooui/graph/indicator.py +++ b/ooui/graph/indicator.py @@ -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 @@ -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 @@ -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 diff --git a/spec/graph/graph_spec.py b/spec/graph/graph_spec.py index 96c8e7a..94b76b7 100644 --- a/spec/graph/graph_spec.py +++ b/spec/graph/graph_spec.py @@ -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 = """ + + """ + 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 = """ + + """ + 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 = """ + + """ + 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 = """ + + """ + 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 = """