Browse Source

Fix cabaret and pygal_gen

pull/58/head
Florian Mounier 12 years ago
parent
commit
953aa19df8
  1. 5
      demo/cabaret.py
  2. 4
      demo/cabaret/__init__.py
  3. 4
      demo/cabaret/static/js.js
  4. 6
      demo/cabaret/templates/_layout.jinja2
  5. 6
      demo/cabaret/templates/index.jinja2
  6. 20
      pygal/config.py
  7. 36
      pygal_gen.py

5
demo/cabaret.py

@ -51,10 +51,11 @@ else:
app.logger.debug('HTTPServer monkey patched for url %s' % url)
try:
import wdb
from wdb.ext import WdbMiddleware, add_w_builtin
except ImportError:
pass
else:
app.wsgi_app = wdb.Wdb(app.wsgi_app, start_disabled=True)
add_w_builtin()
app.wsgi_app = WdbMiddleware(app.wsgi_app, start_disabled=True)
app.run(debug=True, threaded=True, host='0.0.0.0', port=12221)

4
demo/cabaret/__init__.py

@ -20,7 +20,7 @@ from flask import Flask, render_template, request, jsonify
from pygal import CHARTS_BY_NAME
from pygal.graph import CHARTS_NAMES
from pygal.config import CONFIG_ITEMS
from pygal.interpolate import KINDS
from pygal.interpolate import INTERPOLATIONS
from pygal.style import styles
from json import loads
from time import time
@ -35,7 +35,7 @@ def create_app():
def index():
return render_template(
'index.jinja2', charts_names=CHARTS_NAMES, configs=CONFIG_ITEMS,
interpolations=KINDS, styles_names=styles.keys())
interpolations=INTERPOLATIONS, styles_names=styles.keys())
@app.route("/svg", methods=('POST',))
def svg():

4
demo/cabaret/static/js.js

@ -15,13 +15,13 @@ function resend() {
}
});
if(interpolation) {
opts['interpolate'] = interpolation;
opts.interpolate = interpolation;
}
$('.data .controls').each(function () {
var label = $(this).find('.serie-label').val(),
values = $(this).find('.serie-value').val(),
lst = [label, values.split(',').map(function (v) { return parseFloat(v); })];
if (values != "") {
if (values !== '') {
vals.push(lst);
}
});

6
demo/cabaret/templates/_layout.jinja2

@ -2,10 +2,10 @@
<html>
<head>
<title>Cabaret - Online pygal graph generator</title>
<script type="text/javascript" src="{{ url_for('static', filename='components/jquery/jquery.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='components/jquery/jquery.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='components/bootstrap/docs/assets/js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="https://raw.github.com/Kozea/pygal.js/master/svg.jquery.js"></script>
<script type="text/javascript" src="https://raw.github.com/Kozea/pygal.js/master/pygal-tooltips.js"></script>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/pygal-tooltips.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='components/bootstrap/docs/assets/css/bootstrap.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ url_for('static', filename='css.css') }}" type="text/css" />

6
demo/cabaret/templates/index.jinja2

@ -22,7 +22,7 @@
</select>
</div>
</div>
<div class="control-group data tt" title="Enter the chart data">
<label class="control-label" for="data">Data</label>
<div class="controls form-inline">
@ -71,12 +71,14 @@
</div>
{% else %}
<label class="control-label" for="c-{{ key.name }}" > {{ key.name.replace('_', ' ') | title }}</label>
<div class="controls">
{% if key.is_numeric %}
<input type="number" id="c-{{ key.name }}" class="c-opts" value="{{ key.value or ''}}" />
{% elif key.is_string %}
<input type="text" id="c-{{ key.name }}" class="c-opts" value="{{ key.value or ''}}" />
{% elif key.is_dict %}
<input type="text" id="c-{{ key.name }}" class="c-opts dict-of-{{ key.subtype }}" value="{{ key.value or ''}}" placeholder="key1: value1, key2: value2, ..." />
{% elif key.is_list %}
<input type="text" id="c-{{ key.name }}" class="c-opts list-of-{{ key.subtype }}" placeholder="value1, value2{{ ', ...' if key.name != 'range' }}" value="{{ key.value or ''}}" />
{% endif %}

20
pygal/config.py

@ -22,6 +22,7 @@ Config module with all options
"""
from copy import deepcopy
from pygal.style import Style, DefaultStyle
from pygal.interpolate import INTERPOLATIONS
class FontSizes(object):
@ -62,6 +63,10 @@ class Key(object):
def is_string(self):
return self.type == str
@property
def is_dict(self):
return self.type == dict
@property
def is_list(self):
return self.type == list
@ -74,6 +79,17 @@ class Key(object):
map(
self.subtype, map(
lambda x: x.strip(), value.split(','))))
elif self.type == dict:
rv = {}
for pair in value.split(','):
key, val = pair.split(':')
key = key.strip()
val = val.strip()
try:
rv[key] = self.subtype(val)
except:
rv[key] = val
return rv
return self.type(value)
@ -202,7 +218,7 @@ class Config(object):
interpolate = Key(
None, str, "Value", "Interpolation",
"May be 'quadratic' or 'cubic'")
"May be %s" % ' or '.join(INTERPOLATIONS))
interpolation_precision = Key(
250, int, "Value", "Number of interpolated points between two values")
@ -210,7 +226,7 @@ class Config(object):
interpolation_parameters = Key(
{}, dict, "Value", "Various parameters for parametric interpolations",
"ie: For hermite interpolation, you can set the cardinal tension with"
"{'type': 'cardinal', 'c': .5}")
"{'type': 'cardinal', 'c': .5}", int)
order_min = Key(
None, int, "Value", "Minimum order of scale, defaults to None")

36
pygal_gen.py

@ -35,23 +35,25 @@ parser.add_argument('-o', '--output', dest='filename', default='pygal_out.svg',
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 is not 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'] = ['quadratic', 'cubic']
parser.add_argument(
'--%s' % opt_name, dest=key, default=val, **opts)
for key in pygal.config.CONFIG_ITEMS:
opt_name = key.name
val = key.value
opts = {}
if key.type == list:
opts['type'] = key.subtype
opts['nargs'] = '+'
else:
opts['type'] = key.type
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.name == 'interpolate':
opts['choices'] = list(pygal.interpolate.INTERPOLATIONS.keys())
parser.add_argument(
'--%s' % opt_name, dest=key.name, default=val, **opts)
config = parser.parse_args()

Loading…
Cancel
Save