diff --git a/demo/cabaret/__init__.py b/demo/cabaret/__init__.py index 1c2bb18..a6c9dd0 100644 --- a/demo/cabaret/__init__.py +++ b/demo/cabaret/__init__.py @@ -19,7 +19,7 @@ from flask import Flask, render_template, request from pygal import CHARTS_BY_NAME from pygal.graph import CHARTS_NAMES -from pygal.config import Config +from pygal.config import CONFIG_ITEMS from pygal.style import styles from json import loads @@ -31,17 +31,22 @@ def create_app(): @app.route("/") def index(): - configs = Config()._items return render_template( - 'index.jinja2', charts_names=CHARTS_NAMES, configs=dict(configs), + 'index.jinja2', charts_names=CHARTS_NAMES, configs=CONFIG_ITEMS, styles_names=styles.keys()) @app.route("/svg", methods=('POST',)) def svg(): values = request.values - chart = CHARTS_BY_NAME[values['type']]( - disable_xml_declaration=True, - style=styles[values['style']], **loads(values['opts'])) + config = loads(values['opts']) + config['disable_xml_declaration'] = True + config['style'] = styles[values['style']] + config['js'] = [] + for item in CONFIG_ITEMS: + value = config.get(item.name, None) + if value: + config[item.name] = item.coerce(value) + chart = CHARTS_BY_NAME[values['type']](**config) for title, vals in loads(values['vals']).items(): chart.add(title, vals) return chart.render_response() diff --git a/demo/cabaret/static/css.css b/demo/cabaret/static/css.css index aeefd93..bbb99ba 100644 --- a/demo/cabaret/static/css.css +++ b/demo/cabaret/static/css.css @@ -7,12 +7,16 @@ body { padding: 9px 0; } +figure { + margin: 0; +} + figure svg { width: 100%; background: none; } -* { +textarea { -webkit-transition: all 500ms ease-out; -moz-transition: all 500ms ease-out; transition: all 500ms ease-out; diff --git a/demo/cabaret/static/js.js b/demo/cabaret/static/js.js index ee4c7db..3c76b84 100644 --- a/demo/cabaret/static/js.js +++ b/demo/cabaret/static/js.js @@ -8,6 +8,9 @@ function resend() { $('.c-opts').each(function() { var $this = $(this), val = $this.val(); + if($this.attr('type') == 'checkbox') { + val = $this.is(":checked"); + } if(val) { opts[$this.attr('id').replace('c-', '')] = val; } @@ -23,49 +26,22 @@ function resend() { }, dataType: 'html' }).done(function (data) { - $fig.find('svg').remove(); - $fig.prepend(data); + // $fig.find('div').get(0).innerHTML = data; + $fig.find('div').html(data); + init_svg($fig.find('svg').get(0)); $('textarea').css({'-webkit-box-shadow': ''}); }).fail(function () { $('textarea').css({'-webkit-box-shadow': 'inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(255, 0, 0, 0.6)'}); }); - - // $embed.remove(); - // $fig.prepend( - // $('') - // .attr({ - // src: src, - // type: 'image/svg+xml' - // }) - // ); } $(function () { - $('figure figcaption').append( - $('