summaryrefslogtreecommitdiff
path: root/board.py
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-01-15 23:59:59 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-01-15 23:59:59 (GMT)
commit169bab9bffb4b987e87448525e59813a658edb76 (patch)
tree65838243872e375e618f424827397ec6a5c41f3b /board.py
parent15b01266e1d7e193280658f300fd7d95bd918626 (diff)
Written a first usable version.HEADmaster
Diffstat (limited to 'board.py')
-rw-r--r--board.py159
1 files changed, 97 insertions, 62 deletions
diff --git a/board.py b/board.py
index aeda474..35e5735 100644
--- a/board.py
+++ b/board.py
@@ -99,8 +99,8 @@ class DynamicFlyer:
hmargin = self._width * 0.1
vmargin = self._square * 0.1
- width = self._width - 2 * hmargin
- height = self._square - 2 * vmargin
+ width = self._width - 2 * hmargin - 10
+ height = self._square - 2 * vmargin - 10
self._cr.save()
@@ -108,37 +108,40 @@ class DynamicFlyer:
# Find the max and normalize
+ min_vol = min(data.values())
max_vol = max(data.values())
+ diff_vol = max_vol - min_vol
+
sx = width / (end - start)
- sy = height / max_vol
+ sy = height / diff_vol
+
+ # Display volumes
self._cr.save()
self._cr.scale(sx, sy)
- # Display volumes
-
first = min(data.keys())
if created:
- self._cr.move_to(first, max_vol)
+ self._cr.move_to(first - start, diff_vol)
else:
- self._cr.move_to(0, max_vol)
+ self._cr.move_to(0, diff_vol)
self._cr.line_to(0, max_vol - data[first])
for time in sorted(data.keys()):
vol = data[time]
- self._cr.line_to(time, max_vol - vol)
+ self._cr.line_to(time - start, max_vol - vol)
last = max(data.keys())
- self._cr.line_to(last, max_vol)
+ self._cr.line_to(last - start, diff_vol)
self._cr.close_path()
@@ -146,19 +149,9 @@ class DynamicFlyer:
self._cr.fill_preserve()
self._cr.set_source_rgba(*color, 1.0)
- self._cr.set_line_width(1 / sx)
+ self._cr.set_line_width(1 / (sx if sx > sy else sy))
self._cr.stroke()
- # Display commits
-
- for time, vol in data.items():
-
- self._cr.rectangle(time - 2 / sx, max_vol - vol - 2 / sy, 4 / sx, 4 / sy)
-
- self._cr.set_source_rgba(*color, 1.0)
- self._cr.set_line_width(0.5)
- self._cr.fill()
-
self._cr.restore()
# Display the borders
@@ -170,26 +163,52 @@ class DynamicFlyer:
self._cr.set_source_rgba(*self._forecolor, 0.7)
self._cr.stroke()
- self._cr.move_to(0, 0)
- self._cr.line_to(-4, 10)
- self._cr.line_to(4, 10)
+ self._cr.move_to(0, -10)
+ self._cr.line_to(-4, 0)
+ self._cr.line_to(4, 0)
self._cr.set_source_rgba(*self._forecolor, 1.0)
self._cr.fill()
- self._cr.move_to(width, height)
- self._cr.line_to(width - 10, height - 4)
- self._cr.line_to(width - 10, height + 4)
+ self._cr.move_to(width + 10, height)
+ self._cr.line_to(width, height - 4)
+ self._cr.line_to(width, height + 4)
self._cr.set_source_rgba(*self._forecolor, 1.0)
self._cr.fill()
+ # Display some time marks
+
+ unit = width / 12
+
+ for i in range(11):
+
+ self._cr.move_to((i + 1) * unit, height - 2)
+ self._cr.line_to((i + 1) * unit, height + 2)
+
+ self._cr.set_source_rgba(*self._forecolor, 1.0)
+ self._cr.stroke()
+
+ # Display commits
+
+ self._cr.save()
+
+ self._cr.scale(sx, sy)
+
+ for time, vol in data.items():
+
+ self._cr.rectangle(time - start - 2 / sx, max_vol - vol - 2 / sy, 4 / sx, 4 / sy)
+
+ self._cr.set_source_rgba(*color, 1.0)
+ self._cr.fill()
+
self._cr.restore()
# Print a caption as explaination
+ self._cr.restore()
+
count = len(data.values())
- min_vol = min(data.values())
unit = ''
@@ -232,7 +251,7 @@ class DynamicFlyer:
self._cr.restore()
- def _render_pie(self, title, data, colors):
+ def _render_pie(self, title, data):
"""Render a pie chart."""
cx = self._square / 2
@@ -249,10 +268,12 @@ class DynamicFlyer:
for k, v in data.items():
- stats.append((v, k))
+ val, color = v
+
+ stats.append((val, k, color))
count += 1
- total += v
+ total += val
stats = sorted(stats)
@@ -260,33 +281,38 @@ class DynamicFlyer:
done = 0
- init_angle = - (stats[0][0] * math.pi) / (2 * total)
+ init_angle = - (stats[0][0] * 2 * math.pi) / (total * 2)
last_angle = init_angle
for stat in stats:
- angle1 = last_angle
+ value, _, color = stat
- if (done + 1) == count:
- angle2 = init_angle
+ if value > 0:
- else:
- angle2 = angle1 + (stat[0] * math.pi) / total
+ angle1 = last_angle
- self._cr.move_to(cx, cy)
- self._cr.arc(cx, cy, radius, angle1, angle2)
- self._cr.line_to(cx, cy)
+ if (done + 1) == count:
+ angle2 = init_angle if init_angle != 0 else 2 * math.pi
- self._cr.set_source_rgba(*colors[done], 0.5)
- self._cr.fill_preserve()
+ else:
+ angle2 = angle1 + (value * 2 * math.pi) / total
- self._cr.set_source_rgba(*self._backcolor, 1.0)
- self._cr.set_line_width(2)
- self._cr.stroke()
+ self._cr.move_to(cx, cy)
+ self._cr.arc(cx, cy, radius, angle1, angle2)
+ self._cr.line_to(cx, cy)
+
+ self._cr.set_source_rgba(*color, 0.5)
+ self._cr.fill_preserve()
+
+ self._cr.set_source_rgba(*self._backcolor, 1.0)
+ self._cr.set_line_width(2)
+ self._cr.stroke()
+
+ last_angle = angle2
done += 1
- last_angle = angle2
done = 0
@@ -294,22 +320,27 @@ class DynamicFlyer:
for stat in stats:
- angle1 = last_angle
+ value, _, color = stat
- if (done + 1) == count:
- angle2 = init_angle
+ if value > 0:
- else:
- angle2 = angle1 + (stat[0] * math.pi) / total
+ angle1 = last_angle
- self._cr.arc(cx, cy, radius, angle1, angle2)
+ if (done + 1) == count:
+ angle2 = init_angle if init_angle != 0 else 2 * math.pi
- self._cr.set_source_rgba(*colors[done], 1.0)
- self._cr.set_line_width(10)
- self._cr.stroke()
+ else:
+ angle2 = angle1 + (value * 2 * math.pi) / total
+
+ self._cr.arc(cx, cy, radius, angle1, angle2)
+
+ self._cr.set_source_rgba(*color, 1.0)
+ self._cr.set_line_width(10)
+ self._cr.stroke()
+
+ last_angle = angle2
done += 1
- last_angle = angle2
# Printing the title
@@ -346,7 +377,9 @@ class DynamicFlyer:
for stat in stats:
- x_off, y_off, tw, th = self._cr.text_extents(stat[1])[:4]
+ _, name, _ = stat
+
+ x_off, y_off, tw, th = self._cr.text_extents(name)[:4]
if full_width > 0:
full_width += self._caption_sep
@@ -365,7 +398,9 @@ class DynamicFlyer:
for stat in stats:
- x_off, y_off, tw, th = self._cr.text_extents(stat[1])[:4]
+ _, name, color = stat
+
+ x_off, y_off, tw, th = self._cr.text_extents(name)[:4]
self._cr.save()
@@ -378,10 +413,10 @@ class DynamicFlyer:
self._cr.rectangle(0, top, self._caption_width, self._caption_width / 2)
- self._cr.set_source_rgba(*colors[done], 0.7)
+ self._cr.set_source_rgba(*color, 0.7)
self._cr.fill_preserve()
- self._cr.set_source_rgba(*colors[done], 1.0)
+ self._cr.set_source_rgba(*color, 1.0)
self._cr.set_line_width(1)
self._cr.stroke()
@@ -391,7 +426,7 @@ class DynamicFlyer:
self._cr.set_source_rgba(*self._forecolor, 1.0)
- self._cr.show_text(stat[1])
+ self._cr.show_text(name)
self._cr.restore()
@@ -400,12 +435,12 @@ class DynamicFlyer:
done += 1
- def render_pie(self, title, data, colors):
+ def render_pie(self, title, data):
"""Render a pie chart."""
self._book_room(self._square, self._square)
- self._render_pie(title, data, colors)
+ self._render_pie(title, data)
self._cr.restore()