quim831
Posts: 82
Joined: Thu Feb 02, 2012 4:56 pm

Detect zoom through mouse dragging

Hi
I need to detect when zoom it's performed through mouse dragging and none of the other methods.
SetExtremes fires on every zoom operation.
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Detect zoom through mouse dragging

Hi, quim831!

Could you ask your question more precisely? You want to detect whether a zoom was caused by dragging mouse? For example, if we click the left mouse button, drag mouse and release the mouse button - then zoom is performed and you want to return true. But when we zoom differently, for example by setting extremes (not dragging mouse), you want to return false?

Kind regards
Rafal Sebestjanski,
Highcharts Team Lead
quim831
Posts: 82
Joined: Thu Feb 02, 2012 4:56 pm

Re: Detect zoom through mouse dragging

Hello

That' s exactly what I need:
" if we click the left mouse button, drag mouse and release the mouse button - then zoom is performed and you want to return true. But when we zoom differently, for example by setting extremes (not dragging mouse), you want to return false"

Regards
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Detect zoom through mouse dragging

Hi, quim831!

This is an example of how can you do this. You can wrap Highcharts.Pointer.prototype.dragStart function that fires when we start dragging. Then, inside that function, you can add to the chart object an extra info (chart.isZoomedByDrag = true;) that zoom was performed by dragging. I created a jsFiddle example for you: https://jsfiddle.net/BlackLabel/w5rme8yp/

Best regards!
Rafal Sebestjanski,
Highcharts Team Lead
quim831
Posts: 82
Joined: Thu Feb 02, 2012 4:56 pm

Re: Detect zoom through mouse dragging

Hello


That seems to be the way. My zoom is in the X Axis only, when changing the navigator bar width it identify the action as a mouse dragging mouse also. Comparing the mouseY to detect if it's clicking outside the Plot Chart area solve de problem. Thanks for your code.

Just a last question, what is the best way to detect the highest Y point that is clickable inside the Plot Area (identified by the red line in the picture)? In my case it's always a fixed value but just in case the chart may have a different size that could be dynamic.
Attachments
Highstock_max_y_px.png
Highstock_max_y_px.png (85.27 KiB) Viewed 2645 times
quim831
Posts: 82
Joined: Thu Feb 02, 2012 4:56 pm

Re: Detect zoom through mouse dragging

Ok, unless there is an easy way to get the highest y point after creating the chart, when building the chart this value may be calculated,. it's solved.
Regards
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Detect zoom through mouse dragging

I am not sure what exactly are you looking for, but you can easily find plot area's height, you can also easily find the coordinates of the point that has the biggest y value etc.
If you need anything, let me know.

Best regards
Rafal Sebestjanski,
Highcharts Team Lead

Return to “Highcharts Stock”