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

event.detail.p should be a SVG.Point #57

Open
dotnetCarpenter opened this issue Jan 9, 2020 · 0 comments
Open

event.detail.p should be a SVG.Point #57

dotnetCarpenter opened this issue Jan 9, 2020 · 0 comments
Assignees

Comments

@dotnetCarpenter
Copy link
Member

While creating an answer for https://stackoverflow.com/questions/59585107/how-do-i-draw-an-svg-polyline-with-45-degree/59652093#59652093, I found that all events emit a SVGPoint as p and not a SVG.Point.

The SVG.Point has the clone()method which is very useful when you want to store a point from an event for later use. Currently you will get a reference to the SVGPoint which changes with mousemove.

As an example:

let point
rect.on('drawstart', event => {
  point = event.detail.p
})

In the above snippet point will always update as the mouse moves because it is a reference.

The work-around is to get the primitive values and store them instead. As shown here:

const point = {x:0,y:0}
rect.on('drawstart', event => {
  const {x,y} = event.detail.p
  point.x = x
  point.y = y
})

But it would be much nicer if one could just use the clone() method. As in this example:

let point
rect.on('drawstart', event => {
  point = event.detail.p.clone()
})
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