-
Notifications
You must be signed in to change notification settings - Fork 0
Preprocessing Data
When the data has been fetched from the backend and before it has touched any of the Google API objects, the possibility exists to massage the data (i.e.: change string data to Date objects, type changes, unit conversions, extending rows, etc). More than one preprocessor can be set up and each will be called in the order the call-objects were configured
// the call-object signature
{
call : 'preprocessor_name',
params : [ /* array of parameters */ ]
}To invoke a preprocessor simply setup an object in the main options preprocesses array. The following example shows how to apply a preprocessor to change formatted string data into Date objects on the third column:
$('#id').CreateChart({
...
preprocesses : [
{
call : 'dateFrom_Y-M-D',
params : [2]
}
]
...
});
// the preprocessor has been previously defined
$.fn.CreateChart.preprocessors['dateFrom_Y-M-D'] = function (columnIndex) { /* ... */ };`.The preprocessor must be available before the data comes back from the backend, otherwise the process will be ignored and the initialization procedure will continue. Adding a preprocessor is easy, simply extend the preprocessor object with a function, whose context will be the actual raw data, as follows:
$.fn.CreateChart.preprocessors.<method_name> = function (<params>) {
var data = this;
...
};The method_name should be unique or you'll be overriding another preprocessor. There are no restrictions on the params but remember to document what each are for and that the order of parameters is important. For clarity, the preprocessor will be called in the following manner:
$.fn.CreateChart.preprocessors.<method_name>.apply(rawData,params||[]);