D3 parcoords 轴刻度未正确更新
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();
不确定这是否相关(尽管问题同时开始),我开始指定维度的顺序。为此,我没有使用包含轴 (dimensionArray
) 的数组,而是使用包含编号 "index" 键的 JS 对象 dimensionObj
,如下所示:
//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}
}
出于说明目的,以下屏幕截图显示了如何在顶部图像上正确设置比例,但在第二个(更新的)图表上,一些新折线在第 1 和第 3 轴上变为 0,但是比例尺未更新,因此线条超出范围。
有没有一种简单的方法可以在重新加载图表时刷新坐标轴刻度?是否有可能在 .dimensions()
中使用 JS 对象与底层缩放函数产生一些冲突?
找到导致此行为的原因: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);
}
});
我正在使用 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();
不确定这是否相关(尽管问题同时开始),我开始指定维度的顺序。为此,我没有使用包含轴 (dimensionArray
) 的数组,而是使用包含编号 "index" 键的 JS 对象 dimensionObj
,如下所示:
//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}
}
出于说明目的,以下屏幕截图显示了如何在顶部图像上正确设置比例,但在第二个(更新的)图表上,一些新折线在第 1 和第 3 轴上变为 0,但是比例尺未更新,因此线条超出范围。
有没有一种简单的方法可以在重新加载图表时刷新坐标轴刻度?是否有可能在 .dimensions()
中使用 JS 对象与底层缩放函数产生一些冲突?
找到导致此行为的原因: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);
}
});