DotPlotSeries.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* *
  2. *
  3. * (c) 2009-2021 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. var __extends = (this && this.__extends) || (function () {
  21. var extendStatics = function (d, b) {
  22. extendStatics = Object.setPrototypeOf ||
  23. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  24. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  25. return extendStatics(d, b);
  26. };
  27. return function (d, b) {
  28. extendStatics(d, b);
  29. function __() { this.constructor = d; }
  30. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  31. };
  32. })();
  33. import ColumnSeries from '../Column/ColumnSeries.js';
  34. import './DotPlotSymbols.js';
  35. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  36. import U from '../../Core/Utilities.js';
  37. var extend = U.extend, merge = U.merge, objectEach = U.objectEach, pick = U.pick;
  38. import '../Column/ColumnSeries.js';
  39. /* *
  40. *
  41. * Class
  42. *
  43. * */
  44. /**
  45. * @private
  46. * @class
  47. * @name Highcharts.seriesTypes.dotplot
  48. *
  49. * @augments Highcharts.Series
  50. */
  51. var DotPlotSeries = /** @class */ (function (_super) {
  52. __extends(DotPlotSeries, _super);
  53. function DotPlotSeries() {
  54. /* *
  55. *
  56. * Static Properties
  57. *
  58. * */
  59. var _this = _super !== null && _super.apply(this, arguments) || this;
  60. /* *
  61. *
  62. * Properties
  63. *
  64. * */
  65. _this.data = void 0;
  66. _this.options = void 0;
  67. _this.points = void 0;
  68. return _this;
  69. }
  70. /* *
  71. *
  72. * Functions
  73. *
  74. * */
  75. DotPlotSeries.prototype.drawPoints = function () {
  76. var series = this, renderer = series.chart.renderer, seriesMarkerOptions = this.options.marker, itemPaddingTranslated = this.yAxis.transA *
  77. series.options.itemPadding, borderWidth = this.borderWidth, crisp = borderWidth % 2 ? 0.5 : 1;
  78. this.points.forEach(function (point) {
  79. var yPos, attr, graphics, itemY, pointAttr, pointMarkerOptions = point.marker || {}, symbol = (pointMarkerOptions.symbol ||
  80. seriesMarkerOptions.symbol), radius = pick(pointMarkerOptions.radius, seriesMarkerOptions.radius), size, yTop, isSquare = symbol !== 'rect', x, y;
  81. point.graphics = graphics = point.graphics || {};
  82. pointAttr = point.pointAttr ?
  83. (point.pointAttr[point.selected ? 'selected' : ''] ||
  84. series.pointAttr['']) :
  85. series.pointAttribs(point, point.selected && 'select');
  86. delete pointAttr.r;
  87. if (series.chart.styledMode) {
  88. delete pointAttr.stroke;
  89. delete pointAttr['stroke-width'];
  90. }
  91. if (point.y !== null) {
  92. if (!point.graphic) {
  93. point.graphic = renderer.g('point').add(series.group);
  94. }
  95. itemY = point.y;
  96. yTop = pick(point.stackY, point.y);
  97. size = Math.min(point.pointWidth, series.yAxis.transA - itemPaddingTranslated);
  98. for (yPos = yTop; yPos > yTop - point.y; yPos--) {
  99. x = point.barX + (isSquare ?
  100. point.pointWidth / 2 - size / 2 :
  101. 0);
  102. y = series.yAxis.toPixels(yPos, true) +
  103. itemPaddingTranslated / 2;
  104. if (series.options.crisp) {
  105. x = Math.round(x) - crisp;
  106. y = Math.round(y) + crisp;
  107. }
  108. attr = {
  109. x: x,
  110. y: y,
  111. width: Math.round(isSquare ? size : point.pointWidth),
  112. height: Math.round(size),
  113. r: radius
  114. };
  115. if (graphics[itemY]) {
  116. graphics[itemY].animate(attr);
  117. }
  118. else {
  119. graphics[itemY] = renderer.symbol(symbol)
  120. .attr(extend(attr, pointAttr))
  121. .add(point.graphic);
  122. }
  123. graphics[itemY].isActive = true;
  124. itemY--;
  125. }
  126. }
  127. objectEach(graphics, function (graphic, key) {
  128. if (!graphic.isActive) {
  129. graphic.destroy();
  130. delete graphic[key];
  131. }
  132. else {
  133. graphic.isActive = false;
  134. }
  135. });
  136. });
  137. };
  138. DotPlotSeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  139. itemPadding: 0.2,
  140. marker: {
  141. symbol: 'circle',
  142. states: {
  143. hover: {},
  144. select: {}
  145. }
  146. }
  147. });
  148. return DotPlotSeries;
  149. }(ColumnSeries));
  150. extend(DotPlotSeries.prototype, {
  151. markerAttribs: void 0
  152. });
  153. SeriesRegistry.registerSeriesType('dotplot', DotPlotSeries);
  154. /* *
  155. *
  156. * Default Export
  157. *
  158. * */
  159. export default DotPlotSeries;