XRangePoint.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /* *
  29. *
  30. * Declarations
  31. *
  32. * */
  33. var XRangePoint = /** @class */ (function (_super) {
  34. __extends(XRangePoint, _super);
  35. function XRangePoint() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. /* *
  38. *
  39. * Properties
  40. *
  41. * */
  42. _this.options = void 0;
  43. _this.series = void 0;
  44. _this.tooltipDateKeys = ['x', 'x2'];
  45. return _this;
  46. /* eslint-enable valid-jsdoc */
  47. }
  48. /* *
  49. *
  50. * Static properties
  51. *
  52. * */
  53. /**
  54. * Return color of a point based on its category.
  55. *
  56. * @private
  57. * @function getColorByCategory
  58. *
  59. * @param {object} series
  60. * The series which the point belongs to.
  61. *
  62. * @param {object} point
  63. * The point to calculate its color for.
  64. *
  65. * @return {object}
  66. * Returns an object containing the properties color and colorIndex.
  67. */
  68. XRangePoint.getColorByCategory = function (series, point) {
  69. var colors = series.options.colors || series.chart.options.colors, colorCount = colors ?
  70. colors.length :
  71. series.chart.options.chart.colorCount, colorIndex = point.y % colorCount, color = colors && colors[colorIndex];
  72. return {
  73. colorIndex: colorIndex,
  74. color: color
  75. };
  76. };
  77. /* *
  78. *
  79. * Functions
  80. *
  81. * */
  82. /**
  83. * The ending X value of the range point.
  84. * @name Highcharts.Point#x2
  85. * @type {number|undefined}
  86. * @requires modules/xrange
  87. */
  88. /**
  89. * Extend applyOptions so that `colorByPoint` for x-range means that one
  90. * color is applied per Y axis category.
  91. *
  92. * @private
  93. * @function Highcharts.Point#applyOptions
  94. *
  95. * @return {Highcharts.Series}
  96. */
  97. /* eslint-disable valid-jsdoc */
  98. /**
  99. * @private
  100. */
  101. XRangePoint.prototype.resolveColor = function () {
  102. var series = this.series, colorByPoint;
  103. if (series.options.colorByPoint && !this.options.color) {
  104. colorByPoint = XRangePoint.getColorByCategory(series, this);
  105. if (!series.chart.styledMode) {
  106. this.color = colorByPoint.color;
  107. }
  108. if (!this.options.colorIndex) {
  109. this.colorIndex = colorByPoint.colorIndex;
  110. }
  111. }
  112. else if (!this.color) {
  113. this.color = series.color;
  114. }
  115. };
  116. /**
  117. * Extend init to have y default to 0.
  118. *
  119. * @private
  120. * @function Highcharts.Point#init
  121. *
  122. * @return {Highcharts.Point}
  123. */
  124. XRangePoint.prototype.init = function () {
  125. Point.prototype.init.apply(this, arguments);
  126. if (!this.y) {
  127. this.y = 0;
  128. }
  129. return this;
  130. };
  131. /**
  132. * @private
  133. * @function Highcharts.Point#setState
  134. */
  135. XRangePoint.prototype.setState = function () {
  136. Point.prototype.setState.apply(this, arguments);
  137. this.series.drawPoint(this, this.series.getAnimationVerb());
  138. };
  139. /**
  140. * @private
  141. * @function Highcharts.Point#getLabelConfig
  142. *
  143. * @return {Highcharts.PointLabelObject}
  144. */
  145. // Add x2 and yCategory to the available properties for tooltip formats
  146. XRangePoint.prototype.getLabelConfig = function () {
  147. var point = this, cfg = Point.prototype.getLabelConfig.call(point), yCats = point.series.yAxis.categories;
  148. cfg.x2 = point.x2;
  149. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  150. return cfg;
  151. };
  152. /**
  153. * @private
  154. * @function Highcharts.Point#isValid
  155. *
  156. * @return {boolean}
  157. */
  158. XRangePoint.prototype.isValid = function () {
  159. return typeof this.x === 'number' &&
  160. typeof this.x2 === 'number';
  161. };
  162. return XRangePoint;
  163. }(ColumnSeries.prototype.pointClass));
  164. /* *
  165. *
  166. * Default Export
  167. *
  168. * */
  169. export default XRangePoint;