diff --git a/ooui/graph/indicator.py b/ooui/graph/indicator.py
index d307037..6f5a37c 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._show_total = parse_bool_attribute(
+ element.get('showTotal')) if element.get('showTotal') else True
self._progressbar = parse_bool_attribute(
element.get('progressbar')) if element.get('progressbar') else False
self.domain_parse_values = {}
@@ -44,6 +46,10 @@ def total_domain(self):
def show_percent(self):
return self._show_percent
+ @property
+ def show_total(self):
+ return self._show_total
+
@property
def progressbar(self):
return self._progressbar
@@ -71,6 +77,7 @@ def process(self, value, total=0):
res['progressbar'] = self.progressbar
if self.show_percent:
res['showPercent'] = self.show_percent
+ res['showTotal'] = self.show_total
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 94b76b7..2d493dd 100644
--- a/spec/graph/graph_spec.py
+++ b/spec/graph/graph_spec.py
@@ -33,6 +33,7 @@
expect(graph.fields).to(contain_only('potencia'))
expect(graph.total_domain).to(be_none)
expect(graph.show_percent).to(be_true)
+ expect(graph.show_total).to(be_true)
expect(graph.progressbar).to(be_false)
expect(graph.suffix).to(equal('kW'))
@@ -73,6 +74,50 @@
expect(result).not_to(have_key('progressbar'))
expect(result).not_to(have_key('showPercent'))
+ with it('should include showTotal by default'):
+ xml = """
+
+ """
+ graph = parse_graph(xml)
+ expect(graph.show_total).to(be_true)
+ result = graph.process(50, 100)
+ expect(result).to(have_key('showTotal', True))
+
+ with it('should support showTotal="0" to disable'):
+ xml = """
+
+ """
+ graph = parse_graph(xml)
+ expect(graph.show_total).to(be_false)
+ result = graph.process(50, 100)
+ expect(result).to(have_key('showTotal', False))
+
+ with it('should support showTotal="1" explicitly'):
+ xml = """
+
+ """
+ graph = parse_graph(xml)
+ expect(graph.show_total).to(be_true)
+ result = graph.process(50, 100)
+ expect(result).to(have_key('showTotal', True))
+
+ with it('should always include showTotal in response'):
+ xml = """
+
+ """
+ graph = parse_graph(xml)
+ result = graph.process(50, 100)
+ expect(result).to(have_key('showTotal'))
+ expect(result['showTotal']).to(be_true)
+
+ xml_false = """
+
+ """
+ graph_false = parse_graph(xml_false)
+ result_false = graph_false.process(50, 100)
+ expect(result_false).to(have_key('showTotal'))
+ expect(result_false['showTotal']).to(be_false)
+
with it("should parse a chart graph XML with type line"):
xml = """
diff --git a/spec/graph/processor_spec.py b/spec/graph/processor_spec.py
index 39bb155..8c81ec5 100644
--- a/spec/graph/processor_spec.py
+++ b/spec/graph/processor_spec.py
@@ -68,6 +68,7 @@ def get_graph_data(xml, model):
icon='slack',
suffix='kW',
type='indicatorField',
+ showTotal=True,
))
with it('should process indicator graph'):
@@ -91,6 +92,31 @@ def get_graph_data(xml, model):
type='indicator',
))
+ with it('should process indicatorField graph with showTotal="0"'):
+ xml = """
+
+
+
+ """
+ total_values = models['polissa'].data
+ t20A_values = [v for v in total_values if v['tarifa'][1] == "2.0A"]
+ g = parse_graph(xml)
+ result = g.process(
+ t20A_values,
+ fields=models['polissa'].fields,
+ total_values=total_values
+ )
+ expect(result).to(have_keys(
+ value=77.72,
+ percent=28.19,
+ total=275.72,
+ color='red',
+ icon='slack',
+ suffix='kW',
+ type='indicatorField',
+ showTotal=False,
+ ))
+
# Un test per quan el total sigui 0 no falli al calcular el percentatge
with it('should evaluate percent when total is 0'):
xml = """