ControllableCircle.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* *
  2. *
  3. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4. *
  5. * */
  6. 'use strict';
  7. import controllableMixin from './controllableMixin.js';
  8. import ControllablePath from './ControllablePath.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 circle class.
  14. *
  15. * @requires modules/annotations
  16. *
  17. * @private
  18. * @constructor
  19. * @name Highcharts.AnnotationControllableCircle
  20. *
  21. * @param {Highcharts.Annotation} annotation an annotation instance
  22. * @param {Highcharts.AnnotationsShapeOptions} options a shape's options
  23. * @param {number} index of the circle
  24. **/
  25. var ControllableCircle = function (annotation, options, index) {
  26. this.init(annotation, options, index);
  27. this.collection = 'shapes';
  28. };
  29. /**
  30. * A map object which allows to map options attributes to element attributes.
  31. *
  32. * @name Highcharts.AnnotationControllableCircle.attrsMap
  33. * @type {Highcharts.Dictionary<string>}
  34. */
  35. ControllableCircle.attrsMap = merge(ControllablePath.attrsMap, {
  36. r: 'r'
  37. });
  38. merge(true, ControllableCircle.prototype, controllableMixin, /** @lends Highcharts.AnnotationControllableCircle# */ {
  39. /**
  40. * @type 'circle'
  41. */
  42. type: 'circle',
  43. translate: controllableMixin.translateShape,
  44. render: function (parent) {
  45. var attrs = this.attrsFromOptions(this.options);
  46. this.graphic = this.annotation.chart.renderer
  47. .circle(0, -9e9, 0)
  48. .attr(attrs)
  49. .add(parent);
  50. controllableMixin.render.call(this);
  51. },
  52. redraw: function (animation) {
  53. var position = this.anchor(this.points[0]).absolutePosition;
  54. if (position) {
  55. this.graphic[animation ? 'animate' : 'attr']({
  56. x: position.x,
  57. y: position.y,
  58. r: this.options.r
  59. });
  60. }
  61. else {
  62. this.graphic.attr({
  63. x: 0,
  64. y: -9e9
  65. });
  66. }
  67. this.graphic.placed = Boolean(position);
  68. controllableMixin.redraw.call(this, animation);
  69. },
  70. /**
  71. * Set the radius.
  72. *
  73. * @param {number} r a radius to be set
  74. */
  75. setRadius: function (r) {
  76. this.options.r = r;
  77. }
  78. });
  79. export default ControllableCircle;