简体   繁体   English

d3:我的路径似乎在翻倍,我不知道为什么

[英]d3: My paths seem to be doubling up and I can't figure out why

I've been powering into D3, looking at samples by Mike Bostock and anyone else I can find, and brushing up on the documentation, and even have a book by Scott Murray on Interactive Data Visualization - a book on D3. 我一直在研究D3,研究了Mike Bostock和其他可以找到的人的样本,并整理了文档,甚至还有Scott Murray撰写的关于Interactive Data Visualization的书-关于D3的书。

I'm currently working on a connection chart, and I'm starting to understand enough to take this all beyond just changing out the data from a sample, but I am running into some problems still that I can't figure out. 我目前正在研究连接图,除了对样本中的数据进行更改之外,我已经开始了解足够的知识,但是我仍然遇到一些我无法弄清的问题。

Here's my sample link, http://www.nogumallowed.com/test4.php 这是我的示例链接, http://www.nogumallowed.com/test4.php

And here's my data, http://www.nogumallowed.com/userImages/friendData1.JSON 这是我的数据, http://www.nogumallowed.com/userImages/friendData1.JSON

This sample has seven people and the rest are all likes from facebook. 这个样本有7个人,其余的都来自facebook。 The chart shows the intersections of the likes between users. 该图显示了用户之间喜欢的交集。 My problem is with the paths, it seems that I'm adding double the paths necessary, and I'm not sure why. 我的问题是路径,似乎我要添加两倍的必要路径,但我不确定为什么。 I'm still getting familiar with the enter function, as well as the practice of selectiong something that isn't in the DOM to place it in the DOM. 我仍然熟悉enter函数,以及选择将DOM中没有的东西放置到DOM中的做法。

Just doing some counting from the code, there should be 115 paths, but I keep generating 230 paths. 仅从代码中进行一些计数,应该有115条路径,但是我一直在生成230条路径。

I'm still new enough to d3 that for the life of me, I can't figure this one out right now. 我仍然很新,可以d3以至于我一生都无法解决这个问题。

What I'd like to accomplish... When creating the gradients, the starting position should be blue when it's connected to a user, and then another various color for all of the likes. 我要完成的工作...创建渐变时,连接到用户时起始位置应为蓝色,然后为所有喜欢的颜色提供另一种颜色。 From the code I've put together, I don't believe there should ever be something that isn't a user start with blue, and a user should never have a line conencted to them that isn't blue at the base, but as you can see, i'm running into that. 从我编写的代码中,我不认为应该有一些不是用户以蓝色开头的内容,并且用户永远都不应在其上标出不是蓝色的底线,而是如您所见,我遇到了。


Edit: I've found that my problem isn't with grabbing the incorrect paths, it's having connections with A and B, and not knowing this point comes first in the path. 编辑:我发现我的问题不在于抓住不正确的路径,它与A和B有联系,并且不知道这一点首先出现在路径中。 If I want the path at connection A to always be blue, and the connection at path B to always be green, I don't have a way to detect that beyond this path simple has a source of A and a target of B, I don't know which will really come first. 如果我要使连接A处的路径始终为蓝色,而使路径B处的连接始终为绿色,那么我没有办法检测到,除了该路径以外,简单的源A和目标B不知道哪个会真正优先。 I'm updating my example script to a lighter version to see this. 我正在将示例脚本更新为较轻的版本,以查看此内容。

In this example, the 7 user names should always have blue coming from them, and everything else should always have red coming from them, but as you can see, that is definitely not always the case. 在此示例中,这7个用户名应始终带有蓝色,而其他所有名称都应始终带有红色,但是正如您所看到的,肯定并非总是如此。 This is where I am currently at a loss. 这是我目前不知所措的地方。

It looks like your data file actually contains 230 links: 看来您的数据文件实际上包含230个链接:

var n = 0;
classes.forEach(function(d) { n = n + d.imports.length; });
// n == 230

Also you have items with the same name in the data (eg classes[8] abd classes[115]) - may be it leads to some confusiion 另外,您在数据中具有相同名称的项(例如,classes [8] abd classes [115])-可能会导致一些混淆

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

相关问题 D3试图将SVG的属性设置为NaN,我无法弄清楚原因 - D3 is attempting to set attributes of SVG as NaN and I can't figure out why 我的javascript函数似乎无法正常工作。 我不知道为什么 - My javascript function doesn't seem to be working. I can't figure out why 我的CSS问题似乎无法弄清楚 - Issue with my CSS that I can't seem to figure out 我的CPU在Google Cloud上的使用率已达到160%,我似乎不知道为什么吗? - My CPU is reaching 160% on Google Cloud and I can't seem to figure out why? d3 v4为什么我不能让我的x轴和条形排列? - d3 v4 Why can't I get my x axis and bars to line up? 为什么我的角色不会移动? 我不明白为什么我的 Rigidbody 2D 不起作用 - Why won't my character move? I can't figure out why my Rigidbody 2D won't work 似乎无法弄清楚为什么我的JavaScript无法在IE和Chrome中运行 - Can't seem to figure out why my javascript isn't working in IE and Chrome 似乎无法弄清楚为什么我的 promise 阵列不工作 - Can't seem to figure out why my promise array isn't working 为什么我的D3 SVG图形上的轴不更新? - Why won't the axes on my D3 SVG figure update? 似乎无法弄清楚该脚本为何不起作用 - Can't seem to figure out why the script isn't working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM