Posts: 284
Joined: Thu Oct 04, 2012 12:16 pm

annotation add vs afterUpdate

below is the demo code..


in the above example if you add annotation.. first click on chart would fire add event.. then it will start firing afterUpdate event while user is dragging the annotation..

then try to drag/reposition the annotation.. same event(afterUpdate) would get fired..
is there a way to differentiate between those type.. like while user is adding Annotation.. it should not fire afterUpdate event.. until mouse is released..

i am trying to save annotations after user is re-positiong after dragging.. but not while adding..

Posts: 700
Joined: Tue Jan 24, 2023 11:21 am

Re: annotation add vs afterUpdate


Thanks for reaching out to us with your question!

Indeed, in API there are listed only four events attached to annotation (add, afterUpdate, click, remove). In fact, there is also a drag event attached, which isn't mentioned in API for uknown reason: https://github.com/highcharts/highchart ... #L900-L907.
The behaviour you described is because on creation of the annotation, the afterUpdate event is fired at every time the annotation is redrawn (and not fully drawn yet), which is different to when the annotation is already added and e.g. one of control points is moved around. As an answer to your question: you can distinct these events by refering to target hasDragged property, which on creation is undefined, and on drag event finish it changes to true. On afterUpdate event, it is changed to false.

Demo: https://jsfiddle.net/BlackLabel/fxp3voLy/

Let me know if you have any further questions!
Best regards!
Jędrzej Ruta
Highcharts Developer
Posts: 284
Joined: Thu Oct 04, 2012 12:16 pm

Re: annotation add vs afterUpdate

thanks for reply.. this would be really helpful.

Return to “Highcharts Stock”