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

TypeError: Cannot read property 'filter' of undefined in johnson.js #40

Open
architawr opened this issue Jan 29, 2020 · 3 comments
Open

Comments

@architawr
Copy link

architawr commented Jan 29, 2020

I use d3@5. Use this example https://bl.ocks.org/tomshanley/a434d47dc7ff983c764ccc555e89e295

import * as d3Sankey from 'd3-sankey-circular';

const sankey = d3Sankey
        .sankeyCircular()
        .nodeId(d => d.name)
        .nodeAlign(d3Sankey.sankeyJustify)
        .nodeWidth(12)
        .nodePadding(15)
        .nodePaddingRatio(0.5)
        .iterations(32)
        .size([width, height])

const sankeyData = sankey(data);

data

{
  nodes: [
   {name: 'new'},
   {name: 'confirmed'},
   ....
 ],
 links: [
   {target: 'new', source: 'confirmed', value: 10},
   .....
 ]  
}

And sankeyData not generated, but throw the error
image
johnson.js
image

And if i change nodeId to d => d.index (instead d => d.name) this error disappears and another appears
image

image

@HusseinElMotayam
Copy link

HusseinElMotayam commented Mar 11, 2020

Faced the same problem.
It seems that it'll choke if you have nodes that are not connected to any other node.

After some investigation, it looks like the non-connected nodes will leave a gap in the indices of the edges array in jonhson.js https://github.com/antoinerg/elementary-circuits-directed-graph/blob/master/johnson.js#L72
So, the sequential iteration will fail due to the missing indices.
The edges array will be similar to this in the case of non-connected nodes:

0: [1, 2]
1: [1]
2: [0]
// 3 missing. Will fail in the case of the sequential iteration
4: []

As a workaround, create an invisible node with invisible links to the non-connected nodes, and just don't draw those invisible node/links.
This will let d3-sankey-circular figure out locations for the non-connected nodes, and group them together (since they are connected with invisible links) and will not choke then.

@antoinerg
Copy link
Contributor

@HusseinElMotayam could you please open an issue over at https://github.com/antoinerg/elementary-circuits-directed-graph so we can fix the problem there?

Thank you

@HusseinElMotayam
Copy link

@antoinerg I logged it there. Thank you.

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

No branches or pull requests

3 participants