svg.draw.js: .draw() usage is ambiguous
.draw() usage is ambiguous. Take the following code snippet:
const drawing = SVG('mua_logo')
drawing.on('dblclick', event => {
/* not working - click events are not handled */
//const line = drawing.polyline().draw(event)
const line = drawing.polyline().draw()
line.draw(event)
})
_live example: https://github.com/dotnetCarpenter/mua_
I’m not sure why, but if I do drawing.polyline().draw(event) as oppose to drawing.polyline().draw().draw(event), the click event is no longer handled by svg.draw.js.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- changes according to https://github.com/svgdotjs/svg.draw.js/issues/17#issuecomment-293220727 and https://github.com/svgdotjs/svg.draw.js/issues/16#issuecomment-293231233 - NOT WORKING — committed to dotnetCarpenter/mua by dotnetCarpenter 7 years ago
- changes according to https://github.com/svgdotjs/svg.draw.js/issues/17#issuecomment-293220727 and https://github.com/svgdotjs/svg.draw.js/issues/16#issuecomment-293231233 - NOT WORKING — committed to dotnetCarpenter/mua by dotnetCarpenter 7 years ago
Ok I try to explain the whole thing again: When you call
draw()with no parameter, it binds to theclickevent by default. However that means that it starts the drawing process when you click somewhere and not before. So when you want to set a point you need to do that manually by callingdraw('point', event)ordraw.event().When you do not want to bind click by default you need to pass an event argument which is instead used to start teh drawing process. However that means, that you need to manage the whole drawing process yourself. The plugin wont take over again.
So in your case: You want to start the drawing process on dblclick but after that you want to use click so you have 2 possibilities
draw()bind to click by defaultThats tested - it works. However - if you want to use click for points is easier to use the magic default bind. Hope its clear now how this all works. You have to manage the drawing process yourself entirely when you want control. The defaul click handler is just a bonus and for new people to have a result immidiately
I think this is a prime example! and something that should be in the readme. I might make a PR, if I find time and the right words. Thanks a lot!