[英]D3 parcoords axis scale not updating correctly
我正在使用d3 parcoords库。 当我修改在平行坐标图中绘制的数据并重新加载该图时,不会刷新轴的比例。
我打过电话.autoscale()
但如果我之前把它.render()
它没有任何效果,如果我以后把它.render()
则没有折线了绘制。
$("#example").html(""); //to make sure "ghost" axes are removed
parcoords = d3.parcoords()("#example")
.data(parsedData)
.createAxes()
.brushMode("1D-axes")
.reorderable()//;
.detectDimensions()
.dimensions(dimensionObj)
.autoscale() //no visible effect if placed here
.render()
.updateAxes();
不知道这是否相关(尽管问题是同时开始的),我开始为尺寸指定顺序。 为此,我使用一个包含编号的“索引”键的JS对象dimensionObj
,而不是使用包含轴的数组( dimensionArray
),如下所示:
//dimensionArray = ["axis1", "axis2", "axis3", "axis4"]; //orderless array
//Default axes to display with predefined ordering
dimensionObj = {
"axis1": {index:0},
"axis2": {index:1},
"axis3": {index:2},
"axis4": {index:3}
}
出于说明目的,以下屏幕截图显示了如何在顶部图像上正确设置比例,但是在第二张(更新的)图表上,一些新的折线在第一轴和第三轴上变为0,但是比例未更新所以线条超出范围。
重新加载图表时,是否有一种简单的方法来刷新轴刻度? 在.dimensions()
中使用JS对象是否可能与基础scale函数产生一些冲突?
找到了导致此行为的原因:d3.parcoords.js pc.autoscale
函数中的if
语句,仅在先前未定义yscale
下才重置比例。 从本质上讲,我编辑了原始的if
语句:
d3.keys(__.dimensions).forEach(function(k) {
if (!__.dimensions[k].yscale){
__.dimensions[k].yscale = defaultScales[__.dimensions[k].type](k);
}
});
为此(当然可以完全删除if
语句,我只是以这种形式保留了它,以防万一我出于某种原因以后需要恢复到原始版本):
d3.keys(__.dimensions).forEach(function(k) {
if (!__.dimensions[k].yscale || __.dimensions[k].yscale){
__.dimensions[k].yscale = defaultScales[__.dimensions[k].type](k);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.