DotplotSeries.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. import Series from '../Core/Series/Series.js';
  13. import SVGRenderer from '../Core/Renderer/SVG/SVGRenderer.js';
  14. import U from '../Core/Utilities.js';
  15. var extend = U.extend, objectEach = U.objectEach, pick = U.pick;
  16. /**
  17. * @private
  18. * @class
  19. * @name Highcharts.seriesTypes.dotplot
  20. *
  21. * @augments Highcharts.Series
  22. */
  23. Series.seriesType('dotplot', 'column', {
  24. itemPadding: 0.2,
  25. marker: {
  26. symbol: 'circle',
  27. states: {
  28. hover: {},
  29. select: {}
  30. }
  31. }
  32. }, {
  33. markerAttribs: void 0,
  34. drawPoints: function () {
  35. var series = this, renderer = series.chart.renderer, seriesMarkerOptions = this.options.marker, itemPaddingTranslated = this.yAxis.transA *
  36. series.options.itemPadding, borderWidth = this.borderWidth, crisp = borderWidth % 2 ? 0.5 : 1;
  37. this.points.forEach(function (point) {
  38. var yPos, attr, graphics, itemY, pointAttr, pointMarkerOptions = point.marker || {}, symbol = (pointMarkerOptions.symbol ||
  39. seriesMarkerOptions.symbol), radius = pick(pointMarkerOptions.radius, seriesMarkerOptions.radius), size, yTop, isSquare = symbol !== 'rect', x, y;
  40. point.graphics = graphics = point.graphics || {};
  41. pointAttr = point.pointAttr ?
  42. (point.pointAttr[point.selected ? 'selected' : ''] ||
  43. series.pointAttr['']) :
  44. series.pointAttribs(point, point.selected && 'select');
  45. delete pointAttr.r;
  46. if (series.chart.styledMode) {
  47. delete pointAttr.stroke;
  48. delete pointAttr['stroke-width'];
  49. }
  50. if (point.y !== null) {
  51. if (!point.graphic) {
  52. point.graphic = renderer.g('point').add(series.group);
  53. }
  54. itemY = point.y;
  55. yTop = pick(point.stackY, point.y);
  56. size = Math.min(point.pointWidth, series.yAxis.transA - itemPaddingTranslated);
  57. for (yPos = yTop; yPos > yTop - point.y; yPos--) {
  58. x = point.barX + (isSquare ?
  59. point.pointWidth / 2 - size / 2 :
  60. 0);
  61. y = series.yAxis.toPixels(yPos, true) +
  62. itemPaddingTranslated / 2;
  63. if (series.options.crisp) {
  64. x = Math.round(x) - crisp;
  65. y = Math.round(y) + crisp;
  66. }
  67. attr = {
  68. x: x,
  69. y: y,
  70. width: Math.round(isSquare ? size : point.pointWidth),
  71. height: Math.round(size),
  72. r: radius
  73. };
  74. if (graphics[itemY]) {
  75. graphics[itemY].animate(attr);
  76. }
  77. else {
  78. graphics[itemY] = renderer.symbol(symbol)
  79. .attr(extend(attr, pointAttr))
  80. .add(point.graphic);
  81. }
  82. graphics[itemY].isActive = true;
  83. itemY--;
  84. }
  85. }
  86. objectEach(graphics, function (graphic, key) {
  87. if (!graphic.isActive) {
  88. graphic.destroy();
  89. delete graphic[key];
  90. }
  91. else {
  92. graphic.isActive = false;
  93. }
  94. });
  95. });
  96. }
  97. });
  98. SVGRenderer.prototype.symbols.rect = function (x, y, w, h, options) {
  99. return SVGRenderer.prototype.symbols.callout(x, y, w, h, options);
  100. };