ParetoSeries.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. 'use strict';
  11. import U from '../Core/Utilities.js';
  12. var correctFloat = U.correctFloat, merge = U.merge, seriesType = U.seriesType;
  13. import '../Core/Options.js';
  14. import derivedSeriesMixin from '../Mixins/DerivedSeries.js';
  15. /**
  16. * The pareto series type.
  17. *
  18. * @private
  19. * @class
  20. * @name Highcharts.seriesTypes.pareto
  21. *
  22. * @augments Highcharts.Series
  23. */
  24. seriesType('pareto', 'line'
  25. /**
  26. * A pareto diagram is a type of chart that contains both bars and a line
  27. * graph, where individual values are represented in descending order by
  28. * bars, and the cumulative total is represented by the line.
  29. *
  30. * @sample {highcharts} highcharts/demo/pareto/
  31. * Pareto diagram
  32. *
  33. * @extends plotOptions.line
  34. * @since 6.0.0
  35. * @product highcharts
  36. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  37. * borderWidth, crisp, colorAxis, depth, data, dragDrop,
  38. * edgeColor, edgeWidth, findNearestPointBy, gapSize, gapUnit,
  39. * grouping, groupPadding, groupZPadding, maxPointWidth, keys,
  40. * negativeColor, pointInterval, pointIntervalUnit,
  41. * pointPadding, pointPlacement, pointRange, pointStart,
  42. * pointWidth, shadow, step, softThreshold, stacking,
  43. * threshold, zoneAxis, zones, boostBlending
  44. * @requires modules/pareto
  45. * @optionparent plotOptions.pareto
  46. */
  47. , {
  48. /**
  49. * Higher zIndex than column series to draw line above shapes.
  50. */
  51. zIndex: 3
  52. },
  53. /* eslint-disable no-invalid-this, valid-jsdoc */
  54. merge(derivedSeriesMixin, {
  55. /**
  56. * Calculate sum and return percent points.
  57. *
  58. * @private
  59. * @function Highcharts.Series#setDerivedData
  60. * @requires modules/pareto
  61. */
  62. setDerivedData: function () {
  63. var xValues = this.baseSeries.xData, yValues = this.baseSeries.yData, sum = this.sumPointsPercents(yValues, xValues, null, true);
  64. this.setData(this.sumPointsPercents(yValues, xValues, sum, false), false);
  65. },
  66. /**
  67. * Calculate y sum and each percent point.
  68. *
  69. * @private
  70. * @function Highcharts.Series#sumPointsPercents
  71. *
  72. * @param {Array<number>} yValues
  73. * Y values
  74. *
  75. * @param {Array<number>} xValues
  76. * X values
  77. *
  78. * @param {number} sum
  79. * Sum of all y values
  80. *
  81. * @param {boolean} [isSum]
  82. * Declares if calculate sum of all points
  83. *
  84. * @return {number|Array<number,number>}
  85. * Returns sum of points or array of points [x,sum]
  86. *
  87. * @requires modules/pareto
  88. */
  89. sumPointsPercents: function (yValues, xValues, sum, isSum) {
  90. var sumY = 0, sumPercent = 0, percentPoints = [], percentPoint;
  91. yValues.forEach(function (point, i) {
  92. if (point !== null) {
  93. if (isSum) {
  94. sumY += point;
  95. }
  96. else {
  97. percentPoint = (point / sum) * 100;
  98. percentPoints.push([
  99. xValues[i],
  100. correctFloat(sumPercent + percentPoint)
  101. ]);
  102. sumPercent += percentPoint;
  103. }
  104. }
  105. });
  106. return (isSum ? sumY : percentPoints);
  107. }
  108. })
  109. /* eslint-enable no-invalid-this, valid-jsdoc */
  110. );
  111. /**
  112. * A `pareto` series. If the [type](#series.pareto.type) option is not
  113. * specified, it is inherited from [chart.type](#chart.type).
  114. *
  115. * @extends series,plotOptions.pareto
  116. * @since 6.0.0
  117. * @product highcharts
  118. * @excluding data, dataParser, dataURL, boostThreshold, boostBlending
  119. * @requires modules/pareto
  120. * @apioption series.pareto
  121. */
  122. /**
  123. * An integer identifying the index to use for the base series, or a string
  124. * representing the id of the series.
  125. *
  126. * @type {number|string}
  127. * @default undefined
  128. * @apioption series.pareto.baseSeries
  129. */
  130. /**
  131. * An array of data points for the series. For the `pareto` series type,
  132. * points are calculated dynamically.
  133. *
  134. * @type {Array<Array<number|string>|*>}
  135. * @extends series.column.data
  136. * @since 6.0.0
  137. * @product highcharts
  138. * @apioption series.pareto.data
  139. */
  140. ''; // adds the doclets above to the transpiled file