aboutsummaryrefslogtreecommitdiffstats
path: root/playgrounds/matrix/drag.js
diff options
context:
space:
mode:
Diffstat (limited to 'playgrounds/matrix/drag.js')
-rw-r--r--playgrounds/matrix/drag.js50
1 files changed, 23 insertions, 27 deletions
diff --git a/playgrounds/matrix/drag.js b/playgrounds/matrix/drag.js
index 7609404..8f294ed 100644
--- a/playgrounds/matrix/drag.js
+++ b/playgrounds/matrix/drag.js
@@ -1,8 +1,6 @@
function reactToDrag(element, onDrag, beforeDrag) {
-
let xStart, yStart
- let startDrag = event => {
-
+ let startDrag = (event) => {
// Avoid the default events
event.preventDefault()
@@ -21,15 +19,13 @@ function reactToDrag(element, onDrag, beforeDrag) {
SVG.on(window, ['mouseup.drag', 'touchend.drag'], stopDrag)
}
- let reactDrag = event => {
-
+ let reactDrag = (event) => {
// Convert screen coordinates to svg coordinates and use them
var { x, y } = parent.point(event.pageX, event.pageY)
- if (onDrag)
- onDrag(event, x, y)
+ if (onDrag) onDrag(event, x, y)
}
- let stopDrag = event => {
+ let stopDrag = (event) => {
SVG.off(window, ['mousemove.drag', 'touchmove.drag'])
SVG.off(window, ['mouseup.drag', 'touchend.drag'])
}
@@ -42,27 +38,27 @@ function reactToDrag(element, onDrag, beforeDrag) {
SVG.extend(SVG.Element, {
draggable: function (after) {
-
let sx, sy
- reactToDrag(this, (e, x, y) => {
-
- this.transform({
- origin: [sx, sy],
- position: [x, y],
- })
-
- if (after) {
- after(this, x, y)
+ reactToDrag(
+ this,
+ (e, x, y) => {
+ this.transform({
+ origin: [sx, sy],
+ position: [x, y]
+ })
+
+ if (after) {
+ after(this, x, y)
+ }
+ },
+ (e, x, y) => {
+ var toAbsolute = new SVG.Matrix(this).inverse()
+ var p = new SVG.Point(x, y).transform(toAbsolute)
+ sx = p.x
+ sy = p.y
}
-
- }, (e, x, y) => {
-
- var toAbsolute = new SVG.Matrix(this).inverse()
- var p = new SVG.Point(x, y).transform(toAbsolute)
- sx = p.x
- sy = p.y
- })
+ )
return this
- },
+ }
})