item-series.src.js 4.3 KB

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