MapPointer.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * (c) 2010-2019 Torstein Honsi
  3. *
  4. * License: www.highcharts.com/license
  5. */
  6. 'use strict';
  7. import H from '../parts/Globals.js';
  8. import '../parts/Utilities.js';
  9. import '../parts/Pointer.js';
  10. var extend = H.extend,
  11. pick = H.pick,
  12. Pointer = H.Pointer,
  13. wrap = H.wrap;
  14. // Extend the Pointer
  15. extend(Pointer.prototype, {
  16. // The event handler for the doubleclick event
  17. onContainerDblClick: function (e) {
  18. var chart = this.chart;
  19. e = this.normalize(e);
  20. if (chart.options.mapNavigation.enableDoubleClickZoomTo) {
  21. if (
  22. chart.pointer.inClass(e.target, 'highcharts-tracker') &&
  23. chart.hoverPoint
  24. ) {
  25. chart.hoverPoint.zoomTo();
  26. }
  27. } else if (
  28. chart.isInsidePlot(
  29. e.chartX - chart.plotLeft,
  30. e.chartY - chart.plotTop
  31. )
  32. ) {
  33. chart.mapZoom(
  34. 0.5,
  35. chart.xAxis[0].toValue(e.chartX),
  36. chart.yAxis[0].toValue(e.chartY),
  37. e.chartX,
  38. e.chartY
  39. );
  40. }
  41. },
  42. // The event handler for the mouse scroll event
  43. onContainerMouseWheel: function (e) {
  44. var chart = this.chart,
  45. delta;
  46. e = this.normalize(e);
  47. // Firefox uses e.detail, WebKit and IE uses wheelDelta
  48. delta = e.detail || -(e.wheelDelta / 120);
  49. if (chart.isInsidePlot(
  50. e.chartX - chart.plotLeft,
  51. e.chartY - chart.plotTop
  52. )) {
  53. chart.mapZoom(
  54. Math.pow(
  55. chart.options.mapNavigation.mouseWheelSensitivity,
  56. delta
  57. ),
  58. chart.xAxis[0].toValue(e.chartX),
  59. chart.yAxis[0].toValue(e.chartY),
  60. e.chartX,
  61. e.chartY
  62. );
  63. }
  64. }
  65. });
  66. // The pinchType is inferred from mapNavigation options.
  67. wrap(Pointer.prototype, 'zoomOption', function (proceed) {
  68. var mapNavigation = this.chart.options.mapNavigation;
  69. // Pinch status
  70. if (pick(mapNavigation.enableTouchZoom, mapNavigation.enabled)) {
  71. this.chart.options.chart.pinchType = 'xy';
  72. }
  73. proceed.apply(this, [].slice.call(arguments, 1));
  74. });
  75. // Extend the pinchTranslate method to preserve fixed ratio when zooming
  76. wrap(
  77. Pointer.prototype,
  78. 'pinchTranslate',
  79. function (
  80. proceed,
  81. pinchDown,
  82. touches,
  83. transform,
  84. selectionMarker,
  85. clip,
  86. lastValidTouch
  87. ) {
  88. var xBigger;
  89. proceed.call(
  90. this,
  91. pinchDown,
  92. touches,
  93. transform,
  94. selectionMarker,
  95. clip,
  96. lastValidTouch
  97. );
  98. // Keep ratio
  99. if (this.chart.options.chart.type === 'map' && this.hasZoom) {
  100. xBigger = transform.scaleX > transform.scaleY;
  101. this.pinchTranslateDirection(
  102. !xBigger,
  103. pinchDown,
  104. touches,
  105. transform,
  106. selectionMarker,
  107. clip,
  108. lastValidTouch,
  109. xBigger ? transform.scaleX : transform.scaleY
  110. );
  111. }
  112. }
  113. );