- commit
- e6b68cf4953c80d14a690dc66855eb2ef26aa947
- parent
- 9eeaef1b21e4803b3340a98c707baa38670e276e
- Author
- Tobias Bengfort <bengfort@mpib-berlin.mpg.de>
- Date
- 2025-04-28 13:39
fix: deal with all-zero data
Diffstat
| M | simplecharts.py | 2 | ++ |
| A | tests/empty.json | 9 | +++++++++ |
| A | tests/empty_ColumnRenderer.svg | 27 | +++++++++++++++++++++++++++ |
| A | tests/empty_LineRenderer.svg | 30 | ++++++++++++++++++++++++++++++ |
| A | tests/empty_StackedAreaRenderer.svg | 30 | ++++++++++++++++++++++++++++++ |
| A | tests/empty_StackedColumnRenderer.svg | 27 | +++++++++++++++++++++++++++ |
6 files changed, 125 insertions, 0 deletions
diff --git a/simplecharts.py b/simplecharts.py
@@ -8,6 +8,8 @@ COLORS = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33'] 8 8 9 9 10 10 def round_max(value): -1 11 if value <= 0: -1 12 return 10 11 13 tail = 10 ** math.floor(math.log(value, 10)) 12 14 head = int(value / tail) + 1 13 15 if head & 1:
diff --git a/tests/empty.json b/tests/empty.json
@@ -0,0 +1,9 @@
-1 1 {
-1 2 "rows": [{
-1 3 "label": "Apples",
-1 4 "values": [0, 0, 0]
-1 5 }, {
-1 6 "label": "Oranges",
-1 7 "values": [0, 0, 0]
-1 8 }]
-1 9 }
diff --git a/tests/empty_ColumnRenderer.svg b/tests/empty_ColumnRenderer.svg
@@ -0,0 +1,27 @@ -1 1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg"> -1 2 <g role="table"> -1 3 <line stroke="#333" x1="0" x2="0" y1="0" y2="480" /> -1 4 <line stroke="#333" x1="0" x2="640" y1="480" y2="480" /> -1 5 <g aria-hidden="true"> -1 6 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="480">0</text> -1 7 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="240.0">5</text> -1 8 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="0">10</text> -1 9 </g> -1 10 <g role="row"> -1 11 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="160.0" y="490.0">Apples</text> -1 12 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="480.0" y="490.0">Oranges</text> -1 13 </g> -1 14 <g fill="#e41a1c" role="row" stroke="white"> -1 15 <rect height="0.0" role="cell" width="64.0" x="64.0" y="479.0" /> -1 16 <rect height="0.0" role="cell" width="64.0" x="384.0" y="479.0" /> -1 17 </g> -1 18 <g fill="#377eb8" role="row" stroke="white"> -1 19 <rect height="0.0" role="cell" width="64.0" x="128.0" y="479.0" /> -1 20 <rect height="0.0" role="cell" width="64.0" x="448.0" y="479.0" /> -1 21 </g> -1 22 <g fill="#4daf4a" role="row" stroke="white"> -1 23 <rect height="0.0" role="cell" width="64.0" x="192.0" y="479.0" /> -1 24 <rect height="0.0" role="cell" width="64.0" x="512.0" y="479.0" /> -1 25 </g> -1 26 </g> -1 27 </svg>
diff --git a/tests/empty_LineRenderer.svg b/tests/empty_LineRenderer.svg
@@ -0,0 +1,30 @@ -1 1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg"> -1 2 <g role="table"> -1 3 <line stroke="#333" x1="0" x2="0" y1="0" y2="480" /> -1 4 <line stroke="#333" x1="0" x2="640" y1="480" y2="480" /> -1 5 <g aria-hidden="true"> -1 6 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="480">0</text> -1 7 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="240.0">5</text> -1 8 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="0">10</text> -1 9 </g> -1 10 <g role="row"> -1 11 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="160.0" y="490.0">Apples</text> -1 12 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="480.0" y="490.0">Oranges</text> -1 13 </g> -1 14 <polyline fill="none" points="160,480 480,480" stroke="#e41a1c" /> -1 15 <polyline fill="none" points="160,480 480,480" stroke="#377eb8" /> -1 16 <polyline fill="none" points="160,480 480,480" stroke="#4daf4a" /> -1 17 <g fill="#e41a1c" role="row" stroke="white"> -1 18 <circle cx="160.0" cy="480.0" r="3" role="cell" /> -1 19 <circle cx="480.0" cy="480.0" r="3" role="cell" /> -1 20 </g> -1 21 <g fill="#377eb8" role="row" stroke="white"> -1 22 <circle cx="160.0" cy="480.0" r="3" role="cell" /> -1 23 <circle cx="480.0" cy="480.0" r="3" role="cell" /> -1 24 </g> -1 25 <g fill="#4daf4a" role="row" stroke="white"> -1 26 <circle cx="160.0" cy="480.0" r="3" role="cell" /> -1 27 <circle cx="480.0" cy="480.0" r="3" role="cell" /> -1 28 </g> -1 29 </g> -1 30 </svg>
diff --git a/tests/empty_StackedAreaRenderer.svg b/tests/empty_StackedAreaRenderer.svg
@@ -0,0 +1,30 @@ -1 1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg"> -1 2 <g role="table"> -1 3 <line stroke="#333" x1="0" x2="0" y1="0" y2="480" /> -1 4 <line stroke="#333" x1="0" x2="640" y1="480" y2="480" /> -1 5 <g aria-hidden="true"> -1 6 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="480">0</text> -1 7 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="240.0">5</text> -1 8 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="0">10</text> -1 9 </g> -1 10 <g role="row"> -1 11 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="160.0" y="490.0">Apples</text> -1 12 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="480.0" y="490.0">Oranges</text> -1 13 </g> -1 14 <polyline fill="#e41a1c" points="160,479 480,479 480,479 160,479" stroke="white" /> -1 15 <polyline fill="#377eb8" points="160,479 480,479 480,479 160,479" stroke="white" /> -1 16 <polyline fill="#4daf4a" points="160,479 480,479 480,479 160,479" stroke="white" /> -1 17 <g fill="#e41a1c" role="row" stroke="white"> -1 18 <circle cx="160.0" cy="479.0" r="3" role="cell" /> -1 19 <circle cx="480.0" cy="479.0" r="3" role="cell" /> -1 20 </g> -1 21 <g fill="#377eb8" role="row" stroke="white"> -1 22 <circle cx="160.0" cy="479.0" r="3" role="cell" /> -1 23 <circle cx="480.0" cy="479.0" r="3" role="cell" /> -1 24 </g> -1 25 <g fill="#4daf4a" role="row" stroke="white"> -1 26 <circle cx="160.0" cy="479.0" r="3" role="cell" /> -1 27 <circle cx="480.0" cy="479.0" r="3" role="cell" /> -1 28 </g> -1 29 </g> -1 30 </svg>
diff --git a/tests/empty_StackedColumnRenderer.svg b/tests/empty_StackedColumnRenderer.svg
@@ -0,0 +1,27 @@ -1 1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg"> -1 2 <g role="table"> -1 3 <line stroke="#333" x1="0" x2="0" y1="0" y2="480" /> -1 4 <line stroke="#333" x1="0" x2="640" y1="480" y2="480" /> -1 5 <g aria-hidden="true"> -1 6 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="480">0</text> -1 7 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="240.0">5</text> -1 8 <text dominant-baseline="middle" fill="#333" text-anchor="end" x="-4" y="0">10</text> -1 9 </g> -1 10 <g role="row"> -1 11 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="160.0" y="490.0">Apples</text> -1 12 <text dominant-baseline="middle" fill="#333" role="columnheader" text-anchor="middle" x="480.0" y="490.0">Oranges</text> -1 13 </g> -1 14 <g fill="#e41a1c" role="row" stroke="white"> -1 15 <rect height="0.0" role="cell" width="106.66666666666667" x="106.66666666666666" y="479.0" /> -1 16 <rect height="0.0" role="cell" width="106.66666666666667" x="426.6666666666667" y="479.0" /> -1 17 </g> -1 18 <g fill="#377eb8" role="row" stroke="white"> -1 19 <rect height="0.0" role="cell" width="106.66666666666667" x="106.66666666666666" y="479.0" /> -1 20 <rect height="0.0" role="cell" width="106.66666666666667" x="426.6666666666667" y="479.0" /> -1 21 </g> -1 22 <g fill="#4daf4a" role="row" stroke="white"> -1 23 <rect height="0.0" role="cell" width="106.66666666666667" x="106.66666666666666" y="479.0" /> -1 24 <rect height="0.0" role="cell" width="106.66666666666667" x="426.6666666666667" y="479.0" /> -1 25 </g> -1 26 </g> -1 27 </svg>