ColumnRangeSeries.js 8.2 KB

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