|
2 | 2 | import matplotlib.pyplot as plt |
3 | 3 | from floppy.reportWidget import template |
4 | 4 | from numpy import array, arange |
| 5 | +import threading |
| 6 | +import time |
5 | 7 | import os |
6 | 8 |
|
7 | 9 | _pointCache = None |
| 10 | +plotting = False |
8 | 11 |
|
9 | 12 | @template |
10 | 13 | def plotTemplate(data, cache, fileBase): |
@@ -117,34 +120,72 @@ def programTemplate(data, cache, fileBase): |
117 | 120 | name, varType, value in data['outputs']]), |
118 | 121 | stdout=data['stdout'].replace('\\n', '<br>')) |
119 | 122 |
|
| 123 | + |
| 124 | +def plotBars(points, cache, fileName): |
| 125 | + globals()['_pointCache'] = cache |
| 126 | + # thisPlot = time.time() |
| 127 | + # try: |
| 128 | + # if thisPlot - lastPlot < 5: |
| 129 | + # return |
| 130 | + # except: |
| 131 | + # lastPlot = thisPlot |
| 132 | + # return |
| 133 | + # lastPlot = thisPlot |
| 134 | + x, y = zip(*points) |
| 135 | + n_groups = len(x) |
| 136 | + fig, ax = plt.subplots() |
| 137 | + index = arange(n_groups) |
| 138 | + bar_width = 0.35 |
| 139 | + opacity = .4 |
| 140 | + rects1 = plt.bar(index, x, bar_width, |
| 141 | + alpha=opacity, |
| 142 | + color='b', |
| 143 | + label='A') |
| 144 | + rects2 = plt.bar(index + bar_width, y, bar_width, |
| 145 | + alpha=opacity, |
| 146 | + color='r', |
| 147 | + label='B') |
| 148 | + plt.xticks(index+bar_width) |
| 149 | + plt.legend() |
| 150 | + plt.tight_layout() |
| 151 | + savefig(fileName) |
| 152 | + global plotting |
| 153 | + plotting = False |
| 154 | + |
120 | 155 | @template |
121 | 156 | def plotBarsGroupedTemplate(data, cache, fileBase): |
122 | 157 | points = data['points'] |
123 | 158 | fileName = fileBase+'/_ppy_{}.svg'.format(data['ID']) |
124 | 159 | #fileName = os.path.join(fileBase, '_ppy_{}.svg'.format(data['ID'])) |
125 | 160 | # fileName = '_ppy_{}.svg'.format(data['ID']) |
126 | 161 | # print(fileName) |
127 | | - |
| 162 | + global plotting |
128 | 163 | if not points == globals()['_pointCache'] and points: |
129 | | - x, y = zip(*points) |
130 | | - n_groups = len(x) |
131 | | - fig, ax = plt.subplots() |
132 | | - index = arange(n_groups) |
133 | | - bar_width = 0.35 |
134 | | - opacity = .4 |
135 | | - rects1 = plt.bar(index, x, bar_width, |
136 | | - alpha=opacity, |
137 | | - color='b', |
138 | | - label='A') |
139 | | - rects2 = plt.bar(index + bar_width, y, bar_width, |
140 | | - alpha=opacity, |
141 | | - color='r', |
142 | | - label='B') |
143 | | - plt.xticks(index+bar_width) |
144 | | - plt.legend() |
145 | | - plt.tight_layout() |
146 | | - savefig(fileName) |
147 | | - globals()['_pointCache'] = cache[:] |
| 164 | + if not plotting: |
| 165 | + plotting = True |
| 166 | + threading.Thread(target=plotBars, args=(points, cache, fileName)).start() |
| 167 | + else: |
| 168 | + return None |
| 169 | + # x, y = zip(*points) |
| 170 | + # n_groups = len(x) |
| 171 | + # fig, ax = plt.subplots() |
| 172 | + # index = arange(n_groups) |
| 173 | + # bar_width = 0.35 |
| 174 | + # opacity = .4 |
| 175 | + # rects1 = plt.bar(index, x, bar_width, |
| 176 | + # alpha=opacity, |
| 177 | + # color='b', |
| 178 | + # label='A') |
| 179 | + # rects2 = plt.bar(index + bar_width, y, bar_width, |
| 180 | + # alpha=opacity, |
| 181 | + # color='r', |
| 182 | + # label='B') |
| 183 | + # plt.xticks(index+bar_width) |
| 184 | + # plt.legend() |
| 185 | + # plt.tight_layout() |
| 186 | + # savefig(fileName) |
| 187 | + # globals()['_pointCache'] = cache[:] |
| 188 | + |
148 | 189 | fileName = '_ppy_{}.svg'.format(data['ID']) |
149 | 190 | return """<h1 id="head">{nodeName} -- {nodeID}</h1> |
150 | 191 | <style> |
|
0 commit comments