ColumnRangeSeries.js 8.4 KB

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