ColumnPyramidSeries.js 11 KB

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