如何让 crossfilter.js 识别正在添加或删除的项目

how to make crossfilter.js recognize items being added or removed

我正在开发 meteor.js 应用程序,它利用 d3.js 和 crossfilter.js 创建交互式多图表交叉筛选仪表板。 所需功能的一个重要部分是在将记录添加到基础 MongoDB 集合或从中删除记录时实时调整各个图表。 反应性部分不是问题 -

Template.chart.rendered = function () {

        Tracker.autorun(function(){
                yelp_data = Yelp.find().fetch();
            console.log('autorun is called');
        });
}

问题是让 crossfilter 知道这些变化,我希望这会迫使各个图表重新调整以响应 crossfilter 的变化。

只需将以下行添加到自动运行:

Tracker.autorun(function(){
                yelp_data = Yelp.find().fetch();
                ndx = crossfilter(yelp_data);
            console.log('autorun is called');
        });

没有任何区别。 我还需要做什么来调整这些图表?

您需要使用 crossfilter.add and crossfilter.remove to add and remove data from a Crossfilter that has already been created. Crossfilter.remove is annoying because it requires you to change your filters in place to remove specific records. It's on a very long todo-list to fix this pull request 来允许删除任意记录。

更新交叉过滤器后,您将需要触发更新基于交叉过滤器的任何图表。如果您正在使用 dc.js,这只是为您定义的任何图表组调用 dc.redrawAll 的问题。