MediaWiki:Common.js

From FridaV

Jump to: navigation, search
       var my_id=$(this).attr('id');
       var my_id=$(this).attr('id');
       console.log('table '+my_id);
       console.log('table '+my_id);
-
       chart.chart[my_id]={cols:{}, ncols:[]};
+
       var my_chart; chart.chart[my_id]=my_chart;
 +
      my_chart={cols:{}, ncols:[], series:{}};
-
      // get columns
+
      // get columns
       $('tr:first th',this).each(function(j) {
       $('tr:first th',this).each(function(j) {
         var name=this.innerHTML;
         var name=this.innerHTML;
         console.log('column '+name);
         console.log('column '+name);
-
         chart.chart[my_id].cols[name]=j;
+
         my_chart.cols[name]=j;
-
         chart.chart[my_id].ncols.push(name);
+
         my_chart.ncols.push(name);
       });
       });
-
       console.log(chart.chart[my_id]);
+
       // get data
 +
      $('tr',this).each(function(j) {
 +
        if(j>=1) {
 +
        var epoch=$('th.day',this).attr('epoch')*1000;
 +
        $('td',this).each(function(ii) {
 +
          var a=my_chart.ncols[ii]
 +
          var v=this.innerHTML;
 +
          if(v=='None') v=0;
 +
          if(!my_chart.series[a]) my_chart.series[a]={ label: a , data: [] };
 +
          my_chart.series[a].data.unshift([epoch,parseFloat(v)]);
 +
        }
 +
      });
 +
      console.log(my_chart);
     });
     });
   }
   }

Revision as of 21:27, 4 April 2009

/* Any JavaScript here will be loaded for all users on every page load. */

var chart = {
  chart: {},
  init: function() {
    $('table.flot').each(function(i) {
      var my_id=$(this).attr('id');
      console.log('table '+my_id);
      var my_chart; chart.chart[my_id]=my_chart;
      my_chart={cols:{}, ncols:[], series:{}};

      // get columns
      $('tr:first th',this).each(function(j) {
         var name=this.innerHTML;
         console.log('column '+name);
         my_chart.cols[name]=j;
         my_chart.ncols.push(name);
      });
      // get data
      $('tr',this).each(function(j) {
         if(j>=1) {
         var epoch=$('th.day',this).attr('epoch')*1000;
         $('td',this).each(function(ii) {
           var a=my_chart.ncols[ii]
           var v=this.innerHTML;
           if(v=='None') v=0;
           if(!my_chart.series[a]) my_chart.series[a]={ label: a , data: [] };
           my_chart.series[a].data.unshift([epoch,parseFloat(v)]);
         }
       });
      console.log(my_chart);
    });
  }
}

$(document).ready(chart.init);
Personal tools
maps, graphs & data