ControllableCircle.js 2.1 KB

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