item-series.src.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * @license Highcharts JS v7.0.2 (2019-01-17)
  3. *
  4. * Item series type for Highcharts
  5. *
  6. * (c) 2010-2019 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define(function () {
  17. return factory;
  18. });
  19. } else {
  20. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  21. }
  22. }(function (Highcharts) {
  23. (function (H) {
  24. /* *
  25. *
  26. * (c) 2009-2019 Torstein Honsi
  27. *
  28. * Item series type for Highcharts
  29. *
  30. * License: www.highcharts.com/license
  31. *
  32. * */
  33. /**
  34. * @private
  35. * @todo
  36. * - Check update, remove etc.
  37. * - Custom icons like persons, carts etc. Either as images, font icons or
  38. * Highcharts symbols.
  39. */
  40. var extend = H.extend,
  41. pick = H.pick,
  42. seriesType = H.seriesType;
  43. /**
  44. * @private
  45. * @class
  46. * @name Highcharts.seriesTypes.item
  47. *
  48. * @augments Highcharts.Series
  49. */
  50. seriesType('item', 'column', {
  51. itemPadding: 0.2,
  52. marker: {
  53. symbol: 'circle',
  54. states: {
  55. hover: {},
  56. select: {}
  57. }
  58. }
  59. }, {
  60. drawPoints: function () {
  61. var series = this,
  62. renderer = series.chart.renderer,
  63. seriesMarkerOptions = this.options.marker,
  64. itemPaddingTranslated = this.yAxis.transA *
  65. series.options.itemPadding,
  66. borderWidth = this.borderWidth,
  67. crisp = borderWidth % 2 ? 0.5 : 1;
  68. this.points.forEach(function (point) {
  69. var yPos,
  70. attr,
  71. graphics,
  72. itemY,
  73. pointAttr,
  74. pointMarkerOptions = point.marker || {},
  75. symbol = (
  76. pointMarkerOptions.symbol ||
  77. seriesMarkerOptions.symbol
  78. ),
  79. radius = pick(
  80. pointMarkerOptions.radius,
  81. seriesMarkerOptions.radius
  82. ),
  83. size,
  84. yTop,
  85. isSquare = symbol !== 'rect',
  86. x,
  87. y;
  88. point.graphics = graphics = point.graphics || {};
  89. pointAttr = point.pointAttr ?
  90. (
  91. point.pointAttr[point.selected ? 'selected' : ''] ||
  92. series.pointAttr['']
  93. ) :
  94. series.pointAttribs(point, point.selected && 'select');
  95. delete pointAttr.r;
  96. if (series.chart.styledMode) {
  97. delete pointAttr.stroke;
  98. delete pointAttr['stroke-width'];
  99. }
  100. if (point.y !== null) {
  101. if (!point.graphic) {
  102. point.graphic = renderer.g('point').add(series.group);
  103. }
  104. itemY = point.y;
  105. yTop = pick(point.stackY, point.y);
  106. size = Math.min(
  107. point.pointWidth,
  108. series.yAxis.transA - itemPaddingTranslated
  109. );
  110. for (yPos = yTop; yPos > yTop - point.y; yPos--) {
  111. x = point.barX + (
  112. isSquare ?
  113. point.pointWidth / 2 - size / 2 :
  114. 0
  115. );
  116. y = series.yAxis.toPixels(yPos, true) +
  117. itemPaddingTranslated / 2;
  118. if (series.options.crisp) {
  119. x = Math.round(x) - crisp;
  120. y = Math.round(y) + crisp;
  121. }
  122. attr = {
  123. x: x,
  124. y: y,
  125. width: Math.round(isSquare ? size : point.pointWidth),
  126. height: Math.round(size),
  127. r: radius
  128. };
  129. if (graphics[itemY]) {
  130. graphics[itemY].animate(attr);
  131. } else {
  132. graphics[itemY] = renderer.symbol(symbol)
  133. .attr(extend(attr, pointAttr))
  134. .add(point.graphic);
  135. }
  136. graphics[itemY].isActive = true;
  137. itemY--;
  138. }
  139. }
  140. H.objectEach(graphics, function (graphic, key) {
  141. if (!graphic.isActive) {
  142. graphic.destroy();
  143. delete graphic[key];
  144. } else {
  145. graphic.isActive = false;
  146. }
  147. });
  148. });
  149. }
  150. });
  151. H.SVGRenderer.prototype.symbols.rect = function (x, y, w, h, options) {
  152. return H.SVGRenderer.prototype.symbols.callout(x, y, w, h, options);
  153. };
  154. }(Highcharts));
  155. return (function () {
  156. }());
  157. }));