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

feat(rotation): consider adding rotation angle as well #20

Open
theonetheycallneo opened this issue Nov 30, 2022 · 0 comments
Open

feat(rotation): consider adding rotation angle as well #20

theonetheycallneo opened this issue Nov 30, 2022 · 0 comments

Comments

@theonetheycallneo
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch zoomable-svg@5.0.1 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/zoomable-svg/index.js b/node_modules/zoomable-svg/index.js
index 1b3f5e2..1667658 100644
--- a/node_modules/zoomable-svg/index.js
+++ b/node_modules/zoomable-svg/index.js
@@ -238,6 +238,7 @@ function getDerivedStateFromProps(props, state) {
 }
 
 function getZoomTransform({
+  angle,
   left,
   top,
   zoom,
@@ -247,6 +248,7 @@ function getZoomTransform({
   translateY,
 }) {
   return {
+    angle,
     translateX: left + zoom * translateX,
     translateY: top + zoom * translateY,
     scaleX: zoom * scaleX,
@@ -258,6 +260,7 @@ class ZoomableSvg extends Component {
   constructor(props) {
     super();
     this.state = getDerivedStateFromProps(props, {
+      angle: props.angle || 0,
       zoom: props.initialZoom || 1,
       left: props.initialLeft || 0,
       top: props.initialTop || 0,
@@ -430,7 +433,7 @@ class ZoomableSvg extends Component {
         initialTop: top,
         initialLeft: left,
         initialZoom: zoom,
-        initialDistance: distance,
+        initialDistance: distance
       });
     } else {
       const {
@@ -451,10 +454,14 @@ class ZoomableSvg extends Component {
       const top = (initialTop + dy - y) * touchZoom + y;
       const zoom = initialZoom * touchZoom;
 
+      let angle = (Math.atan2(y2-y1, x2-x1) * 180) / Math.PI 
+      console.log("??????tempAngle", angle)
+
       const nextState = {
         zoom,
         left,
         top,
+        angle
       };
 
       this.setState(constrain ? this.constrainExtent(nextState) : nextState);
@@ -473,7 +480,7 @@ class ZoomableSvg extends Component {
         initialY: y,
       });
     } else {
-      const { initialX, initialY, initialLeft, initialTop, zoom } = this.state;
+      const { initialX, initialY, initialLeft, initialTop, zoom, angle } = this.state;
       const { constrain } = this.props;
 
       const dx = x - initialX;
@@ -483,6 +490,7 @@ class ZoomableSvg extends Component {
         left: initialLeft + dx,
         top: initialTop + dy,
         zoom,
+        angle
       };
 
       this.setState(constrain ? this.constrainExtent(nextState) : nextState);
@@ -494,6 +502,7 @@ class ZoomableSvg extends Component {
       top: initialTop,
       left: initialLeft,
       zoom: initialZoom,
+      angle
     } = this.state;
     const { constrain } = this.props;
 
@@ -505,6 +514,7 @@ class ZoomableSvg extends Component {
       zoom,
       left,
       top,
+      angle
     };
 
     this.setState(constrain ? this.constrainExtent(nextState) : nextState);

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant