Fix: handle max values of 0 in termgraph
authorAntoine Busque <abusque@efficios.com>
Fri, 19 Feb 2016 22:54:50 +0000 (17:54 -0500)
committerAntoine Busque <abusque@efficios.com>
Wed, 24 Feb 2016 23:24:03 +0000 (18:24 -0500)
Signed-off-by: Antoine Busque <abusque@efficios.com>
lttnganalyses/cli/termgraph.py

index 2ba614791f3153fa3a4ff4de0a7a9a81b80e8756..493c29af0d9da407060144f74eddd3eb9fb3463b 100644 (file)
@@ -138,7 +138,11 @@ class BarGraph(Graph):
         print(header)
 
     def _get_bar_str(self, datum):
-        bar_width = int(self.MAX_GRAPH_WIDTH * datum.value / self._max_value)
+        if self._max_value == 0:
+            bar_width = 0
+        else:
+            bar_width = int(self.MAX_GRAPH_WIDTH * datum.value /
+                            self._max_value)
         space_width = self.MAX_GRAPH_WIDTH - bar_width
         bar_str = self.BAR_CHAR * bar_width + ' ' * space_width
 
@@ -177,7 +181,10 @@ class FreqGraph(Graph):
 
     def _get_bar_str(self, datum):
         max_width = self.MAX_GRAPH_WIDTH - self.LOWER_BOUND_WIDTH
-        bar_width = int(max_width * datum.value / self._max_value)
+        if self._max_value == 0:
+            bar_width = 0
+        else:
+            bar_width = int(max_width * datum.value / self._max_value)
         space_width = max_width - bar_width
         bar_str = self.BAR_CHAR * bar_width + ' ' * space_width
 
This page took 0.024883 seconds and 5 git commands to generate.