Repository: mkaz/termgraph

Issue:
ZeroDivisionError on empty data
# Background

When passing in data containing all 0's termgraph will return a ZeroDivisionError. Ideally termgraph should accept this value and return an empty graph. 

## Example Code

```
termgraph.chart(
    colors=None,
    data=[0, 0]
    args={'width': 100, 'format': '{:,}', 'suffix': '', 'no_labels': False, 'no_values': False, 'vertical': False, 'stacked': False, 'histogram': False, 'different_scale': False},
    labels=['iOS', 'Android']
)
```

## Error Message

```
ERROR: Problem running script: Traceback (most recent call last):
  File "/../main.py", line 523, in <module>
    cli_handler()
  File "/.../lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/.../lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/.../lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/.../lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/../main.py", line 194, in cli_handler
    main(
  File "/.../main.py", line 449, in main
    termgraph.chart(
  File "/.../lib/python3.8/site-packages/termgraph/termgraph.py", line 485, in chart
    normal_dat = normalize(data, args["width"])
  File "/.../lib/python3.8/site-packages/termgraph/termgraph.py", line 162, in normalize
    norm_factor = width / float(max_datum)
ZeroDivisionError: float division by zero
```

Discussion:

Patch:
diff --git a/termgraph/termgraph.py b/termgraph/termgraph.py
index bacc4c0..ee2c796 100755
--- a/termgraph/termgraph.py
+++ b/termgraph/termgraph.py
@@ -165,6 +165,9 @@ def normalize(data: List, width: int) -> List:
     min_datum = find_min(data_offset)
     max_datum = find_max(data_offset)
 
+    if min_datum == max_datum:
+        return data_offset
+
     # max_dat / width is the value for a single tick. norm_factor is the
     # inverse of this value
     # If you divide a number to the value of single tick, you will find how


Test patch:
diff --git a/tests/test_termgraph.py b/tests/test_termgraph.py
index 79d9a9a..bc3b8a8 100644
--- a/tests/test_termgraph.py
+++ b/tests/test_termgraph.py
@@ -47,6 +47,20 @@ def test_normalize_returns_correct_results():
     assert results == expected
 
 
+def test_normalize_with_all_zeros_returns_correct_results():
+    expected = [
+        [0],
+        [0],
+        [0],
+        [0],
+        [0],
+        [0],
+        [0],
+    ]
+    results = tg.normalize([[0], [0], [0], [0], [0], [0], [0]], 50)
+    assert results == expected
+
+
 def test_normalize_with_negative_datapoint_returns_correct_results():
     expected = [
         [18.625354066709058],