ControllableCircle.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. render: function (parent) {
  36. var attrs = this.attrsFromOptions(this.options);
  37. this.graphic = this.annotation.chart.renderer
  38. .circle(0, -9e9, 0)
  39. .attr(attrs)
  40. .add(parent);
  41. controllableMixin.render.call(this);
  42. },
  43. redraw: function (animation) {
  44. var position = this.anchor(this.points[0]).absolutePosition;
  45. if (position) {
  46. this.graphic[animation ? 'animate' : 'attr']({
  47. x: position.x,
  48. y: position.y,
  49. r: this.options.r
  50. });
  51. } else {
  52. this.graphic.attr({
  53. x: 0,
  54. y: -9e9
  55. });
  56. }
  57. this.graphic.placed = Boolean(position);
  58. controllableMixin.redraw.call(this, animation);
  59. },
  60. translate: function (dx, dy) {
  61. var annotationOptions = this.annotation.userOptions,
  62. shapeOptions = annotationOptions[this.collection][this.index];
  63. this.translatePoint(dx, dy, 0);
  64. // Options stored in chart:
  65. shapeOptions.point = this.options.point;
  66. },
  67. /**
  68. * Set the radius.
  69. *
  70. * @param {number} r a radius to be set
  71. */
  72. setRadius: function (r) {
  73. this.options.r = r;
  74. }
  75. }
  76. );
  77. export default ControllableCircle;