Skip to content

Commit b5c4389

Browse files
committed
(fix) Fix movement when scale is not 1.
1 parent 7051026 commit b5c4389

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/GraphViewer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ function translate (x, y, transform) {
66
return [transform[0] + x, transform[1] + y, transform[2]]
77
}
88

9+
const styles = {
10+
container: {
11+
userSelect: 'none'
12+
}
13+
}
14+
915
export default class GraphViewer extends React.Component {
1016
constructor (props) {
1117
super(props)
@@ -24,7 +30,10 @@ export default class GraphViewer extends React.Component {
2430

2531
if (this.state.mouseDown) {
2632
this.setState({
27-
transform: translate(event.clientX - this.state.moveStartPosition.x, event.clientY - this.state.moveStartPosition.y, this.state.transform),
33+
transform: translate(
34+
(event.clientX - this.state.moveStartPosition.x) / this.state.transform[2],
35+
(event.clientY - this.state.moveStartPosition.y) / this.state.transform[2],
36+
this.state.transform),
2837
moveStartPosition: {
2938
x: event.clientX,
3039
y: event.clientY
@@ -73,7 +82,7 @@ export default class GraphViewer extends React.Component {
7382
return (
7483
<GraphLayouter
7584
ref={(graph) => { this._graph = graph }}
76-
style={this.props.style}
85+
style={{ ...styles.container, ...this.props.style }}
7786
translateX={transform[0]}
7887
translateY={transform[1]}
7988
scale={transform[2]}

0 commit comments

Comments
 (0)