简体   繁体   English

在选择格式为d.value的固定字段名称时避免D3.js“ groupData未定义”错误

[英]Avoiding D3.js “groupData is undefined” errors when selecting on fixed field name of form d.value

Probably trivial, but I seem to have a nested data situation for which I can find no guidance. 可能微不足道,但是我似乎有一个嵌套的数据情况,因此找不到任何指导。 I have an array representing an time progression (index) for which data is only intermittently available: 我有一个表示时间进度(索引)的数组,其数据只能间歇性地使用:

elem[..]
elem[55].path[..]
elem[56]
elem[57]
elem[58].path[..]
elem[59]
elem[60].path[..]
elem[..]

Empty data points are null: 空数据点为空:

elem[count] = null;

..whereas, pending further use, path elements are initialised using: ..而在进一步使用之前,使用以下方法初始化路径元素:

elem[count].path = [];

A large data set is gathered. 收集了一个大数据集。 In the first of the following two blocks of code, I select the array indexes 在以下两个代码块的第一个中,我选择数组索引

classes[chan_index].elem_num_container = "elem_num_container" + "_" + comp_id + "_" + chan_index;

chan_selector.elem_num_container[chan_index] = chan_selector.vis_container[chan_index]
.selectAll(classes[chan_index].elem_num_container)
.data(function(d, i) {
    return d;
})
.enter()
.append("svg:g")
.attr("class", function(d, i) {
    return classes[chan_index].elem_num_container;
});

Given so many null elements, in the second block (below), the nested d.path understandably provokes a "groupData is undefined" error. 给定这么多null元素,在第二个块(如下)中,嵌套的d.path可以理解地引发“ groupData is undefined”错误。

classes[chan_index].path_container = "path_container" + "_" + comp_id + "_" + chan_index;

chan_selector.path_container[chan_index] = chan_selector.elem_num_container[chan_index]
.selectAll(classes[chan_index].path_container)
.data(function(d, i) {
    return d.path;
})
.enter()
.append("svg:g")
.attr("class", function(d, i) {
    return classes[chan_index].path_container;
});

Basically it comes down to selecting data based on the "d" parameter, followed by a nested selection on "d.value". 基本上,归结为基于“ d”参数选择数据,然后是“ d.value”上的嵌套选择。 While preserving the index, I need to side-step the error and select d.path elements, where they exist. 在保留索引的同时,我需要回避错误并选择d.path元素(如果存在)。

I see plenty nested JSON data examples, but nothing applicable to this case. 我看到了大量嵌套的JSON数据示例,但没有适用于这种情况的示例。

Blocked, and grateful for any help.. Thx 被阻止,并感谢您的任何帮助。

From the responses above, elimination of null elements was clearly held to be feasible, throwing doubt on incoming data (checked: all ok) and d3 processing hierarchy (malformed: two processing branches hung on to the same node, one propagating data, the other -the branch in question above- not). 从上面的响应中,显然认为消除空元素是可行的,这对传入数据(已检查:一切正常)和d3处理层次结构(格式错误:两个处理分支挂在同一个节点上,一个正在传播数据,另一个正在处理)上产生了疑问。 -上面讨论的分支-否)。

In response, separated the two branches from their parent with new, interstitial svg:g container structures. 作为响应,使用新的插页式svg:g容器结构将两个分支与其父级分开。 Result: data on both branches. 结果:两个分支上的数据。

Then, as suggested in the responses above, with d.path, I added a filter on the processing branch in question (ie between first and second code blocks in the original question), in the form: 然后,按照上面的响应建议,使用d.path,我在相关处理分支(即原始问题的第一和第二代码块之间)中添加了一个过滤器,格式为:

chan_selector.temp[chan_index] = chan_selector.elem_num_container[chan_index]
.filter(function(d) { return typeof(d.path) === 'object'; });

Strangely (given claimed impact of filter on indexing) it works, giving the accustomed d3 eyecandy. 奇怪的是(考虑到滤镜对索引的影响),它发挥了作用,给了习惯的d3眼镜。 :-) :-)

Thanks to Superboggly and Lars Kotthoff for the valuable help and patience. 感谢Superboggly和Lars Kotthoff的宝贵帮助和耐心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM