DotplotSeries.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* *
  2. *
  3. * (c) 2009-2020 Torstein Honsi
  4. *
  5. * Dot plot series type for Highcharts
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. /**
  13. * @private
  14. * @todo
  15. * - Check update, remove etc.
  16. * - Custom icons like persons, carts etc. Either as images, font icons or
  17. * Highcharts symbols.
  18. */
  19. 'use strict';
  20. import SVGRenderer from '../Core/Renderer/SVG/SVGRenderer.js';
  21. import U from '../Core/Utilities.js';
  22. var extend = U.extend, objectEach = U.objectEach, pick = U.pick, seriesType = U.seriesType;
  23. import '../Core/Series/Series.js';
  24. /**
  25. * @private
  26. * @class
  27. * @name Highcharts.seriesTypes.dotplot
  28. *
  29. * @augments Highcharts.Series
  30. */
  31. seriesType('dotplot', 'column', {
  32. itemPadding: 0.2,
  33. marker: {
  34. symbol: 'circle',
  35. states: {
  36. hover: {},
  37. select: {}
  38. }
  39. }
  40. }, {
  41. markerAttribs: void 0,
  42. drawPoints: function () {
  43. var series = this, renderer = series.chart.renderer, seriesMarkerOptions = this.options.marker, itemPaddingTranslated = this.yAxis.transA *
  44. series.options.itemPadding, borderWidth = this.borderWidth, crisp = borderWidth % 2 ? 0.5 : 1;
  45. this.points.forEach(function (point) {
  46. var yPos, attr, graphics, itemY, pointAttr, pointMarkerOptions = point.marker || {}, symbol = (pointMarkerOptions.symbol ||
  47. seriesMarkerOptions.symbol), radius = pick(pointMarkerOptions.radius, seriesMarkerOptions.radius), size, yTop, isSquare = symbol !== 'rect', x, y;
  48. point.graphics = graphics = point.graphics || {};
  49. pointAttr = point.pointAttr ?
  50. (point.pointAttr[point.selected ? 'selected' : ''] ||
  51. series.pointAttr['']) :
  52. series.pointAttribs(point, point.selected && 'select');
  53. delete pointAttr.r;
  54. if (series.chart.styledMode) {
  55. delete pointAttr.stroke;
  56. delete pointAttr['stroke-width'];
  57. }
  58. if (point.y !== null) {
  59. if (!point.graphic) {
  60. point.graphic = renderer.g('point').add(series.group);
  61. }
  62. itemY = point.y;
  63. yTop = pick(point.stackY, point.y);
  64. size = Math.min(point.pointWidth, series.yAxis.transA - itemPaddingTranslated);
  65. for (yPos = yTop; yPos > yTop - point.y; yPos--) {
  66. x = point.barX + (isSquare ?
  67. point.pointWidth / 2 - size / 2 :
  68. 0);
  69. y = series.yAxis.toPixels(yPos, true) +
  70. itemPaddingTranslated / 2;
  71. if (series.options.crisp) {
  72. x = Math.round(x) - crisp;
  73. y = Math.round(y) + crisp;
  74. }
  75. attr = {
  76. x: x,
  77. y: y,
  78. width: Math.round(isSquare ? size : point.pointWidth),
  79. height: Math.round(size),
  80. r: radius
  81. };
  82. if (graphics[itemY]) {
  83. graphics[itemY].animate(attr);
  84. }
  85. else {
  86. graphics[itemY] = renderer.symbol(symbol)
  87. .attr(extend(attr, pointAttr))
  88. .add(point.graphic);
  89. }
  90. graphics[itemY].isActive = true;
  91. itemY--;
  92. }
  93. }
  94. objectEach(graphics, function (graphic, key) {
  95. if (!graphic.isActive) {
  96. graphic.destroy();
  97. delete graphic[key];
  98. }
  99. else {
  100. graphic.isActive = false;
  101. }
  102. });
  103. });
  104. }
  105. });
  106. SVGRenderer.prototype.symbols.rect = function (x, y, w, h, options) {
  107. return SVGRenderer.prototype.symbols.callout(x, y, w, h, options);
  108. };