【发布时间】:2017-05-03 12:18:13
【问题描述】:
我正在使用一些 D3 代码来整理我的 DC 箱线图,例如使 circle.outlier 半径更小,在每个箱线图后面插入一个矩形并附加一个悬停标题。
这在页面加载时效果很好。我希望它也可以用于过滤。它适用于一种过滤,而不适用于另一种过滤。
我在同一个仪表板上有一个直方图,并且使用 .brushOn(true),我有一个事件,它可以正确更新过滤器上的箱线图:
.on("filtered", function(obj){ update(); });
这段代码调用了下面的函数,该函数又调用了两个函数: (1) updateFactorFields2,它通过一个 fakegroup 更新箱线图后面的数据,并且似乎可以工作。和 (2) tidyBoxPlots,这就是问题所在。
function update() {
var grps = window.grps;//an array holding my crossfilter groups
var dims = window.dims; //an array holding CF dimensions
updateFactorFields2(grps[0]);
factorBox.render();//factorBox is my DC boxplot chart
tidyBoxPlots('postRender');
}
tidyBoxPlots 也会更新 .title,但下面的代码就足够了。 tidyBoxPlots 最终由 histChart.on("filtered",...) 触发时起作用。
function tidyBoxPlots(evType) {
d3.selectAll("circle.outlier").attr("r","2");//works in one case and not another
d3.selectAll("g.box").insert("rect","line.center").attr("x","0").attr("y","0").attr("width","8").attr("height","102.5").attr("class","boxHover");//ditto
}
但 tidyBoxPlots 在以下触发时不起作用,即使调用 update() 并且 updateFactorFields 起作用:
$("[id='filterDropdown']").on('change',function(e,p){
if (p.selected) {
var tempIndex = filters[0].indexOf(e.target.id);
filters[6][tempIndex].push(p.selected);//store this filter
filters[5][tempIndex].filterFunction(function(d){ return filters[6][tempIndex].indexOf(d)!=-1; });//filter the dimension stored in filters[5] by the array values stored in filters[6]
update();//calls update() fine
}
我很确定问题出在我正在使用的事件类型上,因为我之前遇到过这个问题。所以我已经尝试了大部分,如果不是所有这些,但没有快乐:
http://dc-js.github.io/dc.js/docs/html/dc.baseMixin.html#on
我在下拉菜单中使用了 selected.js,因此使用了 jquery。
谁能帮忙?
谢谢
【问题讨论】: