draw-point.js 2.2 KB

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