d3-sankey icon indicating copy to clipboard operation
d3-sankey copied to clipboard

c.length undefined

Open Brunocbarletta opened this issue 4 years ago • 3 comments

c length error c length

Hablo español pero en resumen ese es el problema, dentro de la funcion sankey()--> computenodebreaths() "c is undefined" y "columnas" ciertamente si tiene datos. Ojala puedan guiarme.

I speak Spanish but in summary that is the problem, inside the sankey () -> computenodebreaths () function "c is undefined" and "columns" certainly do have data. Hopefully you can guide me.

Brunocbarletta avatar Oct 18 '20 21:10 Brunocbarletta

Hi @Brunocbarletta ,

Not sure if this is still relevant for you, but there is a quick fix that you can use. The c.length-issue in the computeNodeBreaths is caused by an issue in the computeNodeLayers-function. Specifically in this line: const i = Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x)))); align.call expects 2 arguments, but gets 3.

Additionally, in my project the function behind align.call was replaced with the content of the constant.js, so I also changed the function that is called.

So if (1) you add a function that does what is needed:

  var alignReplaced = function r(n, t) {  
    return n.sourceLinks.length ? n.depth : t - 1;
  }

Then (2) you can replace the incorrect line with: const i = Math.max(0, Math.min(x - 1, Math.floor(alignReplaced(node, x))));

Like this: d3Sankey_fix

This solved my issue, but I'm not 100% sure on the complete context and pull requests are not really merged.

So hopefully this helps someone out there.

Best, Arne

EindbaasExpress avatar Jul 14 '21 14:07 EindbaasExpress

I have the same problem. Can we get this fixed?

I try the following which gives the error "undefined is not an object (evaluating 'c.length')

  const { nodes, links } = sankey()
    .nodeWidth(2)
    .nodePadding(10)
    .nodeAlign(d3.sankeyLeft)
    .extent([[1, 1], [width - 1, height - 1]])(data)

@EindbaasExpress I modified the sankey.js in node_modules as you said but it did not fix the problem.

jadfls avatar Jan 03 '22 22:01 jadfls

I fixed it in d3-sankey.js line 12-28 by adding the missing parameter n to the functions

function left(node, n) {
  return node.depth;
}

function right(node, n) {
  return n - 1 - node.height;
}

function justify(node, n) {
  return node.sourceLinks.length ? node.depth : n - 1;
}

function center(node, n) {
  return node.targetLinks.length ? node.depth
      : node.sourceLinks.length ? d3Array.min(node.sourceLinks, targetDepth) - 1
      : 0;
}

jadfls avatar Jan 04 '22 09:01 jadfls