ControllableImage.js 3.5 KB

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