ColumnPyramidSeries.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* *
  2. *
  3. * (c) 2010-2020 Sebastian Bochan
  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 ColumnSeries from './ColumnSeries.js';
  12. var colProto = ColumnSeries.prototype;
  13. import U from '../Core/Utilities.js';
  14. var clamp = U.clamp, pick = U.pick;
  15. /**
  16. * The ColumnPyramidSeries class
  17. *
  18. * @private
  19. * @class
  20. * @name Highcharts.seriesTypes.columnpyramid
  21. *
  22. * @augments Highcharts.Series
  23. */
  24. BaseSeries.seriesType('columnpyramid', 'column',
  25. /**
  26. * Column pyramid series display one pyramid per value along an X axis.
  27. * To display horizontal pyramids, set [chart.inverted](#chart.inverted) to
  28. * `true`.
  29. *
  30. * @sample {highcharts|highstock} highcharts/demo/column-pyramid/
  31. * Column pyramid
  32. * @sample {highcharts|highstock} highcharts/plotoptions/columnpyramid-stacked/
  33. * Column pyramid stacked
  34. * @sample {highcharts|highstock} highcharts/plotoptions/columnpyramid-inverted/
  35. * Column pyramid inverted
  36. *
  37. * @extends plotOptions.column
  38. * @since 7.0.0
  39. * @product highcharts highstock
  40. * @excluding boostThreshold, borderRadius, crisp, depth, edgeColor,
  41. * edgeWidth, groupZPadding, negativeColor, softThreshold,
  42. * threshold, zoneAxis, zones, boostBlending
  43. * @requires highcharts-more
  44. * @optionparent plotOptions.columnpyramid
  45. */
  46. {
  47. // no additions
  48. }, {
  49. /* eslint-disable-next-line valid-jsdoc */
  50. /**
  51. * Overrides the column translate method
  52. * @private
  53. */
  54. translate: function () {
  55. var series = this, chart = series.chart, options = series.options, dense = series.dense =
  56. series.closestPointRange * series.xAxis.transA < 2, borderWidth = series.borderWidth = pick(options.borderWidth, dense ? 0 : 1 // #3635
  57. ), yAxis = series.yAxis, threshold = options.threshold, translatedThreshold = series.translatedThreshold =
  58. yAxis.getThreshold(threshold), minPointLength = pick(options.minPointLength, 5), metrics = series.getColumnMetrics(), pointWidth = metrics.width,
  59. // postprocessed for border width
  60. seriesBarW = series.barW =
  61. Math.max(pointWidth, 1 + 2 * borderWidth), pointXOffset = series.pointXOffset = metrics.offset;
  62. if (chart.inverted) {
  63. translatedThreshold -= 0.5; // #3355
  64. }
  65. // When the pointPadding is 0,
  66. // we want the pyramids to be packed tightly,
  67. // so we allow individual pyramids to have individual sizes.
  68. // When pointPadding is greater,
  69. // we strive for equal-width columns (#2694).
  70. if (options.pointPadding) {
  71. seriesBarW = Math.ceil(seriesBarW);
  72. }
  73. colProto.translate.apply(series);
  74. // Record the new values
  75. series.points.forEach(function (point) {
  76. var yBottom = pick(point.yBottom, translatedThreshold), safeDistance = 999 + Math.abs(yBottom), plotY = clamp(point.plotY, -safeDistance, yAxis.len + safeDistance),
  77. // Don't draw too far outside plot area
  78. // (#1303, #2241, #4264)
  79. barX = point.plotX + pointXOffset, barW = seriesBarW / 2, barY = Math.min(plotY, yBottom), barH = Math.max(plotY, yBottom) - barY, stackTotal, stackHeight, topPointY, topXwidth, bottomXwidth, invBarPos, x1, x2, x3, x4, y1, y2;
  80. point.barX = barX;
  81. point.pointWidth = pointWidth;
  82. // Fix the tooltip on center of grouped pyramids
  83. // (#1216, #424, #3648)
  84. point.tooltipPos = chart.inverted ?
  85. [
  86. yAxis.len + yAxis.pos - chart.plotLeft - plotY,
  87. series.xAxis.len - barX - barW,
  88. barH
  89. ] :
  90. [
  91. barX + barW,
  92. plotY + yAxis.pos - chart.plotTop,
  93. barH
  94. ];
  95. stackTotal =
  96. threshold + (point.total || point.y);
  97. // overwrite stacktotal (always 100 / -100)
  98. if (options.stacking === 'percent') {
  99. stackTotal =
  100. threshold + (point.y < 0) ?
  101. -100 :
  102. 100;
  103. }
  104. // get the highest point (if stack, extract from total)
  105. topPointY = yAxis.toPixels((stackTotal), true);
  106. // calculate height of stack (in pixels)
  107. stackHeight =
  108. chart.plotHeight - topPointY -
  109. (chart.plotHeight - translatedThreshold);
  110. // topXwidth and bottomXwidth = width of lines from the center
  111. // calculated from tanges proportion.
  112. // Can not be a NaN #12514
  113. topXwidth = stackHeight ? (barW * (barY - topPointY)) / stackHeight : 0;
  114. // like topXwidth, but with height of point
  115. bottomXwidth = stackHeight ? (barW * (barY + barH - topPointY)) / stackHeight : 0;
  116. /*
  117. /\
  118. / \
  119. x1,y1,------ x2,y1
  120. / \
  121. ----------
  122. x4,y2 x3,y2
  123. */
  124. x1 = barX - topXwidth + barW;
  125. x2 = barX + topXwidth + barW;
  126. x3 = barX + bottomXwidth + barW;
  127. x4 = barX - bottomXwidth + barW;
  128. y1 = barY - minPointLength;
  129. y2 = barY + barH;
  130. if (point.y < 0) {
  131. y1 = barY;
  132. y2 = barY + barH + minPointLength;
  133. }
  134. // inverted chart
  135. if (chart.inverted) {
  136. invBarPos = chart.plotWidth - barY;
  137. stackHeight = (topPointY -
  138. (chart.plotWidth - translatedThreshold));
  139. // proportion tanges
  140. topXwidth = (barW *
  141. (topPointY - invBarPos)) / stackHeight;
  142. bottomXwidth = (barW *
  143. (topPointY - (invBarPos - barH))) / stackHeight;
  144. x1 = barX + barW + topXwidth; // top bottom
  145. x2 = x1 - 2 * topXwidth; // top top
  146. x3 = barX - bottomXwidth + barW; // bottom top
  147. x4 = barX + bottomXwidth + barW; // bottom bottom
  148. y1 = barY;
  149. y2 = barY + barH - minPointLength;
  150. if (point.y < 0) {
  151. y2 = barY + barH + minPointLength;
  152. }
  153. }
  154. // Register shape type and arguments to be used in drawPoints
  155. point.shapeType = 'path';
  156. point.shapeArgs = {
  157. // args for datalabels positioning
  158. x: x1,
  159. y: y1,
  160. width: x2 - x1,
  161. height: barH,
  162. // path of pyramid
  163. d: [
  164. ['M', x1, y1],
  165. ['L', x2, y1],
  166. ['L', x3, y2],
  167. ['L', x4, y2],
  168. ['Z']
  169. ]
  170. };
  171. });
  172. }
  173. });
  174. /**
  175. * A `columnpyramid` series. If the [type](#series.columnpyramid.type) option is
  176. * not specified, it is inherited from [chart.type](#chart.type).
  177. *
  178. * @extends series,plotOptions.columnpyramid
  179. * @excluding connectEnds, connectNulls, dashStyle, dataParser, dataURL,
  180. * gapSize, gapUnit, linecap, lineWidth, marker, step,
  181. * boostThreshold, boostBlending
  182. * @product highcharts highstock
  183. * @requires highcharts-more
  184. * @apioption series.columnpyramid
  185. */
  186. /**
  187. * @excluding halo, lineWidth, lineWidthPlus, marker
  188. * @product highcharts highstock
  189. * @apioption series.columnpyramid.states.hover
  190. */
  191. /**
  192. * @excluding halo, lineWidth, lineWidthPlus, marker
  193. * @product highcharts highstock
  194. * @apioption series.columnpyramid.states.select
  195. */
  196. /**
  197. * An array of data points for the series. For the `columnpyramid` series type,
  198. * points can be given in the following ways:
  199. *
  200. * 1. An array of numerical values. In this case, the numerical values will be
  201. * interpreted as `y` options. The `x` values will be automatically
  202. * calculated, either starting at 0 and incremented by 1, or from
  203. * `pointStart` and `pointInterval` given in the series options. If the axis
  204. * has categories, these will be used. Example:
  205. * ```js
  206. * data: [0, 5, 3, 5]
  207. * ```
  208. *
  209. * 2. An array of arrays with 2 values. In this case, the values correspond to
  210. * `x,y`. If the first value is a string, it is applied as the name of the
  211. * point, and the `x` value is inferred.
  212. * ```js
  213. * data: [
  214. * [0, 6],
  215. * [1, 2],
  216. * [2, 6]
  217. * ]
  218. * ```
  219. *
  220. * 3. An array of objects with named values. The objects are point configuration
  221. * objects as seen below. If the total number of data points exceeds the
  222. * series' [turboThreshold](#series.columnpyramid.turboThreshold), this
  223. * option is not available.
  224. * ```js
  225. * data: [{
  226. * x: 1,
  227. * y: 9,
  228. * name: "Point2",
  229. * color: "#00FF00"
  230. * }, {
  231. * x: 1,
  232. * y: 6,
  233. * name: "Point1",
  234. * color: "#FF00FF"
  235. * }]
  236. * ```
  237. *
  238. * @sample {highcharts} highcharts/chart/reflow-true/
  239. * Numerical values
  240. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  241. * Arrays of numeric x and y
  242. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  243. * Arrays of datetime x and y
  244. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  245. * Arrays of point.name and y
  246. * @sample {highcharts} highcharts/series/data-array-of-objects/
  247. * Config objects
  248. *
  249. * @type {Array<number|Array<(number|string),(number|null)>|null|*>}
  250. * @extends series.line.data
  251. * @excluding marker
  252. * @product highcharts highstock
  253. * @apioption series.columnpyramid.data
  254. */
  255. ''; // adds doclets above to transpiled file;