HeatmapPoint.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. var __extends = (this && this.__extends) || (function () {
  12. var extendStatics = function (d, b) {
  13. extendStatics = Object.setPrototypeOf ||
  14. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  15. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  16. return extendStatics(d, b);
  17. };
  18. return function (d, b) {
  19. extendStatics(d, b);
  20. function __() { this.constructor = d; }
  21. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  22. };
  23. })();
  24. import ColorMapMixin from '../../Mixins/ColorMapSeries.js';
  25. var colorMapPointMixin = ColorMapMixin.colorMapPointMixin;
  26. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  27. var ScatterPoint = SeriesRegistry.seriesTypes.scatter.prototype.pointClass;
  28. import U from '../../Core/Utilities.js';
  29. var clamp = U.clamp, extend = U.extend, pick = U.pick;
  30. /* *
  31. *
  32. * Class
  33. *
  34. * */
  35. var HeatmapPoint = /** @class */ (function (_super) {
  36. __extends(HeatmapPoint, _super);
  37. function HeatmapPoint() {
  38. /* *
  39. *
  40. * Properties
  41. *
  42. * */
  43. var _this = _super !== null && _super.apply(this, arguments) || this;
  44. _this.options = void 0;
  45. _this.series = void 0;
  46. _this.value = void 0;
  47. _this.x = void 0;
  48. _this.y = void 0;
  49. return _this;
  50. /* eslint-enable valid-jsdoc */
  51. }
  52. /* *
  53. *
  54. * Functions
  55. *
  56. * */
  57. /* eslint-disable valid-jsdoc */
  58. /**
  59. * @private
  60. */
  61. HeatmapPoint.prototype.applyOptions = function (options, x) {
  62. var point = _super.prototype.applyOptions.call(this, options, x);
  63. point.formatPrefix = point.isNull || point.value === null ? 'null' : 'point';
  64. return point;
  65. };
  66. HeatmapPoint.prototype.getCellAttributes = function () {
  67. var point = this, series = point.series, seriesOptions = series.options, xPad = (seriesOptions.colsize || 1) / 2, yPad = (seriesOptions.rowsize || 1) / 2, xAxis = series.xAxis, yAxis = series.yAxis, markerOptions = point.options.marker || series.options.marker, pointPlacement = series.pointPlacementToXValue(), // #7860
  68. pointPadding = pick(point.pointPadding, seriesOptions.pointPadding, 0), cellAttr = {
  69. x1: clamp(Math.round(xAxis.len -
  70. (xAxis.translate(point.x - xPad, false, true, false, true, -pointPlacement) || 0)), -xAxis.len, 2 * xAxis.len),
  71. x2: clamp(Math.round(xAxis.len -
  72. (xAxis.translate(point.x + xPad, false, true, false, true, -pointPlacement) || 0)), -xAxis.len, 2 * xAxis.len),
  73. y1: clamp(Math.round((yAxis.translate(point.y - yPad, false, true, false, true) || 0)), -yAxis.len, 2 * yAxis.len),
  74. y2: clamp(Math.round((yAxis.translate(point.y + yPad, false, true, false, true) || 0)), -yAxis.len, 2 * yAxis.len)
  75. };
  76. // Handle marker's fixed width, and height values including border
  77. // and pointPadding while calculating cell attributes.
  78. [['width', 'x'], ['height', 'y']].forEach(function (dimension) {
  79. var prop = dimension[0], direction = dimension[1];
  80. var start = direction + '1', end = direction + '2';
  81. var side = Math.abs(cellAttr[start] - cellAttr[end]), borderWidth = markerOptions &&
  82. markerOptions.lineWidth || 0, plotPos = Math.abs(cellAttr[start] + cellAttr[end]) / 2;
  83. if (markerOptions[prop] &&
  84. markerOptions[prop] < side) {
  85. cellAttr[start] = plotPos - (markerOptions[prop] / 2) -
  86. (borderWidth / 2);
  87. cellAttr[end] = plotPos + (markerOptions[prop] / 2) +
  88. (borderWidth / 2);
  89. }
  90. // Handle pointPadding
  91. if (pointPadding) {
  92. if (direction === 'y') {
  93. start = end;
  94. end = direction + '1';
  95. }
  96. cellAttr[start] += pointPadding;
  97. cellAttr[end] -= pointPadding;
  98. }
  99. });
  100. return cellAttr;
  101. };
  102. /**
  103. * @private
  104. */
  105. HeatmapPoint.prototype.haloPath = function (size) {
  106. if (!size) {
  107. return [];
  108. }
  109. var rect = this.shapeArgs;
  110. return [
  111. 'M',
  112. rect.x - size,
  113. rect.y - size,
  114. 'L',
  115. rect.x - size,
  116. rect.y + rect.height + size,
  117. rect.x + rect.width + size,
  118. rect.y + rect.height + size,
  119. rect.x + rect.width + size,
  120. rect.y - size,
  121. 'Z'
  122. ];
  123. };
  124. /**
  125. * Color points have a value option that determines whether or not it is
  126. * a null point
  127. * @private
  128. */
  129. HeatmapPoint.prototype.isValid = function () {
  130. // undefined is allowed
  131. return (this.value !== Infinity &&
  132. this.value !== -Infinity);
  133. };
  134. return HeatmapPoint;
  135. }(ScatterPoint));
  136. extend(HeatmapPoint.prototype, {
  137. dataLabelOnNull: colorMapPointMixin.dataLabelOnNull,
  138. setState: colorMapPointMixin.setState
  139. });
  140. /* *
  141. *
  142. * Default Export
  143. *
  144. * */
  145. export default HeatmapPoint;