Skip to content

Commit

Permalink
Sankey sorting (#269)
Browse files Browse the repository at this point in the history
* remove deprecated refs definition

This old usage of defining refs via a string is deprecated and seems to break when debugging reactochart using `npm link` locally.

* add Sankey Sorting Function hooks

Co-authored-by: Isaac Ezer <[email protected]>
  • Loading branch information
iezer and siezerp authored Oct 30, 2020
1 parent 17a07bd commit ceead23
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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

0 comments on commit ceead23

Please sign in to comment.