Constructor
new Broker()
This is the Data.Broker class.
It realizes an object to load one or more data sources and call a user defined function if all sources have been successfully loaded.
It passes an array with the loaded data (Data.Table objects) to the user function
It realizes an object to load one or more data sources and call a user defined function if all sources have been successfully loaded.
It passes an array with the loaded data (Data.Table objects) to the user function
Example
var broker = new Data.Broker()
.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")
.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/risorse/comuniViminaleISTAT.csv","csv")
.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/camera_geopolitico_italia.csv","csv")
.realize(
function(dataA) {
var scrutini = dataA[0];
var comuniViminaleISTAT = dataA[1];
var camera_geopolitico_italia = dataA[2];
scrutini = scrutini.select("WHERE tipo_riga == LI");
...
});
Returns:
a new Data.Broker object
Methods
addSource(szUrl, szType)
add one source to the broker
Parameters:
| Name | Type | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
szUrl |
String | the url of the data source | ||||||||||
szType |
String | type of the data (csv,...)
|
Returns:
the Data.Broker object
error(onError)
define error function
Example
var broker = new Data.Broker()
.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")
.error(function(e){alert(e);})
.realize(
function(broker) {
...
});
Parameters:
| Name | Type | Description |
|---|---|---|
onError |
function | a user defined function to call when error occurs |
Returns:
the Data.Broker object
notify(onError)
define notify function
Example
var broker = new Data.Broker()
.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")
.notify(function(e){alert(e);})
.realize(
function(broker) {
...
});
Parameters:
| Name | Type | Description |
|---|---|---|
onError |
function | a user defined function to call when notify occurs |
Returns:
the Data.Broker object
realize(callback)
start the broker
initiate the process to load the added sources and [optional] define a user function to be called on success.
the argument passed to the user function is an array with the loaded data as "-_anonymous_-Data.Table" objects
initiate the process to load the added sources and [optional] define a user function to be called on success.
the argument passed to the user function is an array with the loaded data as "-_anonymous_-Data.Table" objects
Example
...
.realize(
function(dataA) {
var scrutini = dataA[0];
var comuniViminaleISTAT = dataA[1];
var camera_geopolitico_italia = dataA[2];
...
});
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | type of the data (csv,...) |
setCallback(callback)
set the callback function to execute on sucess of all loading.
Note: can also be defined as argument of .realize()
Note: can also be defined as argument of .realize()
Example
function onSuccess(dataA) {
... do something with the loaded data
}
var broker = new Data.Broker()
.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")
.setCallback(onSuccess)
.realize();
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | the callback function |
Returns:
the Data.Broker object