ParetoSeries.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 DerivedSeriesMixin from '../../Mixins/DerivedSeries.js';
  25. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  26. var LineSeries = SeriesRegistry.seriesTypes.line;
  27. import U from '../../Core/Utilities.js';
  28. var correctFloat = U.correctFloat, merge = U.merge, extend = U.extend;
  29. /* *
  30. *
  31. * Class
  32. *
  33. * */
  34. /**
  35. * The pareto series type.
  36. *
  37. * @private
  38. * @class
  39. * @name Highcharts.seriesTypes.pareto
  40. *
  41. * @augments Highcharts.Series
  42. */
  43. var ParetoSeries = /** @class */ (function (_super) {
  44. __extends(ParetoSeries, _super);
  45. function ParetoSeries() {
  46. /* *
  47. *
  48. * Static properties
  49. *
  50. * */
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. /* *
  53. *
  54. * Properties
  55. *
  56. * */
  57. _this.data = void 0;
  58. _this.points = void 0;
  59. _this.options = void 0;
  60. return _this;
  61. }
  62. /* *
  63. *
  64. * Functions
  65. *
  66. * */
  67. /**
  68. * Calculate y sum and each percent point.
  69. *
  70. * @private
  71. * @function Highcharts.Series#sumPointsPercents
  72. *
  73. * @param {Array<number>} yValues
  74. * Y values
  75. *
  76. * @param {Array<number>} xValues
  77. * X values
  78. *
  79. * @param {number} sum
  80. * Sum of all y values
  81. *
  82. * @param {boolean} [isSum]
  83. * Declares if calculate sum of all points
  84. *
  85. * @return {number|Array<number,number>}
  86. * Returns sum of points or array of points [x,sum]
  87. *
  88. * @requires modules/pareto
  89. */
  90. ParetoSeries.prototype.sumPointsPercents = function (yValues, xValues, sum, isSum) {
  91. var sumY = 0, sumPercent = 0, percentPoints = [], percentPoint;
  92. yValues.forEach(function (point, i) {
  93. if (point !== null) {
  94. if (isSum) {
  95. sumY += point;
  96. }
  97. else {
  98. percentPoint = (point / sum) * 100;
  99. percentPoints.push([
  100. xValues[i],
  101. correctFloat(sumPercent + percentPoint)
  102. ]);
  103. sumPercent += percentPoint;
  104. }
  105. }
  106. });
  107. return (isSum ? sumY : percentPoints);
  108. };
  109. /**
  110. * Calculate sum and return percent points.
  111. *
  112. * @private
  113. * @function Highcharts.Series#setDerivedData
  114. * @requires modules/pareto
  115. */
  116. ParetoSeries.prototype.setDerivedData = function () {
  117. var xValues = this.baseSeries.xData, yValues = this.baseSeries.yData, sum = this.sumPointsPercents(yValues, xValues, null, true);
  118. this.setData(this.sumPointsPercents(yValues, xValues, sum, false), false);
  119. };
  120. /**
  121. * A pareto diagram is a type of chart that contains both bars and a line
  122. * graph, where individual values are represented in descending order by
  123. * bars, and the cumulative total is represented by the line.
  124. *
  125. * @sample {highcharts} highcharts/demo/pareto/
  126. * Pareto diagram
  127. *
  128. * @extends plotOptions.line
  129. * @since 6.0.0
  130. * @product highcharts
  131. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  132. * borderWidth, crisp, colorAxis, depth, data, dragDrop,
  133. * edgeColor, edgeWidth, findNearestPointBy, gapSize, gapUnit,
  134. * grouping, groupPadding, groupZPadding, maxPointWidth, keys,
  135. * negativeColor, pointInterval, pointIntervalUnit,
  136. * pointPadding, pointPlacement, pointRange, pointStart,
  137. * pointWidth, shadow, step, softThreshold, stacking,
  138. * threshold, zoneAxis, zones, boostBlending
  139. * @requires modules/pareto
  140. * @optionparent plotOptions.pareto
  141. */
  142. ParetoSeries.defaultOptions = merge(LineSeries.defaultOptions, {
  143. /**
  144. * Higher zIndex than column series to draw line above shapes.
  145. */
  146. zIndex: 3
  147. });
  148. return ParetoSeries;
  149. }(LineSeries));
  150. extend(ParetoSeries.prototype, {
  151. addBaseSeriesEvents: DerivedSeriesMixin.addBaseSeriesEvents,
  152. addEvents: DerivedSeriesMixin.addEvents,
  153. destroy: DerivedSeriesMixin.destroy,
  154. hasDerivedData: DerivedSeriesMixin.hasDerivedData,
  155. init: DerivedSeriesMixin.init,
  156. setBaseSeries: DerivedSeriesMixin.setBaseSeries
  157. });
  158. SeriesRegistry.registerSeriesType('pareto', ParetoSeries);
  159. /* *
  160. *
  161. * Default export
  162. *
  163. * */
  164. export default ParetoSeries;
  165. /* *
  166. *
  167. * API options
  168. *
  169. * */
  170. /**
  171. * A `pareto` series. If the [type](#series.pareto.type) option is not
  172. * specified, it is inherited from [chart.type](#chart.type).
  173. *
  174. * @extends series,plotOptions.pareto
  175. * @since 6.0.0
  176. * @product highcharts
  177. * @excluding data, dataParser, dataURL, boostThreshold, boostBlending
  178. * @requires modules/pareto
  179. * @apioption series.pareto
  180. */
  181. /**
  182. * An integer identifying the index to use for the base series, or a string
  183. * representing the id of the series.
  184. *
  185. * @type {number|string}
  186. * @default undefined
  187. * @apioption series.pareto.baseSeries
  188. */
  189. /**
  190. * An array of data points for the series. For the `pareto` series type,
  191. * points are calculated dynamically.
  192. *
  193. * @type {Array<Array<number|string>|*>}
  194. * @extends series.column.data
  195. * @since 6.0.0
  196. * @product highcharts
  197. * @apioption series.pareto.data
  198. */
  199. ''; // adds the doclets above to the transpiled file