替换crossfilter数据,还原维度和组 [英] Replace crossfilter data, restore dimensions and groups

查看:105
本文介绍了替换crossfilter数据,还原维度和组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 dc.js 来渲染数据集的漂亮气泡图。潜在的dc.js是 crossfilter

I'm using dc.js to render a nice bubble chart of a dataset. Underlying dc.js is crossfilter.

我想顺利使用服务器中的新数据刷新我的图表。 Github上的这个问题明确表示可以通过以下方式执行此操作:

I'd like to smoothly refresh my chart with new data from the server. This issue on Github makes it clear that it is possible to do this by:


  1. 删除交叉过滤器中的所有数据

  2. 添加新数据

  3. 调用 dc.redrawAll()

  1. deleting all the data from the crossfilter
  2. adding in the new data
  3. calling dc.redrawAll().

我有这个工作,但为了删除所有数据,你首先必须清除所有过滤器(因为 crossfilter.remove 仅删除与当前过滤器)。

I've got this working but in order to delete all the data, you first have to clear all the filters (because crossfilter.remove only removes the records matching the current filter).

我想记住之前我的数据是如何过滤的,所以一旦我替换了所有数据,我就可以重新构建过滤器。我愿意深入了解 crossfilter 代码,但任何指针都会有所帮助。

I'd like to 'remember' how my data was filtered before, so I can reconstruct the filter again once I've replaced all the data. I'm willing to get into the guts of the crossfilter code, but any pointers would be helpful.

另外:如果有人知道基于唯一键更新crossfilter数据的方法,那就是金尘!

Additionally: if anyone knows a way of updating crossfilter data based on a unique key, that'd be gold dust!

推荐答案

感谢@ londonrob's回答现在从索引中删除所有数据。这是一种更实用的数据重置方法。

Thanks to @londonrob's Answer all data is now removed from the index. Here is a more functional approach for the resetting of data.

// reset the filter for a dimension
function resetDimensionFilter (dimension) {
  dimension.filter(null);
}

// reset filters for all given dimensions, 
// remove all data from index and
// return empty index
function resetData(ndx, dimensions) {
  // Clear all filters from dimensions, because `ndx.remove` 
  // only removes records matching the current filters.
  dimensions.forEach(resetDimensionFilter);

  // Remove all data from the cross filter
  ndx.remove();
}

这篇关于替换crossfilter数据,还原维度和组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆