simplecharts

SVG charts without dependencies
git clone https://git.ce9e.org/simplecharts.git

commit
22e222d77e19e3bc6427bbf2798f438eb6005951
parent
ed5604afb5db723055a8a31f60a2b782dea8b8d6
Author
Tobias Bengfort <bengfort@mpib-berlin.mpg.de>
Date
2026-04-13 10:37
support dark color scheme

Diffstat

M simplecharts.py 18 +++++++++++++-----
M tests/empty_ColumnRenderer.svg 6 ++++++
M tests/empty_LineRenderer.svg 6 ++++++
M tests/empty_StackedAreaRenderer.svg 6 ++++++
M tests/empty_StackedColumnRenderer.svg 6 ++++++
M tests/float_ColumnRenderer.svg 6 ++++++
M tests/float_LineRenderer.svg 6 ++++++
M tests/float_StackedAreaRenderer.svg 6 ++++++
M tests/float_StackedColumnRenderer.svg 6 ++++++
M tests/long_ColumnRenderer.svg 6 ++++++
M tests/long_LineRenderer.svg 6 ++++++
M tests/long_StackedAreaRenderer.svg 6 ++++++
M tests/long_StackedColumnRenderer.svg 6 ++++++
M tests/no-legend_ColumnRenderer.svg 6 ++++++
M tests/no-legend_LineRenderer.svg 6 ++++++
M tests/no-legend_StackedAreaRenderer.svg 6 ++++++
M tests/no-legend_StackedColumnRenderer.svg 6 ++++++
M tests/simple_ColumnRenderer.svg 6 ++++++
M tests/simple_LineRenderer.svg 6 ++++++
M tests/simple_StackedAreaRenderer.svg 6 ++++++
M tests/simple_StackedColumnRenderer.svg 6 ++++++
M tests/single_ColumnRenderer.svg 6 ++++++
M tests/single_LineRenderer.svg 6 ++++++
M tests/single_StackedAreaRenderer.svg 6 ++++++
M tests/single_StackedColumnRenderer.svg 6 ++++++

25 files changed, 157 insertions, 5 deletions


diff --git a/simplecharts.py b/simplecharts.py

@@ -91,6 +91,13 @@ class BaseRenderer:
   91    91     def get_title(self, rows, legend, i, j):
   92    92         return rows[i]['values'][j]
   93    93 
   -1    94     def render_style(self):
   -1    95         style = '@media (prefers-color-scheme: dark) {\n'
   -1    96         style += f'\t[fill="{self.ui_color}"] {{fill: white}}\n'
   -1    97         style += f'\t[stroke="{self.ui_color}"] {{stroke: white}}\n'
   -1    98         style += '}'
   -1    99         return self.element('style', style)
   -1   100 
   94   101     def render_axes(self, rows, max_value):
   95   102         s = ''
   96   103         s += self.line(0, 0, 0, self.height, self.ui_color)
@@ -198,12 +205,13 @@ class BaseRenderer:
  198   205         max_value = round_max(max_value)
  199   206 
  200   207         legend = data.get('legend', [])
  201    -1         content = ''
  202    -1         content += self.render_axes(data['rows'], max_value)
   -1   208         inner = self.render_axes(data['rows'], max_value)
  203   209         if legend:
  204    -1             content += self.render_legend(legend)
  205    -1         content += self.render_rows(data['rows'], legend, max_value)
  206    -1         content = self.element('g', content, role='table')
   -1   210             inner += self.render_legend(legend)
   -1   211         inner += self.render_rows(data['rows'], legend, max_value)
   -1   212 
   -1   213         content = self.render_style()
   -1   214         content += self.element('g', inner, role='table')
  207   215 
  208   216         return self.element(
  209   217             'svg',

diff --git a/tests/empty_ColumnRenderer.svg b/tests/empty_ColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/empty_LineRenderer.svg b/tests/empty_LineRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/empty_StackedAreaRenderer.svg b/tests/empty_StackedAreaRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/empty_StackedColumnRenderer.svg b/tests/empty_StackedColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/float_ColumnRenderer.svg b/tests/float_ColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/float_LineRenderer.svg b/tests/float_LineRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/float_StackedAreaRenderer.svg b/tests/float_StackedAreaRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/float_StackedColumnRenderer.svg b/tests/float_StackedColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/long_ColumnRenderer.svg b/tests/long_ColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/long_LineRenderer.svg b/tests/long_LineRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/long_StackedAreaRenderer.svg b/tests/long_StackedAreaRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/long_StackedColumnRenderer.svg b/tests/long_StackedColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/no-legend_ColumnRenderer.svg b/tests/no-legend_ColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/no-legend_LineRenderer.svg b/tests/no-legend_LineRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/no-legend_StackedAreaRenderer.svg b/tests/no-legend_StackedAreaRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/no-legend_StackedColumnRenderer.svg b/tests/no-legend_StackedColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/simple_ColumnRenderer.svg b/tests/simple_ColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/simple_LineRenderer.svg b/tests/simple_LineRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/simple_StackedAreaRenderer.svg b/tests/simple_StackedAreaRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/simple_StackedColumnRenderer.svg b/tests/simple_StackedColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/single_ColumnRenderer.svg b/tests/single_ColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/single_LineRenderer.svg b/tests/single_LineRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/single_StackedAreaRenderer.svg b/tests/single_StackedAreaRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />

diff --git a/tests/single_StackedColumnRenderer.svg b/tests/single_StackedColumnRenderer.svg

@@ -1,4 +1,10 @@
    1     1 <svg font-family="sans-serif" font-size="16" viewBox="-55 -25 700 530" xmlns="http://www.w3.org/2000/svg">
   -1     2 	<style>
   -1     3 		@media (prefers-color-scheme: dark) {
   -1     4 			[fill="#333"] {fill: white}
   -1     5 			[stroke="#333"] {stroke: white}
   -1     6 		}
   -1     7 	</style>
    2     8 	<g role="table">
    3     9 		<line stroke="#333" x1="0" x2="0" y1="0" y2="480" />
    4    10 		<line stroke="#333" x1="0" x2="640" y1="480" y2="480" />