Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c.length undefined #84

Open
Brunocbarletta opened this issue Oct 18, 2020 · 3 comments
Open

c.length undefined #84

Brunocbarletta opened this issue Oct 18, 2020 · 3 comments

Comments

@Brunocbarletta
Copy link

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.

@EindbaasExpress
Copy link

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

@jadfls
Copy link

jadfls commented Jan 3, 2022

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
Copy link

jadfls commented Jan 4, 2022

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants