DrawPoint.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* *
  2. *
  3. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4. *
  5. * */
  6. var isFn = function (x) {
  7. return typeof x === 'function';
  8. };
  9. /* eslint-disable no-invalid-this, valid-jsdoc */
  10. /**
  11. * Handles the drawing of a component.
  12. * Can be used for any type of component that reserves the graphic property, and
  13. * provides a shouldDraw on its context.
  14. *
  15. * @private
  16. * @function draw
  17. * @param {DrawPointParams} params
  18. * Parameters.
  19. *
  20. * @todo add type checking.
  21. * @todo export this function to enable usage
  22. */
  23. var draw = function draw(params) {
  24. var _this = this;
  25. var animatableAttribs = params.animatableAttribs, onComplete = params.onComplete, css = params.css, renderer = params.renderer;
  26. var animation = (this.series && this.series.chart.hasRendered) ?
  27. // Chart-level animation on updates
  28. void 0 :
  29. // Series-level animation on new points
  30. (this.series &&
  31. this.series.options.animation);
  32. var graphic = this.graphic;
  33. if (this.shouldDraw()) {
  34. if (!graphic) {
  35. this.graphic = graphic =
  36. renderer[params.shapeType](params.shapeArgs)
  37. .add(params.group);
  38. }
  39. graphic
  40. .css(css)
  41. .attr(params.attribs)
  42. .animate(animatableAttribs, params.isNew ? false : animation, onComplete);
  43. }
  44. else if (graphic) {
  45. var destroy_1 = function () {
  46. _this.graphic = graphic = (graphic && graphic.destroy());
  47. if (isFn(onComplete)) {
  48. onComplete();
  49. }
  50. };
  51. // animate only runs complete callback if something was animated.
  52. if (Object.keys(animatableAttribs).length) {
  53. graphic.animate(animatableAttribs, void 0, function () {
  54. destroy_1();
  55. });
  56. }
  57. else {
  58. destroy_1();
  59. }
  60. }
  61. };
  62. /**
  63. * An extended version of draw customized for points.
  64. * It calls additional methods that is expected when rendering a point.
  65. * @private
  66. * @param {Highcharts.Dictionary<any>} params Parameters
  67. */
  68. var drawPoint = function drawPoint(params) {
  69. var point = this, attribs = params.attribs = params.attribs || {};
  70. // Assigning class in dot notation does go well in IE8
  71. // eslint-disable-next-line dot-notation
  72. attribs['class'] = point.getClassName();
  73. // Call draw to render component
  74. draw.call(point, params);
  75. };
  76. var drawPointModule = {
  77. draw: draw,
  78. drawPoint: drawPoint,
  79. isFn: isFn
  80. };
  81. export default drawPointModule;