|
15 | 15 | import os
|
16 | 16 | import re
|
17 | 17 |
|
18 |
| -from math_fns import find_max |
19 |
| -from math_fns import find_min |
20 |
| -from math_fns import normalize |
21 |
| - |
22 |
| -VERSION = "0.4.1" |
| 18 | +VERSION = "0.4.2" |
23 | 19 |
|
24 | 20 | init()
|
25 | 21 |
|
@@ -134,6 +130,43 @@ def main():
|
134 | 130 | chart(colors, data, args, labels)
|
135 | 131 |
|
136 | 132 |
|
| 133 | +def find_min(data): |
| 134 | + """Return the minimum value in sublist of list.""" |
| 135 | + return min([min(sublist) for sublist in data]) |
| 136 | + |
| 137 | + |
| 138 | +def find_max(data): |
| 139 | + """Return the maximum value in sublist of list.""" |
| 140 | + return max([max(sublist) for sublist in data]) |
| 141 | + |
| 142 | + |
| 143 | +def normalize(data, width): |
| 144 | + """Normalize the data and return it.""" |
| 145 | + |
| 146 | + # We offset by the minimum if there's a negative. |
| 147 | + data_offset = [] |
| 148 | + min_datum = find_min(data) |
| 149 | + if min_datum < 0: |
| 150 | + min_datum = abs(min_datum) |
| 151 | + for datum in data: |
| 152 | + data_offset.append([d + min_datum for d in datum]) |
| 153 | + else: |
| 154 | + data_offset = data |
| 155 | + min_datum = find_min(data_offset) |
| 156 | + max_datum = find_max(data_offset) |
| 157 | + |
| 158 | + # max_dat / width is the value for a single tick. norm_factor is the |
| 159 | + # inverse of this value |
| 160 | + # If you divide a number to the value of single tick, you will find how |
| 161 | + # many ticks it does contain basically. |
| 162 | + norm_factor = width / float(max_datum) |
| 163 | + normal_data = [] |
| 164 | + for datum in data_offset: |
| 165 | + normal_data.append([v * norm_factor for v in datum]) |
| 166 | + |
| 167 | + return normal_data |
| 168 | + |
| 169 | + |
137 | 170 | def find_max_label_length(labels):
|
138 | 171 | """Return the maximum length for the labels."""
|
139 | 172 | length = 0
|
|
0 commit comments