MapPointer.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* *
  2. *
  3. * (c) 2010-2020 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. import Pointer from '../Core/Pointer.js';
  12. import U from '../Core/Utilities.js';
  13. var extend = U.extend, pick = U.pick, wrap = U.wrap;
  14. /* eslint-disable no-invalid-this */
  15. // Extend the Pointer
  16. extend(Pointer.prototype, {
  17. // The event handler for the doubleclick event
  18. onContainerDblClick: function (e) {
  19. var chart = this.chart;
  20. e = this.normalize(e);
  21. if (chart.options.mapNavigation.enableDoubleClickZoomTo) {
  22. if (chart.pointer.inClass(e.target, 'highcharts-tracker') &&
  23. chart.hoverPoint) {
  24. chart.hoverPoint.zoomTo();
  25. }
  26. }
  27. else if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  28. chart.mapZoom(0.5, chart.xAxis[0].toValue(e.chartX), chart.yAxis[0].toValue(e.chartY), e.chartX, e.chartY);
  29. }
  30. },
  31. // The event handler for the mouse scroll event
  32. onContainerMouseWheel: function (e) {
  33. var chart = this.chart, delta;
  34. e = this.normalize(e);
  35. // Firefox uses e.detail, WebKit and IE uses wheelDelta
  36. delta = e.detail || -(e.wheelDelta / 120);
  37. if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  38. chart.mapZoom(Math.pow(chart.options.mapNavigation.mouseWheelSensitivity, delta), chart.xAxis[0].toValue(e.chartX), chart.yAxis[0].toValue(e.chartY), e.chartX, e.chartY);
  39. }
  40. }
  41. });
  42. // The pinchType is inferred from mapNavigation options.
  43. wrap(Pointer.prototype, 'zoomOption', function (proceed) {
  44. var mapNavigation = this.chart.options.mapNavigation;
  45. // Pinch status
  46. if (pick(mapNavigation.enableTouchZoom, mapNavigation.enabled)) {
  47. this.chart.options.chart.pinchType = 'xy';
  48. }
  49. proceed.apply(this, [].slice.call(arguments, 1));
  50. });
  51. // Extend the pinchTranslate method to preserve fixed ratio when zooming
  52. wrap(Pointer.prototype, 'pinchTranslate', function (proceed, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch) {
  53. var xBigger;
  54. proceed.call(this, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch);
  55. // Keep ratio
  56. if (this.chart.options.chart.type === 'map' && this.hasZoom) {
  57. xBigger = transform.scaleX > transform.scaleY;
  58. this.pinchTranslateDirection(!xBigger, pinchDown, touches, transform, selectionMarker, clip, lastValidTouch, xBigger ? transform.scaleX : transform.scaleY);
  59. }
  60. });