Skip to content

Commit

Permalink
new(Zoom): update to handle null localPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Williams committed Oct 22, 2019
1 parent ff1e73b commit 745a201
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vx-zoom/src/Zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ class Zoom extends React.Component<ZoomProps, ZoomState> {
dragStart = (event: React.MouseEvent) => {
const { transformMatrix } = this.state;
const { translateX, translateY } = transformMatrix;
this.startPoint = localPoint(event);
this.startPoint = localPoint(event) || undefined;
this.startTranslate = { translateX, translateY };
this.setState({ isDragging: true });
};

dragMove = (event: React.MouseEvent) => {
if (!this.state.isDragging || !this.startPoint || !this.startTranslate) return;
const currentPoint = localPoint(event);
const dx = -(this.startPoint.x - currentPoint.x);
const dy = -(this.startPoint.y - currentPoint.y);
const dx = currentPoint ? -(this.startPoint.x - currentPoint.x) : -this.startPoint.x;
const dy = currentPoint ? -(this.startPoint.y - currentPoint.y) : -this.startPoint.y;
this.setTranslate({
translateX: this.startTranslate.translateX + dx,
translateY: this.startTranslate.translateY + dy,
Expand All @@ -240,7 +240,7 @@ class Zoom extends React.Component<ZoomProps, ZoomState> {
handleWheel = (event: React.WheelEvent | WheelEvent) => {
const { passive, wheelDelta } = this.props;
if (!passive) event.preventDefault();
const point = localPoint(event);
const point = localPoint(event) || undefined;
const { scaleX, scaleY } = wheelDelta!(event);
this.scale({ scaleX, scaleY, point });
};
Expand Down

0 comments on commit 745a201

Please sign in to comment.