XRangePoint.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* *
  2. *
  3. * X-range series module
  4. *
  5. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. var __extends = (this && this.__extends) || (function () {
  13. var extendStatics = function (d, b) {
  14. extendStatics = Object.setPrototypeOf ||
  15. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  16. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  17. return extendStatics(d, b);
  18. };
  19. return function (d, b) {
  20. extendStatics(d, b);
  21. function __() { this.constructor = d; }
  22. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  23. };
  24. })();
  25. import Point from '../../Core/Series/Point.js';
  26. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  27. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  28. import U from '../../Core/Utilities.js';
  29. var extend = U.extend;
  30. /* *
  31. *
  32. * Class
  33. *
  34. * */
  35. var XRangePoint = /** @class */ (function (_super) {
  36. __extends(XRangePoint, _super);
  37. function XRangePoint() {
  38. var _this = _super !== null && _super.apply(this, arguments) || this;
  39. /* *
  40. *
  41. * Properties
  42. *
  43. * */
  44. _this.options = void 0;
  45. _this.series = void 0;
  46. return _this;
  47. /* eslint-enable valid-jsdoc */
  48. }
  49. /* *
  50. *
  51. * Static properties
  52. *
  53. * */
  54. /**
  55. * Return color of a point based on its category.
  56. *
  57. * @private
  58. * @function getColorByCategory
  59. *
  60. * @param {object} series
  61. * The series which the point belongs to.
  62. *
  63. * @param {object} point
  64. * The point to calculate its color for.
  65. *
  66. * @return {object}
  67. * Returns an object containing the properties color and colorIndex.
  68. */
  69. XRangePoint.getColorByCategory = function (series, point) {
  70. var colors = series.options.colors || series.chart.options.colors, colorCount = colors ?
  71. colors.length :
  72. series.chart.options.chart.colorCount, colorIndex = point.y % colorCount, color = colors && colors[colorIndex];
  73. return {
  74. colorIndex: colorIndex,
  75. color: color
  76. };
  77. };
  78. /* *
  79. *
  80. * Functions
  81. *
  82. * */
  83. /**
  84. * The ending X value of the range point.
  85. * @name Highcharts.Point#x2
  86. * @type {number|undefined}
  87. * @requires modules/xrange
  88. */
  89. /**
  90. * Extend applyOptions so that `colorByPoint` for x-range means that one
  91. * color is applied per Y axis category.
  92. *
  93. * @private
  94. * @function Highcharts.Point#applyOptions
  95. *
  96. * @return {Highcharts.Series}
  97. */
  98. /* eslint-disable valid-jsdoc */
  99. /**
  100. * @private
  101. */
  102. XRangePoint.prototype.resolveColor = function () {
  103. var series = this.series, colorByPoint;
  104. if (series.options.colorByPoint && !this.options.color) {
  105. colorByPoint = XRangePoint.getColorByCategory(series, this);
  106. if (!series.chart.styledMode) {
  107. this.color = colorByPoint.color;
  108. }
  109. if (!this.options.colorIndex) {
  110. this.colorIndex = colorByPoint.colorIndex;
  111. }
  112. }
  113. else if (!this.color) {
  114. this.color = series.color;
  115. }
  116. };
  117. /**
  118. * Extend init to have y default to 0.
  119. *
  120. * @private
  121. * @function Highcharts.Point#init
  122. *
  123. * @return {Highcharts.Point}
  124. */
  125. XRangePoint.prototype.init = function () {
  126. Point.prototype.init.apply(this, arguments);
  127. if (!this.y) {
  128. this.y = 0;
  129. }
  130. return this;
  131. };
  132. /**
  133. * @private
  134. * @function Highcharts.Point#setState
  135. */
  136. XRangePoint.prototype.setState = function () {
  137. Point.prototype.setState.apply(this, arguments);
  138. this.series.drawPoint(this, this.series.getAnimationVerb());
  139. };
  140. /**
  141. * @private
  142. * @function Highcharts.Point#getLabelConfig
  143. *
  144. * @return {Highcharts.PointLabelObject}
  145. */
  146. // Add x2 and yCategory to the available properties for tooltip formats
  147. XRangePoint.prototype.getLabelConfig = function () {
  148. var point = this, cfg = Point.prototype.getLabelConfig.call(point), yCats = point.series.yAxis.categories;
  149. cfg.x2 = point.x2;
  150. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  151. return cfg;
  152. };
  153. /**
  154. * @private
  155. * @function Highcharts.Point#isValid
  156. *
  157. * @return {boolean}
  158. */
  159. XRangePoint.prototype.isValid = function () {
  160. return typeof this.x === 'number' &&
  161. typeof this.x2 === 'number';
  162. };
  163. return XRangePoint;
  164. }(ColumnSeries.prototype.pointClass));
  165. extend(XRangePoint.prototype, {
  166. tooltipDateKeys: ['x', 'x2']
  167. });
  168. /* *
  169. *
  170. * Default Export
  171. *
  172. * */
  173. export default XRangePoint;