Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #15 from crossfilter/fix-changemap-default-null-
Browse files Browse the repository at this point in the history
Default null value option for changeMap
  • Loading branch information
tannerlinsley committed Mar 29, 2016
2 parents 09c7b28 + 7b230d2 commit b9c5638
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "universe",
"version": "0.6.1",
"version": "0.6.2",
"description": "The fastest way to query and explore multivariate datasets",
"main": "src/universe.js",
"directories": {
Expand Down
13 changes: 7 additions & 6 deletions src/postAggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ module.exports = function(service) {
query.data = obj
}

function changeMap(query, parent, aggObj) {
function changeMap(query, parent, aggObj, defaultNull) {
defaultNull = _.isUndefined(defaultNull) ? 0 : defaultNull
query.data = cloneIfLocked(parent)
_.recurseObject(aggObj, function(val, key, path) {

Expand All @@ -96,14 +97,14 @@ module.exports = function(service) {
fromStartPath.push(key + 'ChangeFromStart')
fromEndPath.push(key + 'ChangeFromEnd')

var start = _.get(query.data[0].value, path)
var end = _.get(query.data[query.data.length - 1].value, path)
var start = _.get(query.data[0].value, path, defaultNull)
var end = _.get(query.data[query.data.length - 1].value, path, defaultNull)

_.forEach(query.data, function(record, i) {
var previous = query.data[i - 1] || query.data[0]
_.set(query.data[i].value, changePath, _.get(record.value, path) - (previous ? _.get(previous.value, path) : 0))
_.set(query.data[i].value, fromStartPath, _.get(record.value, path) - start)
_.set(query.data[i].value, fromEndPath, _.get(record.value, path) - end)
_.set(query.data[i].value, changePath, _.get(record.value, path, defaultNull) - (previous ? _.get(previous.value, path, defaultNull) : defaultNull))
_.set(query.data[i].value, fromStartPath, _.get(record.value, path, defaultNull) - start)
_.set(query.data[i].value, fromEndPath, _.get(record.value, path, defaultNull) - end)
})
})
}
Expand Down
15 changes: 8 additions & 7 deletions universe.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions universe.min.js

Large diffs are not rendered by default.

0 comments on commit b9c5638

Please sign in to comment.