simplecharts

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

commit
e1d15830049ba50809b262a3487b099632f69bbc
parent
8582829f55080244312e63519500cdef5e5ae241
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-01-10 13:04
add cli

Diffstat

M setup.py 3 +++
M simplecharts.py 35 +++++++++++++++++++++++++++++++++++

2 files changed, 38 insertions, 0 deletions


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

@@ -15,6 +15,9 @@ setup(
   15    15     author_email='tobias.bengfort@posteo.de',
   16    16     py_modules=['simplecharts'],
   17    17     license='MIT',
   -1    18     entry_points={'console_scripts': [
   -1    19         'simplecharts=simplecharts:main',
   -1    20     ]},
   18    21     classifiers=[
   19    22         'Topic :: Scientific/Engineering :: Visualization',
   20    23     ]

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

@@ -1,3 +1,6 @@
   -1     1 import argparse
   -1     2 import csv
   -1     3 import sys
    1     4 from xml.sax.saxutils import escape
    2     5 
    3     6 COLORS = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33']
@@ -302,3 +305,35 @@ class StackedAreaRenderer(BaseRenderer):
  302   305             prev = points
  303   306         s += dots
  304   307         return s
   -1   308 
   -1   309 
   -1   310 def main():
   -1   311     parser = argparse.ArgumentParser(
   -1   312         'read CSV from stdin and write SVG to stdout'
   -1   313     )
   -1   314     parser.add_argument('-r', '--renderer', choices=[
   -1   315         'column', 'stacked-column', 'line', 'stacked-area'
   -1   316     ], default='line')
   -1   317     args = parser.parse_args()
   -1   318 
   -1   319     cls = {
   -1   320         'column': ColumnRenderer,
   -1   321         'stacked-column': StackedColumnRenderer,
   -1   322         'line': LineRenderer,
   -1   323         'stacked-area': StackedAreaRenderer,
   -1   324     }[args.renderer]
   -1   325 
   -1   326     reader = csv.reader(sys.stdin)
   -1   327     data = {
   -1   328         'rows': [],
   -1   329         'legend': next(reader)[1:],
   -1   330     }
   -1   331     for row in reader:
   -1   332         data['rows'].append({
   -1   333             'label': row[0],
   -1   334             'values': [float(i) for i in row[1:]],
   -1   335         })
   -1   336 
   -1   337     renderer = cls()
   -1   338     svg = renderer.render(data)
   -1   339     print(svg)