Data controller for lotivis.js.
let data = [
{ label: "label-1", location: "paris", date: "1999-01-01", value: 1 },
{ label: "label-1", location: "paris", date: "1999-01-02", value: 2 },
{ label: "label-1", location: "berlin", date: "1999-01-03", value: 3 },
];
let dataController = lotivis.dataController(data);
// append data controller to charts ...
Installing
If you use npm, npm install lotivis-data
. You can also download the latest realease on GitHub. For using in browsers, you can load the UMD bundle from an npm-based CDN such as jsDelivr.
<script src="https://cdn.jsdelivr.net/..."></script>
<script>
let dataController = lotivis.dataController();
</script>
API Reference
id()
dataController.Returns the controllers id.
data(_)
dataController.Gets or sets the controllers data.
snapshot()
dataController.Returns the current snapshot from the filtered data.
Call with specifying a name
will return the corresponding array.
onFilterWillChange(name, callback)
dataController.Adds a listener with the passed name for filter-will-change
events.
onFilterDidChange(name, callback)
dataController.Adds a listener with the passed name for filter-did-change
events.
onDataWillChange(name, callback)
dataController.Adds a listener with the passed name for data-will-change
events.
onDataDidChange(name, callback)
dataController.Adds a listener with the passed name for data-did-change
events.
removeAllListeners()
dataController.Removes all callbacks.
filters(name?)
dataController.Gets the controllers filters. Calling without specifying a name
will return the following presented filters object.
// available filters
{
labels: [],
locations: [],
dates: [],
groups: []
}
hasFilters(name?)
dataController.Returns a Boolean value indicating whether the controller contains any filters.
var anyFilters = dataController.hasFilters();
var dateFilters = dataController.hasFilters("dates");
clearFilters(sender, name?)
dataController.Clears the filters of the controller.
// clear all filters
dataController.clearFilters(someChart);
// clear date filters
dataController.clearFilters(someChart, "dates");
isFilter(name, item)
dataController.Returns a Boolean value indicating whether the specified item is included in the specified filters list.
addFilter(name, item, sender)
dataController.Adds the specified item
to the specified filters list.
removeFilter(name, item, sender)
dataController.Removes the specified item
from the collection of filters with the specified name
.
toggleFilter(name, item, sender)
dataController.Toggles the filtered state of the passed item in the collection of filters with the passed name.
filename(extension, prefix)
dataController.Generates and returns a filename from the data with the passed extension
and prefix
.
Data
sum
data.Holds the sum of all values.
max
data.Holds the maximum value.
min
data.Holds the minimum value.
labels
data.Holds an array of all labels found in the data.
locations
data.Holds an array of all locations found in the data.
dates
data.Holds an array of all dates found in the data.
groups
data.Holds an array of all groups found in the data.
byLabel
data.Holds an InternMap mapping label to data.
byLocation
data.Holds an InternMap mapping location to data.
byDate
data.Holds an InternMap mapping date to data.
byGroup
data.Holds an InternMap mapping group to data.
filterValid()
data.Returns an array containing only data with valid values.
dataByLabel(label)
data.Returns an array containing only data for the specified label
.
dataByLocation(location)
data.Returns an array containing only data for the specified location
.
dataByDate(date)
data.Returns an array containing only data for the specified date
.
dataByGroup(group)
data.Returns an array containing only data for the specified group
.
sumOfLabel(label)
data.Returns the sum of data for the specified label
.
sumOfLocation(location)
data.Returns the sum of data for the specified location
.
sumOfDate(date)
data.Returns the sum of data for the specified date
.
sumOfGroup(group)
data.Returns the sum of data for the specified group
.
Events
disp()
Events.The static dispatch object.
on(type, callback)
Events.Adds the given callback
for the given type
.
call(type, sender, ...params)
Events.Calls the callback
for the given type
with the given sender
and params
.
Development
# build module
yarn build
# develop module
yarn build:watch