d3-sankey
d3-sankey copied to clipboard
c.length undefined
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.
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:
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
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.
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;
}