pareto.src.js 4.3 KB

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