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

Sankey sorting #269

Merged
merged 2 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/SankeyDiagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ export default class SankeyDiagram extends React.Component {
* or accessor function which returns a style object.
*/
nodeStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
/**
* Node sort function
*/
nodeSort: PropTypes.func,
/**
* Node `mouseenter` event handler, called when user's mouse enters a node.
*/
Expand Down Expand Up @@ -580,6 +584,10 @@ export default class SankeyDiagram extends React.Component {
* or accessor function which returns a class (string).
*/
linkClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Link sort function
*/
linkSort: PropTypes.func,
/**
* Inline style object to be applied to each link,
* or accessor function which returns a style object.
Expand Down Expand Up @@ -992,6 +1000,8 @@ export default class SankeyDiagram extends React.Component {
.nodeId(props.nodeId)
.nodeWidth(props.nodeWidth)
.nodePadding(props.nodePadding)
.nodeSort(props.nodeSort)
.linkSort(props.linkSort)
.nodeAlign(
nodeAlignmentsByName[props.nodeAlignment] ||
nodeAlignmentsByName.justify,
Expand Down
20 changes: 15 additions & 5 deletions src/ZoomContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ export default class ZoomContainer extends React.Component {

state = { lastZoomTransform: null, selection: null };

constructor(props) {
super(props);
this.svgRef = React.createRef();
}

componentDidMount() {
const initialZoomTransform = zoomTransformFromProps(this.props);
const selection = d3.select(this.refs.svg);
const selection = d3.select(this.svgRef.current);

this.zoom = d3.zoom();
selection.call(this.zoom);
Expand Down Expand Up @@ -225,12 +230,17 @@ export default class ZoomContainer extends React.Component {
}

render() {
const zoomTransform = this.refs.svg
? d3.zoomTransform(this.refs.svg)
: null;
const zoomTransform =
this.svgRef && this.svgRef.current
? d3.zoomTransform(this.svgRef.current)
: null;

return (
<svg ref="svg" width={this.props.width} height={this.props.height}>
<svg
ref={this.svgRef}
width={this.props.width}
height={this.props.height}
>
<g
width={this.props.width}
height={this.props.height}
Expand Down