ParetoSeries.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* *
  2. *
  3. * (c) 2010-2017 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 DerivedSeriesMixin from '../Mixins/DerivedSeries.js';
  12. import U from '../Core/Utilities.js';
  13. var correctFloat = U.correctFloat, merge = U.merge;
  14. import '../Core/Options.js';
  15. import '../Series/LineSeries.js';
  16. /**
  17. * The pareto series type.
  18. *
  19. * @private
  20. * @class
  21. * @name Highcharts.seriesTypes.pareto
  22. *
  23. * @augments Highcharts.Series
  24. */
  25. BaseSeries.seriesType('pareto', 'line'
  26. /**
  27. * A pareto diagram is a type of chart that contains both bars and a line
  28. * graph, where individual values are represented in descending order by
  29. * bars, and the cumulative total is represented by the line.
  30. *
  31. * @sample {highcharts} highcharts/demo/pareto/
  32. * Pareto diagram
  33. *
  34. * @extends plotOptions.line
  35. * @since 6.0.0
  36. * @product highcharts
  37. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  38. * borderWidth, crisp, colorAxis, depth, data, dragDrop,
  39. * edgeColor, edgeWidth, findNearestPointBy, gapSize, gapUnit,
  40. * grouping, groupPadding, groupZPadding, maxPointWidth, keys,
  41. * negativeColor, pointInterval, pointIntervalUnit,
  42. * pointPadding, pointPlacement, pointRange, pointStart,
  43. * pointWidth, shadow, step, softThreshold, stacking,
  44. * threshold, zoneAxis, zones, boostBlending
  45. * @requires modules/pareto
  46. * @optionparent plotOptions.pareto
  47. */
  48. , {
  49. /**
  50. * Higher zIndex than column series to draw line above shapes.
  51. */
  52. zIndex: 3
  53. },
  54. /* eslint-disable no-invalid-this, valid-jsdoc */
  55. merge(DerivedSeriesMixin, {
  56. /**
  57. * Calculate sum and return percent points.
  58. *
  59. * @private
  60. * @function Highcharts.Series#setDerivedData
  61. * @requires modules/pareto
  62. */
  63. setDerivedData: function () {
  64. var xValues = this.baseSeries.xData, yValues = this.baseSeries.yData, sum = this.sumPointsPercents(yValues, xValues, null, true);
  65. this.setData(this.sumPointsPercents(yValues, xValues, sum, false), false);
  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. 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. /* eslint-enable no-invalid-this, valid-jsdoc */
  111. );
  112. /**
  113. * A `pareto` series. If the [type](#series.pareto.type) option is not
  114. * specified, it is inherited from [chart.type](#chart.type).
  115. *
  116. * @extends series,plotOptions.pareto
  117. * @since 6.0.0
  118. * @product highcharts
  119. * @excluding data, dataParser, dataURL, boostThreshold, boostBlending
  120. * @requires modules/pareto
  121. * @apioption series.pareto
  122. */
  123. /**
  124. * An integer identifying the index to use for the base series, or a string
  125. * representing the id of the series.
  126. *
  127. * @type {number|string}
  128. * @default undefined
  129. * @apioption series.pareto.baseSeries
  130. */
  131. /**
  132. * An array of data points for the series. For the `pareto` series type,
  133. * points are calculated dynamically.
  134. *
  135. * @type {Array<Array<number|string>|*>}
  136. * @extends series.column.data
  137. * @since 6.0.0
  138. * @product highcharts
  139. * @apioption series.pareto.data
  140. */
  141. ''; // adds the doclets above to the transpiled file