最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Filter for multiple discrete values in crossfilter - Stack Overflow

programmeradmin8浏览0评论

Does anyone have an approach to filtering a crossfilter object dimension on multiple values? Something like

.filterExact(["cash","visa"])

or

.filter(["cash","visa"])

...but not the range form of it...

or

.filterAll(["cash","visa"])

...but without the clearing part.

or an equivalent workaround/approach not using

.filterRange(["cash","visa"])

??

Or am I missing something in the API?

Thanks!

Larry

Does anyone have an approach to filtering a crossfilter object dimension on multiple values? Something like

.filterExact(["cash","visa"])

or

.filter(["cash","visa"])

...but not the range form of it...

or

.filterAll(["cash","visa"])

...but without the clearing part.

or an equivalent workaround/approach not using

.filterRange(["cash","visa"])

??

Or am I missing something in the API?

Thanks!

Larry

Share Improve this question edited Jun 16, 2012 at 4:05 Larry Battle 9,1784 gold badges43 silver badges55 bronze badges asked Jun 16, 2012 at 3:41 Larry HenglLarry Hengl 711 silver badge2 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 13

I was facing a similar problem. The way I solved it was that I wrote a filter function that would check whether the dimension lies in a particular array or not.

// Array of things you want to filter
var f = ["cash", "visa"];
// Assuming "dim" is our dimension
dim.filter(function(d){
  return f.indexOf(d) > -1;
});

This will check if the value lies in that array and filter accordingly.

Hope this helps.

The following pull request looks like it would address your needs, but it has not yet been merged in.

Multiple arguments to filter result in union of filter operations

Once merged you would be able to do something like the following.

data.total.filter("cash", "visa");

Which would result in the union of all filter criteria.

There doesn't seem to be anything in the API, but if you want to avoid filterRange, you could to it with two basic filters and concating the results:

var paymentsByType = payments.dimension(function(d) { return d.type; }),
cashAndVisaPayments = Array.prototype.concat(paymentsByType.filter('cash').top(Infinity),paymentsByType.filter('visa').top(Infinity))
发布评论

评论列表(0)

  1. 暂无评论