DrawPoint.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 _a;
  25. var component = this, graphic = component.graphic, animatableAttribs = params.animatableAttribs, onComplete = params.onComplete, css = params.css, renderer = params.renderer, animation = (_a = component.series) === null || _a === void 0 ? void 0 : _a.options.animation;
  26. if (component.shouldDraw()) {
  27. if (!graphic) {
  28. component.graphic = graphic =
  29. renderer[params.shapeType](params.shapeArgs)
  30. .add(params.group);
  31. }
  32. graphic
  33. .css(css)
  34. .attr(params.attribs)
  35. .animate(animatableAttribs, params.isNew ? false : animation, onComplete);
  36. }
  37. else if (graphic) {
  38. var destroy = function () {
  39. component.graphic = graphic = graphic.destroy();
  40. if (isFn(onComplete)) {
  41. onComplete();
  42. }
  43. };
  44. // animate only runs complete callback if something was animated.
  45. if (Object.keys(animatableAttribs).length) {
  46. graphic.animate(animatableAttribs, void 0, function () {
  47. destroy();
  48. });
  49. }
  50. else {
  51. destroy();
  52. }
  53. }
  54. };
  55. /**
  56. * An extended version of draw customized for points.
  57. * It calls additional methods that is expected when rendering a point.
  58. * @private
  59. * @param {Highcharts.Dictionary<any>} params Parameters
  60. */
  61. var drawPoint = function drawPoint(params) {
  62. var point = this, attribs = params.attribs = params.attribs || {};
  63. // Assigning class in dot notation does go well in IE8
  64. // eslint-disable-next-line dot-notation
  65. attribs['class'] = point.getClassName();
  66. // Call draw to render component
  67. draw.call(point, params);
  68. };
  69. var drawPointModule = {
  70. draw: draw,
  71. drawPoint: drawPoint,
  72. isFn: isFn
  73. };
  74. export default drawPointModule;