[英]D3 parcoords axis scale not updating correctly
I'm using the d3 parcoords library. 我正在使用d3 parcoords库。 When I modify data plotted in a parallel coordinates chart, and reload the chart, the scale of the axis isn't refreshed.
当我修改在平行坐标图中绘制的数据并重新加载该图时,不会刷新轴的比例。
I tried calling .autoscale()
, but if I call it before .render()
, it has no effect, and if I call it after .render()
, then no polylines are drawn anymore. 我打过电话
.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();
Not sure if this is related (although the issue started at the same time), I started specifying an order for the dimensions. 不知道这是否相关(尽管问题是同时开始的),我开始为尺寸指定顺序。 To do this, instead of using an array containing the axes (
dimensionArray
), I use a JS object dimensionObj
containing numbered "index" keys, as follows: 为此,我使用一个包含编号的“索引”键的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}
}
For illustration purposes, the following screenshots show how on the top image, the scales are properly set, but on the second (updated) chart, some new polylines are going to 0 on the 1st and 3rd axis, but the scale isn't updated so lines go out of range. 出于说明目的,以下屏幕截图显示了如何在顶部图像上正确设置比例,但是在第二张(更新的)图表上,一些新的折线在第一轴和第三轴上变为0,但是比例未更新所以线条超出范围。
Is there a simple way to refresh the axis scales when reloading a chart? 重新加载图表时,是否有一种简单的方法来刷新轴刻度? Is it possible that using the JS object in
.dimensions()
is creating some conflicts with the underlying scale function? 在
.dimensions()
中使用JS对象是否可能与基础scale函数产生一些冲突?
Found what was causing this behaviour: an if
statement in d3.parcoords.js pc.autoscale
function which was only resetting scales if the yscale
was not previously defined. 找到了导致此行为的原因:d3.parcoords.js
pc.autoscale
函数中的if
语句,仅在先前未定义yscale
下才重置比例。 Essentially I edited the if
statement from original: 从本质上讲,我编辑了原始的
if
语句:
d3.keys(__.dimensions).forEach(function(k) {
if (!__.dimensions[k].yscale){
__.dimensions[k].yscale = defaultScales[__.dimensions[k].type](k);
}
});
to this (of course the if
statement could be dropped altogether, I simply kept it in this form in case I need to revert to original version later for any reason): 为此(当然可以完全删除
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.