我有很多动态视图并动态创建了Crossfilter维度。我经常超过32的限制。所以我一直在处理它们,因为新的创建,但实际上很难一直跟踪它们。在开发期间获取所有交叉滤波器维度或至少其数量的列表会很有帮助。
(为了清楚,我不是在询问记录的数量,crossfilter.size())
谢谢!
答案 0 :(得分:0)
好建议。我基本上最终做到了这一点并且运作良好。
显示维度总数:
_.size(measureDimensions)
但更重要的是,将它们整合到一个物体中可以让我轻松地参考和处理它们:
var measureDimensions = {};
var measureGroups = {};
var measureCharts = {};
function generateCharts(entities) {
_.each(entities, function(entity){
// attach the charts to the following elements:
$('.js-measures-container').append('<div class="aligned-barchart" id="dc-'+entity'">')
// create dimensions and groups
measureDimensions[entity] = xf.dimension(function(d){ return d[entity] });
measureGroups[entity] = measureDimensions[entity].group().reduceCount();
// output the number of dimensions:
console.log('total dimensions: ', _.size(measureDimensions))
// generate chart
measureCharts[entity] = dc.barChart('#dc-'+entity)
.width(_.span(10))
.height(40)
.dimension(measureDimensions[entity])
.group(measureGroups[entity])
// etc...
})
};
// Code called by event handler that requires dimensions to be disposed:
function cleanup() {
_.each(measureDimensions, function(dim){ dim.dispose() });
_.each(measureGroups, function(group){ group.dispose() });
measureDimensions = {};
measureGroups = {};
measureCharts = {};
};
(我正在使用Underscore,但所有这些都可以用vanilla JS完成)