Skip to content

Commit

Permalink
Merge pull request #145 from uber/fix_getbbox_zoom
Browse files Browse the repository at this point in the history
Fix 'Cannot read property 'getBBox' of null' error when remounting
  • Loading branch information
ajbogh authored Jul 11, 2019
2 parents d2a28e0 + 40692f0 commit b4219d3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/graph-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
// Manually render the first view.
this.renderView();
setTimeout(() => {
if (this.viewWrapper != null) {
if (this.viewWrapper.current != null) {
this.handleZoomToFit();
}
}, zoomDelay);
Expand Down Expand Up @@ -1074,6 +1074,11 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
// Zooms to contents of this.refs.entities
handleZoomToFit = () => {
const entities = d3.select(this.entities).node();

if (!entities) {
return;
}

const viewBBox = entities.getBBox ? entities.getBBox() : null;

if (!viewBBox) {
Expand All @@ -1084,6 +1089,10 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
};

handleZoomToFitImpl = (viewBBox: IBBox, zoomDur: number) => {
if (!this.viewWrapper.current) {
return;
}

const parent = d3.select(this.viewWrapper.current).node();
const width = parent.clientWidth;
const height = parent.clientHeight;
Expand Down

0 comments on commit b4219d3

Please sign in to comment.