diff --git a/bijoe/schemas.py b/bijoe/schemas.py index 27ee824..f5182f2 100644 --- a/bijoe/schemas.py +++ b/bijoe/schemas.py @@ -137,6 +137,12 @@ class Measure(Base): 'expression': str, } + @property + def default_value(self): + if self.type in ['integer', 'percent']: + return 0 + return None + class Dimension(Base): __slots__ = ['name', 'label', 'type', 'join', 'value', 'value_label', diff --git a/bijoe/visualization/utils.py b/bijoe/visualization/utils.py index 9762ae5..5258f72 100644 --- a/bijoe/visualization/utils.py +++ b/bijoe/visualization/utils.py @@ -181,7 +181,7 @@ class Visualization(object): return data def default_cell(self): - return MeasureCell(measure=self.measure, value=None) + return MeasureCell(measure=self.measure, value=self.measure.default_value) def table_2d(self): '''Layout data into 2d tables''' diff --git a/tests/test_schema1.py b/tests/test_schema1.py index 4decb0b..cb3cea6 100644 --- a/tests/test_schema1.py +++ b/tests/test_schema1.py @@ -192,11 +192,11 @@ def test_none_percent_json_data(schema1, app, admin): assert visu.json_data() == [ { 'coords': [{'value': u'2017'}, {'value': u'cat\xe92'}], - 'measures': [{'value': None}] + 'measures': [{'value': 0}] }, { 'coords': [{'value': u'2017'}, {'value': u'cat\xe93'}], - 'measures': [{'value': None}]}, + 'measures': [{'value': 0}]}, { 'coords': [{'value': u'2017'}, {'value': u'cat\xe91'}], 'measures': [{'value': 94.11764705882354}]},