-
Notifications
You must be signed in to change notification settings - Fork 0
DataViews
A DataView
constructor takes as parameters a data
object and an options
object. The accepted format of the data
paramter is dependant upon the data view and the options
object has the following properties:
Parameter | Type | Description |
---|---|---|
aggregator |
function | The aggregator generating function. |
derivedAttributes |
function | The dictionary of "attribute generator" functions: the keys are the names of the new attributes, and the functions take an existing record and return the value of the new attribute. |
meta |
function | The characteristic properties from which a data view's state may be persisted or initialized. |
A "data interaction" object factory must be configured before it can become available to a compatible rndr
renderer plugin. The $rndrDataViews
singleton is a dictionary of such DataView
object factories and has the following methods:
-
add(name, DataView, opts)
: It takes as parameters:Parameter Type Description name
string The lookup name of the DataView
object factory.DataView
function A "data interaction" object factory. opts
(optional) object Overrides or extends the options for the DataView
during initialization. -
list()
, Lists the available "data interaction" object factories.
You can create your own DataView
object factories as a plugin. A DataView
is an Universal Module Definition (UMD) that can be loaded with NativeJS, AMD, or CJS and will resigter itself with the $rndrDataViews
singleton for use with compatible rndr
renderer plugins. The mechanism is fairly generic, so it should be possible to write some interesting data views. rndr
ships with the PivotData data view (which is fairly complex) and would be a good example to start with when beginning to develop a new one.
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['$rndrDataViews'], function($rndrDataViews) {
return factory($rndrDataViews);
});
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('$rndrDataViews'));
} else {
factory(root.rndr.plugins.dataViews);
}
}(this, function($rndrDataViews) {
function MyDataView(data, opts) {
// reference to the data
this.data = data;
// Set the meta data from a previous state or initialize it.
// The meta data is the characteristic properties from
// which a data view's state may be persisted or initialized. It
// is best practice to always be set from the `opts.meta` on
// instantiation but you must take care to set it to the default meta
// object in the case where the `opts.meta` is `undefined`.
this.meta = opts.meta || {
rows: [],
cols: []
};
}
MyDataView.prototype = {
constructor: MyDataView,
};
// Register this DataView object factory with the `$rndrDataViews`
// dictionary exposing `MyDataView` to compatible `rndr` renderer plugins.
$rndrDataViews.add('MyDataView', MyDataView);
}));