Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to get reduced group to filter correctly #101

Closed
tvinci opened this issue Dec 20, 2013 · 1 comment
Closed

A way to get reduced group to filter correctly #101

tvinci opened this issue Dec 20, 2013 · 1 comment

Comments

@tvinci
Copy link

tvinci commented Dec 20, 2013

I'm using crossfilter to reduce and sort an array which produces key value pairs. However, when I filter it, the values disappears but the key remains. Is there a way to make sure the keys don't show? Here is the code. I've also created a jsfiddle example: http://jsfiddle.net/tvinci/v36Rv/5/

var data2 = [
{date: "10/01/2012", hits: 1, tps: 100, http_status:'s200'},
{date: "10/01/2012", hits: 1, tps: 90, http_status:'s302'},
{date: "01/02/2013", hits: 1, tps: 100, http_status:'s200'},
{date: "01/02/2013", hits: 1, tps: 10, http_status:'s302'},
{date: "01/03/2013", hits: 0, tps: 300, http_status:'s200'},
{date: "01/03/2013", hits: 1, tps: 10, http_status:'s302'},
{date: "01/04/2013", hits: 1, tps: 90, http_status:'s200'},
{date: "01/04/2013", hits: 1, tps: 0, http_status:'s302'},
];
var parseDate = d3.time.format("%m/%d/%Y").parse;
data2.forEach(function(d) {
d.date = parseDate(d.date);
d.Year=d.date.getFullYear();
});

var ndx2 = crossfilter(data2);

var tpsDim = ndx2.dimension(function(d) {return d.date;});
var yearDim = ndx2.dimension(function(d) {return d.Year;});
print_filter("tpsDim");

var tableGroup = tpsDim.group().reduce(
function(p,v) {
p[v.http_status] = (p[v.http_status] || 0) + +v.tps;
p["Year"]=v.Year;
return p;
},
function(p,v) {
p[v.http_status] = (p[v.http_status] || 0) - +v.tps;
p["Year"]=v.Year;
return p;
},
function() { return {}; });

print_filter("tableGroup");
/* This prints the following
"tableGroup(4) = [
{"key":"2013-01-02T05:00:00.000Z","value":{"s200":100,"Year":2013,"s302":10}},
{"key":"2013-01-03T05:00:00.000Z","value":{"s200":300,"Year":2013,"s302":10}},
{"key":"2013-01-04T05:00:00.000Z","value":{"s200":90,"Year":2013,"s302":0}},
{"key":"2012-10-01T04:00:00.000Z","value":{"s200":100,"Year":2012,"s302":90}}
]"
/
var filter_2012= yearDim.filter("2012");
print_filter("filter_2012");
/
This prints the following:
"filter_2012(2) = [
{"date":"2012-10-01T04:00:00.000Z","hits":1,"tps":90,"http_status":"s302","Year":2012},
{"date":"2012-10-01T04:00:00.000Z","hits":1,"tps":100,"http_status":"s200","Year":2012}
]"
/
print_filter("tableGroup");
/
This prints the following. You can see the values are 0 except for year. Even when filtering on the date instead of year, the filter still keeps the key.
"tableGroup(4) = [
{"key":"2013-01-02T05:00:00.000Z","value":{"s200":0,"Year":2013,"s302":0}},
{"key":"2013-01-03T05:00:00.000Z","value":{"s200":0,"Year":2013,"s302":0}},
{"key":"2013-01-04T05:00:00.000Z","value":{"s200":0,"Year":2013,"s302":0}},
{"key":"2012-10-01T04:00:00.000Z","value":{"s200":100,"Year":2012,"s302":90}}
]"

*/

@RandomEtc
Copy link
Collaborator

Apologies for silence here. Please ask questions on http://stackoverflow.com/questions/tagged/crossfilter and note that as discussed in #151 an active fork is being developed in a new Crossfilter Organization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants