ControllableImage.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 './controllableMixin.js';
  9. import U from './../../parts/Utilities.js';
  10. var merge = U.merge;
  11. /* eslint-disable no-invalid-this, valid-jsdoc */
  12. /**
  13. * A controllable image class.
  14. *
  15. * @requires modules/annotations
  16. *
  17. * @private
  18. * @class
  19. * @name Highcharts.AnnotationControllableImage
  20. *
  21. * @param {Highcharts.Annotation} annotation
  22. * An annotation instance.
  23. *
  24. * @param {Highcharts.AnnotationsShapeOptions} options
  25. * A controllable's options.
  26. *
  27. * @param {number} index
  28. * Index of the image.
  29. **/
  30. var ControllableImage = function (annotation, options, index) {
  31. this.init(annotation, options, index);
  32. this.collection = 'shapes';
  33. };
  34. /**
  35. * A map object which allows to map options attributes to element attributes
  36. *
  37. * @name Highcharts.AnnotationControllableImage.attrsMap
  38. * @type {Highcharts.Dictionary<string>}
  39. */
  40. ControllableImage.attrsMap = {
  41. width: 'width',
  42. height: 'height',
  43. zIndex: 'zIndex'
  44. };
  45. merge(true, ControllableImage.prototype, controllableMixin, /** @lends Annotation.ControllableImage# */ {
  46. /**
  47. * @type 'image'
  48. */
  49. type: 'image',
  50. translate: controllableMixin.translateShape,
  51. render: function (parent) {
  52. var attrs = this.attrsFromOptions(this.options), options = this.options;
  53. this.graphic = this.annotation.chart.renderer
  54. .image(options.src, 0, -9e9, options.width, options.height)
  55. .attr(attrs)
  56. .add(parent);
  57. this.graphic.width = options.width;
  58. this.graphic.height = options.height;
  59. controllableMixin.render.call(this);
  60. },
  61. redraw: function (animation) {
  62. var anchor = this.anchor(this.points[0]), position = ControllableLabel.prototype.position.call(this, anchor);
  63. if (position) {
  64. this.graphic[animation ? 'animate' : 'attr']({
  65. x: position.x,
  66. y: position.y
  67. });
  68. }
  69. else {
  70. this.graphic.attr({
  71. x: 0,
  72. y: -9e9
  73. });
  74. }
  75. this.graphic.placed = Boolean(position);
  76. controllableMixin.redraw.call(this, animation);
  77. }
  78. });
  79. export default ControllableImage;