Python to generate nice looking SVG graph http://pygal.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

function resend() {
var $fig = $('figure'),
type = $('#type').val(),
style = $('#style').val(),
12 years ago
interpolation = $('#interpolation').val(),
opts = {},
vals = [];
$('.c-opts').each(function() {
var $this = $(this),
val = $this.val();
12 years ago
if($this.attr('type') == 'checkbox') {
opts[$this.attr('id').replace('c-', '')] = $this.is(":checked");
} else if(val) {
opts[$this.attr('id').replace('c-', '')] = val;
}
});
12 years ago
if(interpolation) {
opts['interpolate'] = interpolation;
}
$('.data .controls').each(function () {
var label = $(this).find('.serie-label').val(),
12 years ago
values = $(this).find('.serie-value').val(),
lst = [label, values.split(',').map(function (v) { return parseFloat(v); })];
if (values != "") {
vals.push(lst);
}
12 years ago
});
12 years ago
var t = new Date().getTime();
$.ajax({
url: '/svg',
type: 'POST',
data: {
type: type,
style: style,
12 years ago
vals: JSON.stringify({vals: vals}),
opts: JSON.stringify(opts)
},
12 years ago
dataType: 'json',
12 years ago
traditional: true
}).done(function (data) {
12 years ago
$('.total-time').html('<label>Total time: </label>' + (new Date().getTime() - t) + 'ms');
$('.server-time').html('<label>Generation time:</label> ' + data.time + 'ms');
12 years ago
// $fig.find('div').get(0).innerHTML = data;
12 years ago
$fig.find('div').html(data.svg);
12 years ago
init_svg($fig.find('svg').get(0));
$('.nav a').css({color: ''});
}).fail(function () {
$('.nav a').css({color: 'red'});
});
}
$(function () {
12 years ago
$('#type').add('#style').add('#interpolation').on('change', resend);
$('#data').on('input', resend);
12 years ago
$('.c-opts:not([type=checkbox])').on('input', resend);
$('.c-opts[type=checkbox]').on('change', resend);
12 years ago
$('div.tt').tooltip({ placement: 'top' });
$('.control-group.data').on('click keypress', '.btn.rem', function () {
if($('.data .controls').length > 1) {
$(this).closest('.controls').remove();
}
});
$('.control-group.data').on('click keypress', '.btn.add', function () {
$(this).siblings('.controls').last().clone().insertBefore($(this)).find('input').val('');
});
$('.control-group.data').on('input', 'input', resend);
resend();
});