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

Commit

Permalink
_.values function for complex keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Mar 8, 2016
1 parent 25a1bb3 commit 0e744f8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crossfilter-universe",
"version": "0.4.0",
"version": "0.4.1",
"description": "The fastest way to query and explore multivariate datasets",
"main": "src/universe.js",
"directories": {
Expand Down
7 changes: 5 additions & 2 deletions src/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = function(service) {
// Complex column Keys
if (_.isArray(column.key)) {
column.complex = true
sample = _.map(_.pick(all[0], column.key))
sample = _.values(_.pick(all[0], column.key))
if (sample.length !== column.key.length) {
throw new Error('Column key does not exist in data!', column.key)
}
Expand Down Expand Up @@ -130,7 +130,10 @@ module.exports = function(service) {
return Promise.resolve(column.dimension.bottom(Infinity))
.then(function(rows) {
var accessor = dimension.makeAccessor(column.key)
if (column.type === 'array') {
if (column.type === 'complex') {
column.values = _.uniq(_.flatten(_.map(rows, accessor)))
}
else if (column.type === 'array') {
column.values = _.uniq(_.flatten(_.map(rows, accessor)))
} else {
column.values = _.uniq(_.map(rows, accessor))
Expand Down
16 changes: 8 additions & 8 deletions src/lodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
uniq: uniq,
flatten: flatten,
sort: sort,
keys: keys,
values: values,
}


Expand Down Expand Up @@ -110,7 +110,7 @@ function map(a, b) {
m = []
for (key in a) {
if (a.hasOwnProperty(key)) {
m.push(a[key][b])
m.push(a[key])
}
}
return m
Expand Down Expand Up @@ -256,12 +256,12 @@ function sort(arr) {
return arr;
}

function keys(aa) {
var keys = []
for (var key in aa) {
if (aa.hasOwnProperty(key)) {
keys.push(aa[key])
function values(a) {
var values = []
for (var key in a) {
if (a.hasOwnProperty(key)) {
values.push(a[key])
}
}
return keys
return values
}
25 changes: 14 additions & 11 deletions universe.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions universe.min.js

Large diffs are not rendered by default.

0 comments on commit 0e744f8

Please sign in to comment.