Skip to content

Commit

Permalink
Fix cabaret and pygal_gen
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Jun 27, 2013
1 parent 71af33d commit 953aa19
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
5 changes: 3 additions & 2 deletions demo/cabaret.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def log(httpserver):
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 changes: 2 additions & 2 deletions demo/cabaret/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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
Expand All @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions demo/cabaret/static/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
6 changes: 3 additions & 3 deletions demo/cabaret/templates/_layout.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
6 changes: 4 additions & 2 deletions demo/cabaret/templates/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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 %}
Expand Down
20 changes: 18 additions & 2 deletions pygal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""
from copy import deepcopy
from pygal.style import Style, DefaultStyle
from pygal.interpolate import INTERPOLATIONS


class FontSizes(object):
Expand Down Expand Up @@ -62,6 +63,10 @@ def is_numeric(self):
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
Expand All @@ -74,6 +79,17 @@ def coerce(self, value):
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)


Expand Down Expand Up @@ -202,15 +218,15 @@ 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")

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")
Expand Down
36 changes: 19 additions & 17 deletions pygal_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@
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()

Expand Down

0 comments on commit 953aa19

Please sign in to comment.