data.js

Source:
Version:
  • 1.47
Author:
  • Guenter Richter guenter.richter@medienobjekte.de
License:
  • MIT
provides an object and methods to load, parse and process various data sources.
The sources may be of the following type: csv, json, geojson, kml e rss.
The methods to load data are:
  • Data.feed() to load from url
  • Data.import() to import javascript objects and
  • Data.broker() to load more than one source
The loaded data is stored in a Table object which gives the user the methods to transform the data.
The format of the data of a Table object is jsonDB, the same format used internaly by iXmaps.

Example

// define data source
 var szUrl = "https://raw.githubusercontent.com/emergenzeHack/terremotocentro/master/_data/issues.csv";

 // load data from feed
 var myfeed = Data.feed({"source":szUrl,"type":"csv"}).load(function(mydata){

     // on data load succeeds, process the loaded data via mydata object
     // create new columns 'date' and 'hour' from one timestamp column
     // we need them to create pivot tables 
     // ---------------------------------------------------------------
     mydata.addColumn({'source':'created_at','destination':'date'},function(value){
         var d = new Date(__normalizeTime(value));
         return( String(d.getDate()) + "." + String(d.getMonth()+1) + "." + String(d.getFullYear()) );
     });

     // get the hours
     // -----------------------------------------
     var hoursA = mydata.column("hour").values();

     // do something ... 

     // make a pivot table from the values in column 'state'
     // ----------------------------------------------------
     var pivot = mydata.pivot({ "lead":	'date',
                                "keep":  ['created_at'],	
                                "cols":	'state' 
                              });

     // invert data table (let the last record be the first)
     // ----------------------------------------------
     pivot = pivot.revert();

     // make chart with 2 curves, total and closed issues
     // -------------------------------------------------
     var set1  = pivot.column("Total").values();
     var set2  = pivot.column("closed").values();

    ....
}).error(function(e){
     alert("Data.feed error: " + e);
});