MediaWiki:Common.js
From FridaV
}, // init() | }, // init() | ||
toggle_series: function(id,name,e) { | toggle_series: function(id,name,e) { | ||
| - | |||
var my_chart=charts.chart[id]; | var my_chart=charts.chart[id]; | ||
$('#'+id+' tr').each(function(i) { | $('#'+id+' tr').each(function(i) { | ||
} | } | ||
}); | }); | ||
| + | plot(id); | ||
}, // toggle_series() | }, // toggle_series() | ||
| + | plot: function(id) { | ||
| + | var data=[]; | ||
| + | $('#'+id+' tr:first th.plot').each(function(i) { | ||
| + | var name=this.innerHTML; | ||
| + | if(charts.chart[id].series[name]) { | ||
| + | data.push(charts.chart[id].series[name]); | ||
| + | } | ||
| + | }); | ||
| + | if(data.length>0) { | ||
| + | console.log(data); | ||
| + | } | ||
| + | } | ||
} | } | ||
$(document).ready(charts.init); | $(document).ready(charts.init); | ||
Revision as of 22:39, 4 April 2009
/* Any JavaScript here will be loaded for all users on every page load. */
var charts = {
chart: {},
init: function() {
$('table.flot').each(function(i) {
var my_id=$(this).attr('id');
var my_chart={cols:{}, ncols:[], series:{}};
charts.chart[my_id]=my_chart;
// get fields
$('tr:first th',this).each(function(j) {
var name=this.innerHTML;
my_chart.cols[name]=j;
my_chart.ncols.push(name);
this.onclick=function(e) { charts.toggle_series(my_id,name,e); }
}); // fields
// get rows
$('tr',this).each(function(j) {
if(j>=1) {
var epoch=$('th.day',this).attr('epoch')*1000;
$('td',this).each(function(ii) { // columns
var a=my_chart.ncols[ii];
var v=this.innerHTML;
if((!v) || v=='None') v=0;
if(!my_chart.series[a]) my_chart.series[a]={ label: a , data: [] };
this.onclick=function(e) { charts.toggle_series(my_id,a,e); }
my_chart.series[a].data.unshift([epoch,parseFloat(v)]);
}); // columns
}
}); // rows
return;
}); // tables
}, // init()
toggle_series: function(id,name,e) {
var my_chart=charts.chart[id];
$('#'+id+' tr').each(function(i) {
if(i<1) {
$('th:eq('+my_chart.cols[name]+')',this).toggleClass('plot');
} else {
$('td:eq('+my_chart.cols[name]+')',this).toggleClass('plot');
}
});
plot(id);
}, // toggle_series()
plot: function(id) {
var data=[];
$('#'+id+' tr:first th.plot').each(function(i) {
var name=this.innerHTML;
if(charts.chart[id].series[name]) {
data.push(charts.chart[id].series[name]);
}
});
if(data.length>0) {
console.log(data);
}
}
}
$(document).ready(charts.init);
