ColumnRangeSeries.js 8.4 KB

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