ControllableRect.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* *
  2. *
  3. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4. *
  5. * */
  6. import controllableMixin from './controllableMixin.js';
  7. import ControllablePath from './ControllablePath.js';
  8. import U from '../../parts/Utilities.js';
  9. var merge = U.merge;
  10. /* eslint-disable no-invalid-this, valid-jsdoc */
  11. /**
  12. * A controllable rect class.
  13. *
  14. * @requires modules/annotations
  15. *
  16. * @private
  17. * @class
  18. * @name Highcharts.AnnotationControllableRect
  19. *
  20. * @param {Highcharts.Annotation} annotation
  21. * An annotation instance.
  22. *
  23. * @param {Highcharts.AnnotationsShapeOptions} options
  24. * A rect's options.
  25. *
  26. * @param {number} index
  27. * Index of the rectangle
  28. */
  29. var ControllableRect = function (annotation, options, index) {
  30. this.init(annotation, options, index);
  31. this.collection = 'shapes';
  32. };
  33. /**
  34. * @typedef {Annotation.ControllablePath.AttrsMap}
  35. * Annotation.ControllableRect.AttrsMap
  36. * @property {string} width=width
  37. * @property {string} height=height
  38. */
  39. /**
  40. * A map object which allows to map options attributes to element attributes
  41. *
  42. * @type {Annotation.ControllableRect.AttrsMap}
  43. */
  44. ControllableRect.attrsMap = merge(ControllablePath.attrsMap, {
  45. width: 'width',
  46. height: 'height'
  47. });
  48. merge(true, ControllableRect.prototype, controllableMixin, /** @lends Annotation.ControllableRect# */ {
  49. /**
  50. * @type 'rect'
  51. */
  52. type: 'rect',
  53. translate: controllableMixin.translateShape,
  54. render: function (parent) {
  55. var attrs = this.attrsFromOptions(this.options);
  56. this.graphic = this.annotation.chart.renderer
  57. .rect(0, -9e9, 0, 0)
  58. .attr(attrs)
  59. .add(parent);
  60. controllableMixin.render.call(this);
  61. },
  62. redraw: function (animation) {
  63. var position = this.anchor(this.points[0]).absolutePosition;
  64. if (position) {
  65. this.graphic[animation ? 'animate' : 'attr']({
  66. x: position.x,
  67. y: position.y,
  68. width: this.options.width,
  69. height: this.options.height
  70. });
  71. }
  72. else {
  73. this.attr({
  74. x: 0,
  75. y: -9e9
  76. });
  77. }
  78. this.graphic.placed = Boolean(position);
  79. controllableMixin.redraw.call(this, animation);
  80. }
  81. });
  82. export default ControllableRect;