- commit
- a9eb4705bf26f1a717a080325d3ef7eb39941fc4
- parent
- 0da1f1902e2a2011b08330b680510d424388e645
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-02-20 09:22
use polyline instead of path (simpler)
Diffstat
| M | simplecharts.py | 12 | +++++------- |
| M | tests/no-legend_LineRenderer.svg | 6 | +++--- |
| M | tests/no-legend_StackedAreaRenderer.svg | 6 | +++--- |
| M | tests/simple_LineRenderer.svg | 6 | +++--- |
| M | tests/simple_StackedAreaRenderer.svg | 6 | +++--- |
| M | tests/single_LineRenderer.svg | 2 | +- |
| M | tests/single_StackedAreaRenderer.svg | 2 | +- |
7 files changed, 19 insertions, 21 deletions
diff --git a/simplecharts.py b/simplecharts.py
@@ -79,11 +79,9 @@ class BaseRenderer: 79 79 content = self.element('title', escape(str(title))) 80 80 return self.element('circle', content, cx=x, cy=y, r=radius, **kwargs) 81 8182 -1 def path(self, points, **kwargs):83 -1 d = 'M {},{} L'.format(*points[0])84 -1 for x, y in points[1:]:85 -1 d += ' {},{}'.format(x, y)86 -1 return self.element('path', d=d, **kwargs)-1 82 def polyline(self, points, **kwargs): -1 83 d = ' '.join('{},{}'.format(*p) for p in points) -1 84 return self.element('polyline', points=d, **kwargs) 87 85 88 86 def get_title(self, rows, legend, i, j): 89 87 return rows[i]['values'][j] @@ -268,7 +266,7 @@ class LineRenderer(BaseRenderer): 268 266 dots += self.element( 269 267 'g', group, fill=self.get_color(j), stroke='white', role='row' 270 268 )271 -1 s += self.path(points, fill='none', stroke=self.get_color(j))-1 269 s += self.polyline(points, fill='none', stroke=self.get_color(j)) 272 270 s += dots 273 271 return s 274 272 @@ -298,7 +296,7 @@ class StackedAreaRenderer(BaseRenderer): 298 296 dots += self.element( 299 297 'g', group, fill=self.get_color(j), stroke='white', role='row' 300 298 )301 -1 s += self.path([-1 299 s += self.polyline([ 302 300 (x, self.height - y) for x, y in points + list(reversed(prev)) 303 301 ], fill=self.get_color(j), stroke='white') 304 302 prev = points
diff --git a/tests/no-legend_LineRenderer.svg b/tests/no-legend_LineRenderer.svg
@@ -13,9 +13,9 @@ 13 13 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="400.0" y="490.0">Pears</text> 14 14 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="560.0" y="490.0">Bananas</text> 15 15 </g>16 -1 <path d="M 80.0,240.0 L 240.0,160.0 400.0,160.0 560.0,80.0" fill="none" stroke="#e41a1c" />17 -1 <path d="M 80.0,320.0 L 240.0,320.0 400.0,240.0 560.0,400.0" fill="none" stroke="#377eb8" />18 -1 <path d="M 80.0,80.0 L 240.0,240.0 400.0,160.0 560.0,320.0" fill="none" stroke="#4daf4a" />-1 16 <polyline fill="none" points="80.0,240.0 240.0,160.0 400.0,160.0 560.0,80.0" stroke="#e41a1c" /> -1 17 <polyline fill="none" points="80.0,320.0 240.0,320.0 400.0,240.0 560.0,400.0" stroke="#377eb8" /> -1 18 <polyline fill="none" points="80.0,80.0 240.0,240.0 400.0,160.0 560.0,320.0" stroke="#4daf4a" /> 19 19 <g fill="#e41a1c" role="row" stroke="white"> 20 20 <circle cx="80.0" cy="240.0" r="3" role="cell"> 21 21 <title>3</title>
diff --git a/tests/no-legend_StackedAreaRenderer.svg b/tests/no-legend_StackedAreaRenderer.svg
@@ -13,9 +13,9 @@ 13 13 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="400.0" y="490.0">Pears</text> 14 14 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="560.0" y="490.0">Bananas</text> 15 15 </g>16 -1 <path d="M 80.0,407.0 L 240.0,383.0 400.0,383.0 560.0,359.0 560.0,479 400.0,479 240.0,479 80.0,479" fill="#e41a1c" stroke="white" />17 -1 <path d="M 80.0,359.0 L 240.0,335.0 400.0,311.0 560.0,335.0 560.0,359.0 400.0,383.0 240.0,383.0 80.0,407.0" fill="#377eb8" stroke="white" />18 -1 <path d="M 80.0,239.0 L 240.0,263.0 400.0,215.0 560.0,287.0 560.0,335.0 400.0,311.0 240.0,335.0 80.0,359.0" fill="#4daf4a" stroke="white" />-1 16 <polyline fill="#e41a1c" points="80.0,407.0 240.0,383.0 400.0,383.0 560.0,359.0 560.0,479 400.0,479 240.0,479 80.0,479" stroke="white" /> -1 17 <polyline fill="#377eb8" points="80.0,359.0 240.0,335.0 400.0,311.0 560.0,335.0 560.0,359.0 400.0,383.0 240.0,383.0 80.0,407.0" stroke="white" /> -1 18 <polyline fill="#4daf4a" points="80.0,239.0 240.0,263.0 400.0,215.0 560.0,287.0 560.0,335.0 400.0,311.0 240.0,335.0 80.0,359.0" stroke="white" /> 19 19 <g fill="#e41a1c" role="row" stroke="white"> 20 20 <circle cx="80.0" cy="407.0" r="3" role="cell"> 21 21 <title>3</title>
diff --git a/tests/simple_LineRenderer.svg b/tests/simple_LineRenderer.svg
@@ -22,9 +22,9 @@ 22 22 <rect fill="#4daf4a" height="10" width="10" x="592" y="-15.0" /> 23 23 <text dominant-baseline="middle" fill="#333" x="606" y="-10.0">Joe</text> 24 24 </g>25 -1 <path d="M 80.0,240.0 L 240.0,160.0 400.0,160.0 560.0,80.0" fill="none" stroke="#e41a1c" />26 -1 <path d="M 80.0,320.0 L 240.0,320.0 400.0,240.0 560.0,400.0" fill="none" stroke="#377eb8" />27 -1 <path d="M 80.0,80.0 L 240.0,240.0 400.0,160.0 560.0,320.0" fill="none" stroke="#4daf4a" />-1 25 <polyline fill="none" points="80.0,240.0 240.0,160.0 400.0,160.0 560.0,80.0" stroke="#e41a1c" /> -1 26 <polyline fill="none" points="80.0,320.0 240.0,320.0 400.0,240.0 560.0,400.0" stroke="#377eb8" /> -1 27 <polyline fill="none" points="80.0,80.0 240.0,240.0 400.0,160.0 560.0,320.0" stroke="#4daf4a" /> 28 28 <g fill="#e41a1c" role="row" stroke="white"> 29 29 <circle cx="80.0" cy="240.0" r="3" role="cell"> 30 30 <title>3</title>
diff --git a/tests/simple_StackedAreaRenderer.svg b/tests/simple_StackedAreaRenderer.svg
@@ -22,9 +22,9 @@ 22 22 <rect fill="#4daf4a" height="10" width="10" x="592" y="-15.0" /> 23 23 <text dominant-baseline="middle" fill="#333" x="606" y="-10.0">Joe</text> 24 24 </g>25 -1 <path d="M 80.0,407.0 L 240.0,383.0 400.0,383.0 560.0,359.0 560.0,479 400.0,479 240.0,479 80.0,479" fill="#e41a1c" stroke="white" />26 -1 <path d="M 80.0,359.0 L 240.0,335.0 400.0,311.0 560.0,335.0 560.0,359.0 400.0,383.0 240.0,383.0 80.0,407.0" fill="#377eb8" stroke="white" />27 -1 <path d="M 80.0,239.0 L 240.0,263.0 400.0,215.0 560.0,287.0 560.0,335.0 400.0,311.0 240.0,335.0 80.0,359.0" fill="#4daf4a" stroke="white" />-1 25 <polyline fill="#e41a1c" points="80.0,407.0 240.0,383.0 400.0,383.0 560.0,359.0 560.0,479 400.0,479 240.0,479 80.0,479" stroke="white" /> -1 26 <polyline fill="#377eb8" points="80.0,359.0 240.0,335.0 400.0,311.0 560.0,335.0 560.0,359.0 400.0,383.0 240.0,383.0 80.0,407.0" stroke="white" /> -1 27 <polyline fill="#4daf4a" points="80.0,239.0 240.0,263.0 400.0,215.0 560.0,287.0 560.0,335.0 400.0,311.0 240.0,335.0 80.0,359.0" stroke="white" /> 28 28 <g fill="#e41a1c" role="row" stroke="white"> 29 29 <circle cx="80.0" cy="407.0" r="3" role="cell"> 30 30 <title>3</title>
diff --git a/tests/single_LineRenderer.svg b/tests/single_LineRenderer.svg
@@ -13,7 +13,7 @@ 13 13 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="400.0" y="490.0">Pears</text> 14 14 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="560.0" y="490.0">Bananas</text> 15 15 </g>16 -1 <path d="M 80.0,240.0 L 240.0,160.0 400.0,160.0 560.0,80.0" fill="none" stroke="#e41a1c" />-1 16 <polyline fill="none" points="80.0,240.0 240.0,160.0 400.0,160.0 560.0,80.0" stroke="#e41a1c" /> 17 17 <g fill="#e41a1c" role="row" stroke="white"> 18 18 <circle cx="80.0" cy="240.0" r="3" role="cell"> 19 19 <title>3</title>
diff --git a/tests/single_StackedAreaRenderer.svg b/tests/single_StackedAreaRenderer.svg
@@ -13,7 +13,7 @@ 13 13 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="400.0" y="490.0">Pears</text> 14 14 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="560.0" y="490.0">Bananas</text> 15 15 </g>16 -1 <path d="M 80.0,239.0 L 240.0,159.0 400.0,159.0 560.0,79.0 560.0,479 400.0,479 240.0,479 80.0,479" fill="#e41a1c" stroke="white" />-1 16 <polyline fill="#e41a1c" points="80.0,239.0 240.0,159.0 400.0,159.0 560.0,79.0 560.0,479 400.0,479 240.0,479 80.0,479" stroke="white" /> 17 17 <g fill="#e41a1c" role="row" stroke="white"> 18 18 <circle cx="80.0" cy="239.0" r="3" role="cell"> 19 19 <title>3</title>