ColumnRangeSeries.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 ColumnRangePoint from './ColumnRangePoint.js';
  25. import H from '../../Core/Globals.js';
  26. var noop = H.noop;
  27. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  28. var _a = SeriesRegistry.seriesTypes, AreaRangeSeries = _a.arearange, ColumnSeries = _a.column;
  29. var columnProto = ColumnSeries.prototype;
  30. var arearangeProto = AreaRangeSeries.prototype;
  31. import U from '../../Core/Utilities.js';
  32. var clamp = U.clamp, merge = U.merge, pick = U.pick, extend = U.extend;
  33. /**
  34. * The column range is a cartesian series type with higher and lower
  35. * Y values along an X axis. To display horizontal bars, set
  36. * [chart.inverted](#chart.inverted) to `true`.
  37. *
  38. * @sample {highcharts|highstock} highcharts/demo/columnrange/
  39. * Inverted column range
  40. *
  41. * @extends plotOptions.column
  42. * @since 2.3.0
  43. * @excluding negativeColor, stacking, softThreshold, threshold
  44. * @product highcharts highstock
  45. * @requires highcharts-more
  46. * @optionparent plotOptions.columnrange
  47. */
  48. var columnRangeOptions = {
  49. /**
  50. * Extended data labels for range series types. Range series data labels
  51. * have no `x` and `y` options. Instead, they have `xLow`, `xHigh`,
  52. * `yLow` and `yHigh` options to allow the higher and lower data label
  53. * sets individually.
  54. *
  55. * @declare Highcharts.SeriesAreaRangeDataLabelsOptionsObject
  56. * @extends plotOptions.arearange.dataLabels
  57. * @since 2.3.0
  58. * @product highcharts highstock
  59. * @apioption plotOptions.columnrange.dataLabels
  60. */
  61. pointRange: null,
  62. /** @ignore-option */
  63. marker: null,
  64. states: {
  65. hover: {
  66. /** @ignore-option */
  67. halo: false
  68. }
  69. }
  70. };
  71. /* *
  72. *
  73. * Class
  74. *
  75. * */
  76. /**
  77. * The ColumnRangeSeries class
  78. *
  79. * @private
  80. * @class
  81. * @name Highcharts.seriesTypes.columnrange
  82. *
  83. * @augments Highcharts.Series
  84. */
  85. var ColumnRangeSeries = /** @class */ (function (_super) {
  86. __extends(ColumnRangeSeries, _super);
  87. function ColumnRangeSeries() {
  88. /* *
  89. *
  90. * Static properties
  91. *
  92. * */
  93. var _this = _super !== null && _super.apply(this, arguments) || this;
  94. /* *
  95. *
  96. * Properties
  97. *
  98. * */
  99. _this.data = void 0;
  100. _this.points = void 0;
  101. _this.options = void 0;
  102. return _this;
  103. }
  104. /* *
  105. *
  106. * Functions
  107. *
  108. * */
  109. ColumnRangeSeries.prototype.setOptions = function () {
  110. merge(true, arguments[0], { stacking: void 0 }); // #14359 Prevent side-effect from stacking.
  111. return arearangeProto.setOptions.apply(this, arguments);
  112. };
  113. // eslint-disable-next-line valid-jsdoc
  114. /**
  115. * Translate data points from raw values x and y to plotX and plotY
  116. * @private
  117. */
  118. ColumnRangeSeries.prototype.translate = function () {
  119. var series = this, yAxis = series.yAxis, xAxis = series.xAxis, startAngleRad = xAxis.startAngleRad, start, chart = series.chart, isRadial = series.xAxis.isRadial, safeDistance = Math.max(chart.chartWidth, chart.chartHeight) + 999, plotHigh;
  120. // eslint-disable-next-line valid-jsdoc
  121. /**
  122. * Don't draw too far outside plot area (#6835)
  123. * @private
  124. */
  125. function safeBounds(pixelPos) {
  126. return clamp(pixelPos, -safeDistance, safeDistance);
  127. }
  128. columnProto.translate.apply(series);
  129. // Set plotLow and plotHigh
  130. series.points.forEach(function (point) {
  131. var shapeArgs = point.shapeArgs || {}, minPointLength = series.options.minPointLength, heightDifference, height, y;
  132. point.plotHigh = plotHigh = safeBounds(yAxis.translate(point.high, 0, 1, 0, 1));
  133. point.plotLow = safeBounds(point.plotY);
  134. // adjust shape
  135. y = plotHigh;
  136. height = pick(point.rectPlotY, point.plotY) - plotHigh;
  137. // Adjust for minPointLength
  138. if (Math.abs(height) < minPointLength) {
  139. heightDifference = (minPointLength - height);
  140. height += heightDifference;
  141. y -= heightDifference / 2;
  142. // Adjust for negative ranges or reversed Y axis (#1457)
  143. }
  144. else if (height < 0) {
  145. height *= -1;
  146. y -= height;
  147. }
  148. if (isRadial) {
  149. start = point.barX + startAngleRad;
  150. point.shapeType = 'arc';
  151. point.shapeArgs = series.polarArc(y + height, y, start, start + point.pointWidth);
  152. }
  153. else {
  154. shapeArgs.height = height;
  155. shapeArgs.y = y;
  156. var _a = shapeArgs.x, x = _a === void 0 ? 0 : _a, _b = shapeArgs.width, width = _b === void 0 ? 0 : _b;
  157. point.tooltipPos = chart.inverted ?
  158. [
  159. yAxis.len + yAxis.pos - chart.plotLeft - y -
  160. height / 2,
  161. xAxis.len + xAxis.pos - chart.plotTop -
  162. x - width / 2,
  163. height
  164. ] : [
  165. xAxis.left - chart.plotLeft + x +
  166. width / 2,
  167. yAxis.pos - chart.plotTop + y + height / 2,
  168. height
  169. ]; // don't inherit from column tooltip position - #3372
  170. }
  171. });
  172. };
  173. // Overrides from modules that may be loaded after this module
  174. ColumnRangeSeries.prototype.crispCol = function () {
  175. return columnProto.crispCol.apply(this, arguments);
  176. };
  177. ColumnRangeSeries.prototype.drawPoints = function () {
  178. return columnProto.drawPoints.apply(this, arguments);
  179. };
  180. ColumnRangeSeries.prototype.drawTracker = function () {
  181. return columnProto.drawTracker.apply(this, arguments);
  182. };
  183. ColumnRangeSeries.prototype.getColumnMetrics = function () {
  184. return columnProto.getColumnMetrics.apply(this, arguments);
  185. };
  186. ColumnRangeSeries.prototype.pointAttribs = function () {
  187. return columnProto.pointAttribs.apply(this, arguments);
  188. };
  189. ColumnRangeSeries.prototype.adjustForMissingColumns = function () {
  190. return columnProto.adjustForMissingColumns.apply(this, arguments);
  191. };
  192. ColumnRangeSeries.prototype.animate = function () {
  193. return columnProto.animate.apply(this, arguments);
  194. };
  195. ColumnRangeSeries.prototype.translate3dPoints = function () {
  196. return columnProto.translate3dPoints.apply(this, arguments);
  197. };
  198. ColumnRangeSeries.prototype.translate3dShapes = function () {
  199. return columnProto.translate3dShapes.apply(this, arguments);
  200. };
  201. ColumnRangeSeries.defaultOptions = merge(ColumnSeries.defaultOptions, AreaRangeSeries.defaultOptions, columnRangeOptions);
  202. return ColumnRangeSeries;
  203. }(AreaRangeSeries));
  204. extend(ColumnRangeSeries.prototype, {
  205. directTouch: true,
  206. trackerGroups: ['group', 'dataLabelsGroup'],
  207. drawGraph: noop,
  208. getSymbol: noop,
  209. polarArc: function () {
  210. return columnProto.polarArc.apply(this, arguments);
  211. },
  212. pointClass: ColumnRangePoint
  213. });
  214. SeriesRegistry.registerSeriesType('columnrange', ColumnRangeSeries);
  215. /* *
  216. *
  217. * Default export
  218. *
  219. * */
  220. export default ColumnRangeSeries;
  221. /* *
  222. *
  223. * API options
  224. *
  225. * */
  226. /**
  227. * A `columnrange` series. If the [type](#series.columnrange.type)
  228. * option is not specified, it is inherited from
  229. * [chart.type](#chart.type).
  230. *
  231. * @extends series,plotOptions.columnrange
  232. * @excluding dataParser, dataURL, stack, stacking
  233. * @product highcharts highstock
  234. * @requires highcharts-more
  235. * @apioption series.columnrange
  236. */
  237. /**
  238. * An array of data points for the series. For the `columnrange` series
  239. * type, points can be given in the following ways:
  240. *
  241. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  242. * to `x,low,high`. If the first value is a string, it is applied as the name
  243. * of the point, and the `x` value is inferred. The `x` value can also be
  244. * omitted, in which case the inner arrays should be of length 2\. Then the
  245. * `x` value is automatically calculated, either starting at 0 and
  246. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  247. * series options.
  248. * ```js
  249. * data: [
  250. * [0, 4, 2],
  251. * [1, 2, 1],
  252. * [2, 9, 10]
  253. * ]
  254. * ```
  255. *
  256. * 2. An array of objects with named values. The following snippet shows only a
  257. * few settings, see the complete options set below. If the total number of
  258. * data points exceeds the series'
  259. * [turboThreshold](#series.columnrange.turboThreshold), this option is not
  260. * available.
  261. * ```js
  262. * data: [{
  263. * x: 1,
  264. * low: 0,
  265. * high: 4,
  266. * name: "Point2",
  267. * color: "#00FF00"
  268. * }, {
  269. * x: 1,
  270. * low: 5,
  271. * high: 3,
  272. * name: "Point1",
  273. * color: "#FF00FF"
  274. * }]
  275. * ```
  276. *
  277. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  278. * Arrays of numeric x and y
  279. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  280. * Arrays of datetime x and y
  281. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  282. * Arrays of point.name and y
  283. * @sample {highcharts} highcharts/series/data-array-of-objects/
  284. * Config objects
  285. *
  286. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  287. * @extends series.arearange.data
  288. * @excluding marker
  289. * @product highcharts highstock
  290. * @apioption series.columnrange.data
  291. */
  292. /**
  293. * @extends series.columnrange.dataLabels
  294. * @product highcharts highstock
  295. * @apioption series.columnrange.data.dataLabels
  296. */
  297. /**
  298. * @excluding halo, lineWidth, lineWidthPlus, marker
  299. * @product highcharts highstock
  300. * @apioption series.columnrange.states.hover
  301. */
  302. /**
  303. * @excluding halo, lineWidth, lineWidthPlus, marker
  304. * @product highcharts highstock
  305. * @apioption series.columnrange.states.select
  306. */
  307. ''; // adds doclets above into transpiled