简体   繁体   English

来自 CSV 渲染的 D3 Sankey 图不正确

[英]D3 Sankey diagram from CSV rendering incorrectly

I am trying to make a Sankey Diagram using d3js.我正在尝试使用 d3js 制作桑基图。 I am using a csv data source and using code based on this block: http://bl.ocks.org/d3noob/c9b90689c1438f57d649我正在使用 csv 数据源并使用基于此块的代码: http : //bl.ocks.org/d3noob/c9b90689c1438f57d649

My dataset is quite large, but I think I should be under the threshold where I would be breaking the SVG renderer.我的数据集非常大,但我认为我应该低于破坏 SVG 渲染器的阈值。 I am unsure though.我不确定。 My code is functional when running with the 1082 line "SankeyDataSampleFunctional.csv".使用 1082 行“SankeyDataSampleFunctional.csv”运行时,我的代码可以正常工作。 Here is what it looks like:这是它的样子: 工作代码

I have made some slight modifications to the original codebase to allow for my diagram to have substantially larger amounts nodes at some layers while others don't.我对原始代码库进行了一些细微的修改,以允许我的图表在某些层有大量节点,而其他层则没有。 This is my attempt at accommodating it in sankey.js:这是我在 sankey.js 中适应它的尝试:

 function initializeNodeDepth() {
  var ky = d3.min(nodesByBreadth, function(nodes) {
    if (nodes.length > 200){
      return (size[1] - (nodes.length - 1) * 1) / d3.sum(nodes, value);
    }
    else if (nodes.length > 1000) {
      console.log((size[1] - (nodes.length - 1) * 1) / d3.sum(nodes, value))
      return (size[1] - (nodes.length - 1) * 1) / d3.sum(nodes, value);
    }
    return (size[1] - (nodes.length - 1) * nodePadding) / d3.sum(nodes, 
    value);
  });

I'm doing this to clamp down the space between nodes on layers with large numbers.我这样做是为了压缩大量层上节点之间的空间。 But when I try to add the last layer with 2102 more nodes I get all sorts of problems.但是当我尝试添加具有 2102 个节点的最后一层时,我遇到了各种各样的问题。 This is what it looks like when I plug in "SankeyDataSample1.csv" into the same code in question:这是当我将“SankeyDataSample1.csv”插入到相同的代码中时的样子:

第一个错误

I checked the console and its saying I'm trying to draw a bunch of stuff with negative height.我检查了控制台,它说我正在尝试绘制一堆负高度的东西。 My first recourse was to clip 2101 of those 2102 extra nodes off, to see if i could get just one node to render correctly on the following layer.我的第一个办法是剪掉那 2102 个额外节点中的 2101 个,看看我是否可以让一个节点在下一层正确渲染。 of course not:当然不是:

在此处输入图片说明

I tried adding some additional depth to that branch and it continues to render the branch in the wrong direction:我尝试向该分支添加一些额外的深度,但它继续以错误的方向呈现分支:

在此处输入图片说明

finally, i checked this post about someone else who was using large datasets in a d3 sankey: Large data set breaks d3 sankey diagram最后,我查看了这篇关于在 d3 sankey 中使用大型数据集的其他人的帖子: 大型数据集破坏了 d3 sankey 图表

I attempt the 'quick fix' of forcing my height to be nonzero seen in this post:我尝试在这篇文章中看到强制我的高度非零的“快速修复”:

    .attr("height", function(d) { return d.dy < 0 ? 0 : d.y; })

However this didnt do much for me.然而,这对我没有多大作用。 I also tried multiplying negative values of d.dy by -1 with a hope to invert them and this is all i got:我还尝试将 d.dy 的负值乘以 -1 以希望反转它们,这就是我得到的全部:

在此处输入图片说明

Here is my code: http://plnkr.co/edit/g2rE0z?p=info这是我的代码: http : //plnkr.co/edit/g2rE0z?p=info

Am I up at the limits of SVG with that last 2k nodes?我在最后 2k 个节点上达到了 SVG 的极限吗? Or am I just going about this wrong?或者我只是在做这个错误? Any assistance would be appreciated.任何援助将不胜感激。

Have you tried to enlarge canvas size?您是否尝试过放大画布尺寸? Usually, in my case, if there's no space left for nodes, it renders like that.通常,在我的情况下,如果节点没有剩余空间,它会像这样呈现。

您可能想查看我在此处发布的答案: 大型数据集破坏 d3 桑基图想法是您可以重新生成具有新宽度和新高度的图形,直到每个节点都具有适当的高度。

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

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