You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/
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}}
]"
*/
The text was updated successfully, but these errors were encountered:
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}}
]"
*/
The text was updated successfully, but these errors were encountered: