ControlPoint.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* *
  2. *
  3. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4. *
  5. * */
  6. /**
  7. * Callback to modify annotation's possitioner controls.
  8. *
  9. * @callback Highcharts.AnnotationControlPointPositionerFunction
  10. * @param {Highcharts.AnnotationControlPoint} this
  11. * @param {Highcharts.AnnotationControllable} target
  12. * @return {Highcharts.PositionObject}
  13. */
  14. import U from '../../Core/Utilities.js';
  15. var extend = U.extend, merge = U.merge, pick = U.pick;
  16. import eventEmitterMixin from './Mixins/EventEmitterMixin.js';
  17. /* eslint-disable no-invalid-this, valid-jsdoc */
  18. /**
  19. * A control point class which is a connection between controllable
  20. * transform methods and a user actions.
  21. *
  22. * @requires modules/annotations
  23. *
  24. * @class
  25. * @name Highcharts.AnnotationControlPoint
  26. *
  27. * @hideconstructor
  28. *
  29. * @param {Highcharts.Chart} chart
  30. * A chart instance.
  31. *
  32. * @param {Highcharts.AnnotationControllable} target
  33. * A controllable instance which is a target for a control point.
  34. *
  35. * @param {Highcharts.AnnotationControlPointOptionsObject} options
  36. * An options object.
  37. *
  38. * @param {number} [index]
  39. * Point index.
  40. */
  41. var ControlPoint = /** @class */ (function () {
  42. function ControlPoint(chart, target, options, index) {
  43. /**
  44. *
  45. * Properties
  46. *
  47. */
  48. this.addEvents = eventEmitterMixin.addEvents;
  49. this.graphic = void 0;
  50. this.mouseMoveToRadians = eventEmitterMixin.mouseMoveToRadians;
  51. this.mouseMoveToScale = eventEmitterMixin.mouseMoveToScale;
  52. this.mouseMoveToTranslation = eventEmitterMixin.mouseMoveToTranslation;
  53. this.onDrag = eventEmitterMixin.onDrag;
  54. this.onMouseDown = eventEmitterMixin.onMouseDown;
  55. this.onMouseUp = eventEmitterMixin.onMouseUp;
  56. this.removeDocEvents = eventEmitterMixin.removeDocEvents;
  57. /**
  58. *
  59. * Functions
  60. *
  61. */
  62. /**
  63. * List of events for `anntation.options.events` that should not be
  64. * added to `annotation.graphic` but to the `annotation`.
  65. * @private
  66. * @name Highcharts.AnnotationControlPoint#nonDOMEvents
  67. * @type {Array<string>}
  68. */
  69. this.nonDOMEvents = ['drag'];
  70. this.chart = chart;
  71. this.target = target;
  72. this.options = options;
  73. this.index = pick(options.index, index);
  74. }
  75. /**
  76. * Set the visibility of the control point.
  77. *
  78. * @function Highcharts.AnnotationControlPoint#setVisibility
  79. *
  80. * @param {boolean} visible
  81. * Visibility of the control point.
  82. *
  83. * @return {void}
  84. */
  85. ControlPoint.prototype.setVisibility = function (visible) {
  86. this.graphic.attr('visibility', visible ? 'visible' : 'hidden');
  87. this.options.visible = visible;
  88. };
  89. /**
  90. * Render the control point.
  91. * @private
  92. */
  93. ControlPoint.prototype.render = function () {
  94. var chart = this.chart, options = this.options;
  95. this.graphic = chart.renderer
  96. .symbol(options.symbol, 0, 0, options.width, options.height)
  97. .add(chart.controlPointsGroup)
  98. .css(options.style);
  99. this.setVisibility(options.visible);
  100. // npm test -- --tests "highcharts/annotations-advanced/*"
  101. this.addEvents();
  102. };
  103. /**
  104. * Redraw the control point.
  105. * @private
  106. * @param {boolean} [animation]
  107. */
  108. ControlPoint.prototype.redraw = function (animation) {
  109. this.graphic[animation ? 'animate' : 'attr'](this.options.positioner.call(this, this.target));
  110. };
  111. /**
  112. * Destroy the control point.
  113. * @private
  114. */
  115. ControlPoint.prototype.destroy = function () {
  116. eventEmitterMixin.destroy.call(this);
  117. if (this.graphic) {
  118. this.graphic = this.graphic.destroy();
  119. }
  120. this.chart = null;
  121. this.target = null;
  122. this.options = null;
  123. };
  124. /**
  125. * Update the control point.
  126. *
  127. * @function Highcharts.AnnotationControlPoint#update
  128. *
  129. * @param {Partial<Highcharts.AnnotationControlPointOptionsObject>} userOptions
  130. * New options for the control point.
  131. *
  132. * @return {void}
  133. */
  134. ControlPoint.prototype.update = function (userOptions) {
  135. var chart = this.chart, target = this.target, index = this.index, options = merge(true, this.options, userOptions);
  136. this.destroy();
  137. this.constructor(chart, target, options, index);
  138. this.render(chart.controlPointsGroup);
  139. this.redraw();
  140. };
  141. return ControlPoint;
  142. }());
  143. export default ControlPoint;