ControllableImage.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. 'use strict';
  2. import H from './../../parts/Globals.js';
  3. import './../../parts/Utilities.js';
  4. import controllableMixin from './controllableMixin.js';
  5. import ControllableLabel from './ControllableLabel.js';
  6. /**
  7. * A controllable image class.
  8. *
  9. * @class
  10. * @mixes Annotation.controllableMixin
  11. * @memberOf Annotation
  12. *
  13. * @param {Highcharts.Annotation} annotation - an annotation instance
  14. * @param {Object} options a controllable's options
  15. * @param {number} index of the image
  16. **/
  17. function ControllableImage(annotation, options, index) {
  18. this.init(annotation, options, index);
  19. this.collection = 'shapes';
  20. }
  21. /**
  22. * @typedef {Object} Annotation.ControllableImage.AttrsMap
  23. * @property {string} width=width
  24. * @property {string} height=height
  25. * @property {string} zIndex=zIndex
  26. */
  27. /**
  28. * A map object which allows to map options attributes to element attributes
  29. *
  30. * @type {Annotation.ControllableImage.AttrsMap}
  31. */
  32. ControllableImage.attrsMap = {
  33. width: 'width',
  34. height: 'height',
  35. zIndex: 'zIndex'
  36. };
  37. H.merge(
  38. true,
  39. ControllableImage.prototype,
  40. controllableMixin, /** @lends Annotation.ControllableImage# */ {
  41. /**
  42. * @type 'image'
  43. */
  44. type: 'image',
  45. translate: controllableMixin.translateShape,
  46. render: function (parent) {
  47. var attrs = this.attrsFromOptions(this.options),
  48. options = this.options;
  49. this.graphic = this.annotation.chart.renderer
  50. .image(options.src, 0, -9e9, options.width, options.height)
  51. .attr(attrs)
  52. .add(parent);
  53. this.graphic.width = options.width;
  54. this.graphic.height = options.height;
  55. controllableMixin.render.call(this);
  56. },
  57. redraw: function (animation) {
  58. var anchor = this.anchor(this.points[0]),
  59. position = ControllableLabel.prototype.position.call(
  60. this,
  61. anchor
  62. );
  63. if (position) {
  64. this.graphic[animation ? 'animate' : 'attr']({
  65. x: position.x,
  66. y: position.y
  67. });
  68. } else {
  69. this.graphic.attr({
  70. x: 0,
  71. y: -9e9
  72. });
  73. }
  74. this.graphic.placed = Boolean(position);
  75. controllableMixin.redraw.call(this, animation);
  76. }
  77. }
  78. );
  79. export default ControllableImage;