ControllableRect.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* *
  2. *
  3. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4. *
  5. * */
  6. import ControllableMixin from '../Mixins/ControllableMixin.js';
  7. import ControllablePath from './ControllablePath.js';
  8. import U from '../../../Core/Utilities.js';
  9. var merge = U.merge;
  10. /**
  11. * @typedef {Annotation.ControllablePath.AttrsMap}
  12. * Annotation.ControllableRect.AttrsMap
  13. * @property {string} width=width
  14. * @property {string} height=height
  15. */
  16. /* eslint-disable no-invalid-this, valid-jsdoc */
  17. /**
  18. * A controllable rect class.
  19. *
  20. * @requires modules/annotations
  21. *
  22. * @private
  23. * @class
  24. * @name Highcharts.AnnotationControllableRect
  25. *
  26. * @param {Highcharts.Annotation} annotation
  27. * An annotation instance.
  28. *
  29. * @param {Highcharts.AnnotationsShapeOptions} options
  30. * A rect's options.
  31. *
  32. * @param {number} index
  33. * Index of the rectangle
  34. */
  35. var ControllableRect = /** @class */ (function () {
  36. /* *
  37. *
  38. * Constructors
  39. *
  40. * */
  41. function ControllableRect(annotation, options, index) {
  42. /* *
  43. *
  44. * Properties
  45. *
  46. * */
  47. this.addControlPoints = ControllableMixin.addControlPoints;
  48. this.anchor = ControllableMixin.anchor;
  49. this.attr = ControllableMixin.attr;
  50. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  51. this.destroy = ControllableMixin.destroy;
  52. this.getPointsOptions = ControllableMixin.getPointsOptions;
  53. this.init = ControllableMixin.init;
  54. this.linkPoints = ControllableMixin.linkPoints;
  55. this.point = ControllableMixin.point;
  56. this.rotate = ControllableMixin.rotate;
  57. this.scale = ControllableMixin.scale;
  58. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  59. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  60. this.transform = ControllableMixin.transform;
  61. this.transformPoint = ControllableMixin.transformPoint;
  62. this.translatePoint = ControllableMixin.translatePoint;
  63. this.translateShape = ControllableMixin.translateShape;
  64. this.update = ControllableMixin.update;
  65. /**
  66. * @type 'rect'
  67. */
  68. this.type = 'rect';
  69. this.translate = ControllableMixin.translateShape;
  70. this.init(annotation, options, index);
  71. this.collection = 'shapes';
  72. }
  73. /* *
  74. *
  75. * Functions
  76. *
  77. * */
  78. ControllableRect.prototype.render = function (parent) {
  79. var attrs = this.attrsFromOptions(this.options);
  80. this.graphic = this.annotation.chart.renderer
  81. .rect(0, -9e9, 0, 0)
  82. .attr(attrs)
  83. .add(parent);
  84. ControllableMixin.render.call(this);
  85. };
  86. ControllableRect.prototype.redraw = function (animation) {
  87. var position = this.anchor(this.points[0]).absolutePosition;
  88. if (position) {
  89. this.graphic[animation ? 'animate' : 'attr']({
  90. x: position.x,
  91. y: position.y,
  92. width: this.options.width,
  93. height: this.options.height
  94. });
  95. }
  96. else {
  97. this.attr({
  98. x: 0,
  99. y: -9e9
  100. });
  101. }
  102. this.graphic.placed = Boolean(position);
  103. ControllableMixin.redraw.call(this, animation);
  104. };
  105. /* *
  106. *
  107. * Static Properties
  108. *
  109. * */
  110. /**
  111. * A map object which allows to map options attributes to element attributes
  112. *
  113. * @type {Annotation.ControllableRect.AttrsMap}
  114. */
  115. ControllableRect.attrsMap = merge(ControllablePath.attrsMap, {
  116. width: 'width',
  117. height: 'height'
  118. });
  119. return ControllableRect;
  120. }());
  121. export default ControllableRect;