ColumnRangeSeries.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. point.tooltipPos = chart.inverted ?
  157. [
  158. yAxis.len + yAxis.pos - chart.plotLeft - y -
  159. height / 2,
  160. xAxis.len + xAxis.pos - chart.plotTop -
  161. shapeArgs.x - shapeArgs.width / 2,
  162. height
  163. ] : [
  164. xAxis.left - chart.plotLeft + shapeArgs.x +
  165. shapeArgs.width / 2,
  166. yAxis.pos - chart.plotTop + y + height / 2,
  167. height
  168. ]; // don't inherit from column tooltip position - #3372
  169. }
  170. });
  171. };
  172. // Overrides from modules that may be loaded after this module
  173. ColumnRangeSeries.prototype.crispCol = function () {
  174. return columnProto.crispCol.apply(this, arguments);
  175. };
  176. ColumnRangeSeries.prototype.drawPoints = function () {
  177. return columnProto.drawPoints.apply(this, arguments);
  178. };
  179. ColumnRangeSeries.prototype.drawTracker = function () {
  180. return columnProto.drawTracker.apply(this, arguments);
  181. };
  182. ColumnRangeSeries.prototype.getColumnMetrics = function () {
  183. return columnProto.getColumnMetrics.apply(this, arguments);
  184. };
  185. ColumnRangeSeries.prototype.pointAttribs = function () {
  186. return columnProto.pointAttribs.apply(this, arguments);
  187. };
  188. ColumnRangeSeries.prototype.adjustForMissingColumns = function () {
  189. return columnProto.adjustForMissingColumns.apply(this, arguments);
  190. };
  191. ColumnRangeSeries.prototype.animate = function () {
  192. return columnProto.animate.apply(this, arguments);
  193. };
  194. ColumnRangeSeries.prototype.translate3dPoints = function () {
  195. return columnProto.translate3dPoints.apply(this, arguments);
  196. };
  197. ColumnRangeSeries.prototype.translate3dShapes = function () {
  198. return columnProto.translate3dShapes.apply(this, arguments);
  199. };
  200. ColumnRangeSeries.defaultOptions = merge(ColumnSeries.defaultOptions, AreaRangeSeries.defaultOptions, columnRangeOptions);
  201. return ColumnRangeSeries;
  202. }(AreaRangeSeries));
  203. extend(ColumnRangeSeries.prototype, {
  204. directTouch: true,
  205. trackerGroups: ['group', 'dataLabelsGroup'],
  206. drawGraph: noop,
  207. getSymbol: noop,
  208. polarArc: function () {
  209. return columnProto.polarArc.apply(this, arguments);
  210. },
  211. pointClass: ColumnRangePoint
  212. });
  213. SeriesRegistry.registerSeriesType('columnrange', ColumnRangeSeries);
  214. /* *
  215. *
  216. * Default export
  217. *
  218. * */
  219. export default ColumnRangeSeries;
  220. /* *
  221. *
  222. * API options
  223. *
  224. * */
  225. /**
  226. * A `columnrange` series. If the [type](#series.columnrange.type)
  227. * option is not specified, it is inherited from
  228. * [chart.type](#chart.type).
  229. *
  230. * @extends series,plotOptions.columnrange
  231. * @excluding dataParser, dataURL, stack, stacking
  232. * @product highcharts highstock
  233. * @requires highcharts-more
  234. * @apioption series.columnrange
  235. */
  236. /**
  237. * An array of data points for the series. For the `columnrange` series
  238. * type, points can be given in the following ways:
  239. *
  240. * 1. An array of arrays with 3 or 2 values. In this case, the values correspond
  241. * to `x,low,high`. If the first value is a string, it is applied as the name
  242. * of the point, and the `x` value is inferred. The `x` value can also be
  243. * omitted, in which case the inner arrays should be of length 2\. Then the
  244. * `x` value is automatically calculated, either starting at 0 and
  245. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  246. * series options.
  247. * ```js
  248. * data: [
  249. * [0, 4, 2],
  250. * [1, 2, 1],
  251. * [2, 9, 10]
  252. * ]
  253. * ```
  254. *
  255. * 2. An array of objects with named values. The following snippet shows only a
  256. * few settings, see the complete options set below. If the total number of
  257. * data points exceeds the series'
  258. * [turboThreshold](#series.columnrange.turboThreshold), this option is not
  259. * available.
  260. * ```js
  261. * data: [{
  262. * x: 1,
  263. * low: 0,
  264. * high: 4,
  265. * name: "Point2",
  266. * color: "#00FF00"
  267. * }, {
  268. * x: 1,
  269. * low: 5,
  270. * high: 3,
  271. * name: "Point1",
  272. * color: "#FF00FF"
  273. * }]
  274. * ```
  275. *
  276. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  277. * Arrays of numeric x and y
  278. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  279. * Arrays of datetime x and y
  280. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  281. * Arrays of point.name and y
  282. * @sample {highcharts} highcharts/series/data-array-of-objects/
  283. * Config objects
  284. *
  285. * @type {Array<Array<(number|string),number>|Array<(number|string),number,number>|*>}
  286. * @extends series.arearange.data
  287. * @excluding marker
  288. * @product highcharts highstock
  289. * @apioption series.columnrange.data
  290. */
  291. /**
  292. * @extends series.columnrange.dataLabels
  293. * @product highcharts highstock
  294. * @apioption series.columnrange.data.dataLabels
  295. */
  296. /**
  297. * @excluding halo, lineWidth, lineWidthPlus, marker
  298. * @product highcharts highstock
  299. * @apioption series.columnrange.states.hover
  300. */
  301. /**
  302. * @excluding halo, lineWidth, lineWidthPlus, marker
  303. * @product highcharts highstock
  304. * @apioption series.columnrange.states.select
  305. */
  306. ''; // adds doclets above into transpiled