Gathering detailed insights and metrics for @plotly/d3-sankey-circular
Gathering detailed insights and metrics for @plotly/d3-sankey-circular
Gathering detailed insights and metrics for @plotly/d3-sankey-circular
Gathering detailed insights and metrics for @plotly/d3-sankey-circular
A fork of the d3-sankey library to allow circular links.
npm install @plotly/d3-sankey-circular
99.3
Supply Chain
99.6
Quality
82.1
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
103 Commits
1 Forks
3 Watching
3 Branches
9 Contributors
Updated on 03 Jun 2024
Minified
Minified + Gzipped
JavaScript (99.27%)
HTML (0.73%)
Cumulative downloads
Total Downloads
Last day
-13.2%
32,612
Compared to previous day
Last week
-3.3%
178,153
Compared to previous week
Last month
3.6%
787,198
Compared to previous month
Last year
9.1%
8,742,584
Compared to previous year
A fork of the d3-sankey library (https://github.com/d3/d3-sankey) to allow circular links (ie cyclic graphs, like in this example).
The library contains a portion of code from Colin Fergus' bl.ock https://gist.github.com/cfergus/3956043 to detect circular links.
If you use NPM, npm install d3-sankey-circular
.
Else, use the d3-sankey-circular.js file from the compiled folder.
var sankey = d3.sankeyCircular();
The API follows the original d3-sankey library, with additional options to allow the circular links to be laid out and drawn.
Constructs a new Sankey generator with the default settings.
Computes the node and link positions for the given arguments, returning a graph representing the Sankey layout. The returned graph has the following properties:
# sankey.update(graph)
Recomputes the specified graph’s links’ positions, updating the following properties of each link:
This method is intended to be called after computing the initial Sankey layout, for example when the diagram is repositioned interactively.
If nodes is specified, sets the Sankey generator’s nodes accessor to the specified function or array and returns this Sankey generator. If nodes is not specified, returns the current nodes accessor, which defaults to:
1function nodes(graph) { 2 return graph.nodes; 3}
If nodes is specified as a function, the function is invoked when the Sankey layout is generated, being passed any arguments passed to the Sankey generator. This function must return an array of nodes. If nodes is not a function, it must be a constant array of nodes.
Each node must be an object. The following properties are assigned by the Sankey generator:
See also sankey.links.
If links is specified, sets the Sankey generator’s links accessor to the specified function or array and returns this Sankey generator. If links is not specified, returns the current links accessor, which defaults to:
1function links(graph) { 2 return graph.links; 3}
If links is specified as a function, the function is invoked when the Sankey layout is generated, being passed any arguments passed to the Sankey generator. This function must return an array of links. If links is not a function, it must be a constant array of links.
Each link must be an object with the following properties:
For convenience, a link’s source and target may be initialized using numeric or string identifiers rather than object references; ; see sankey.nodeId. The following properties are assigned to each link by the Sankey generator:
For any links that circular (link.circular = true), the following properties are assigned
If id is specified, sets the node id accessor to the specified function and returns this Sankey generator. If id is not specified, returns the current node id accessor, which defaults to the numeric node.index:
1function id(d) { 2 return d.index; 3}
The default id accessor allows each link’s source and target to be specified as a zero-based index into the nodes array. For example:
1var nodes = [ 2 {"id": "Alice"}, 3 {"id": "Bob"}, 4 {"id": "Carol"} 5]; 6 7var links = [ 8 {"source": 0, "target": 1}, // Alice → Bob 9 {"source": 1, "target": 2} // Bob → Carol 10];
Now consider a different id accessor that returns a string:
1function id(d) { 2 return d.id; 3}
With this accessor, you can use named sources and targets:
1var nodes = [ 2 {"id": "Alice"}, 3 {"id": "Bob"}, 4 {"id": "Carol"} 5]; 6 7var links = [ 8 {"source": "Alice", "target": "Bob"}, 9 {"source": "Bob", "target": "Carol"} 10];
# sankey.nodeAlign([align]) <>
If align is specified, sets the node alignment method the specified function and returns this Sankey generator. If align is not specified, returns the current node alignment method, which defaults to d3.sankeyJustify. The specified function is evaluated for each input node in order, being passed the current node and the total depth n of the graph (one plus the maximum node.depth), and must return an integer between 0 and n - 1 that indicates the desired horizontal position of the node in the generated Sankey diagram.
# sankey.nodeWidth([width]) <>
If width is specified, sets the node width to the specified number and returns this Sankey generator. If width is not specified, returns the current node width, which defaults to 24.
# sankey.nodePadding([padding]) <>
If padding is specified, sets the vertical separation between nodes at each column to the specified number and returns this Sankey generator. If padding is not specified, returns the current node padding, which defaults to 8.
# sankey.nodePaddingRatio([proportion]) <>
If proportion is specified (from 0 to 1), sets the vertical separation between nodes at each column to the specified number and returns this Sankey generator. The proportion is applied to the most dense column of nodes, and calculates a minimum padding that will be used across the chart.
If a nodePaddingRatio is not specified, then defaults to the padding setting in pixels.
If extent is specified, sets the extent of the Sankey layout to the specified bounds and returns the layout. The extent bounds are specified as an array [[x0, y0], [x1, y1]], where x0 is the left side of the extent, y0 is the top, x1 is the right and y1 is the bottom. If extent is not specified, returns the current extent which defaults to [[0, 0], [1, 1]].
An alias for sankey.extent where the minimum x and y of the extent are ⟨0,0⟩. Equivalent to:
1sankey.extent([[0, 0], size]);
# sankey.iterations([iterations]) <>
If iterations is specified, sets the number of relaxation iterations when generating the layout and returns this Sankey generator. If iterations is not specified, returns the current number of relaxation iterations, which defaults to 32.
# sankey.circularLinkGap([circularLinkGap]) <>
If circularLinkGap is specified, sets the gap (in pixels) between circular links that travel next to each other. If circularLinkGap, it defaults to 2.
See sankey.nodeAlign.
# d3.sankeyLeft(node, n)
Returns node.depth.
# d3.sankeyRight(node, n)
Returns n - 1 - node.height.
# d3.sankeyCenter(node, n)
Like d3.sankeyLeft, except that nodes without any incoming links are moved as right as possible.
# d3.sankeyJustify(node, n)
Like d3.sankeyLeft, except that nodes without any outgoing links are moved to the far right.
Each link has a .path property which stores the svg path d string, which can be accessed to draw the path, for example
1 2svg.append("g") 3 .attr("class", "links") 4 .attr("fill", "none") 5 .attr("stroke-opacity", 0.2) 6 .selectAll("path"); 7 .data(sankey.links) 8 .enter() 9 .append("path") 10 .attr("d", function(d){ 11 return d.path; 12 }) 13 .style("stroke-width", function (link) { link.width; }) 14 .style("stroke", function (link, i) { 15 return link.circular ? "red" : "black" 16 })
For normal paths, the path string is created by the d3-shape linkHorizontal function. For circular paths, the path string is calculated to reduced overlaps with other nodes and paths.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
project is archived
Details
Reason
Found 1/27 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
42 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More