Browse Source

Add executable pygal_gen

pull/8/head
Florian Mounier 13 years ago
parent
commit
e5b74b05b4
  1. 9
      pygal/__init__.py
  2. 6
      pygal/config.py
  3. 65
      pygal_gen.py
  4. 4
      setup.py

9
pygal/__init__.py

@ -16,9 +16,7 @@
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.9.17' __version__ = '0.9.18'
from collections import namedtuple
from pygal.graph.bar import Bar from pygal.graph.bar import Bar
from pygal.graph.horizontal import HorizontalBar from pygal.graph.horizontal import HorizontalBar
from pygal.graph.stackedbar import StackedBar from pygal.graph.stackedbar import StackedBar
@ -29,3 +27,8 @@ from pygal.graph.xy import XY
from pygal.graph.pie import Pie from pygal.graph.pie import Pie
from pygal.graph.radar import Radar from pygal.graph.radar import Radar
from pygal.config import Config from pygal.config import Config
"""List of all chart types"""
CHARTS = [
Bar, HorizontalBar, StackedBar, HorizontalStackedBar,
Line, StackedLine, XY, Pie, Radar]

6
pygal/config.py

@ -27,8 +27,10 @@ class Config(object):
"""Class holding config values""" """Class holding config values"""
_horizontal = False _horizontal = False
# Graph width and height # Graph width
width, height = 800, 600 width = 800
# Graph height
height = 600
# Display values in human readable format (ie: 12.4M) # Display values in human readable format (ie: 12.4M)
human_readable = False human_readable = False
# Display values in logarithmic scale # Display values in logarithmic scale

65
pygal_gen.py

@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
import argparse
import pygal
parser = argparse.ArgumentParser(
description='Generate pygal chart in command line',
prog='pygal_gen',
version=pygal.__version__)
parser.add_argument('-t', '--type', dest='type', default='Line',
choices=map(lambda x: x.__name__, pygal.CHARTS),
help='Kind of chart to generate')
parser.add_argument('-o', '--output', dest='filename', default='pygal_out.svg',
help='Filename to write the svg to')
parser.add_argument('-s', '--serie', dest='series', nargs='+', action='append',
help='Add a serie in the form (title val1 val2...)')
for key, val in pygal.config.Config.__dict__.items():
if not key.startswith('_') and not hasattr(val, '__call__'):
opt_name = key
opts = {'type': str}
if val != None:
opts['type'] = type(val)
elif 'labels' in key:
opts['nargs'] = '+'
if opts['type'] == bool:
del opts['type']
opts['action'] = 'store_true' if not val else 'store_false'
if val:
opt_name = 'no-' + opt_name
if key == 'interpolate':
opts['choices'] = [
'linear', 'nearest', 'zero', 'slinear', 'quadratic',
'cubic', 'krogh', 'barycentric', 'univariate']
parser.add_argument(
'--%s' % opt_name, dest=key, default=val, **opts)
config = parser.parse_args()
chart = getattr(pygal, config.type)(**vars(config))
for serie in config.series:
chart.add(serie[0], map(float, serie[1:]))
chart.render_to_file(config.filename)

4
setup.py

@ -21,14 +21,16 @@ from setuptools import setup, find_packages
setup( setup(
name="pygal", name="pygal",
version='0.9.17', version='0.9.18',
description="A python svg graph plotting library", description="A python svg graph plotting library",
author="Kozea", author="Kozea",
url="http://pygal.org/",
author_email="florian.mounier@kozea.fr", author_email="florian.mounier@kozea.fr",
license="GNU LGPL v3", license="GNU LGPL v3",
platforms="Any", platforms="Any",
packages=find_packages(), packages=find_packages(),
provides=['pygal'], provides=['pygal'],
scripts=["pygal_gen.py"],
keywords=["svg", "graph", "diagram", "plot", "histogram", "kiviat"], keywords=["svg", "graph", "diagram", "plot", "histogram", "kiviat"],
tests_require=["pytest", "pyquery", "flask"], tests_require=["pytest", "pyquery", "flask"],
package_data={'pygal': ['css/*', 'js/*']}, package_data={'pygal': ['css/*', 'js/*']},

Loading…
Cancel
Save