pareto.src.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* *
  2. * (c) 2010-2017 Sebastian Bochan
  3. *
  4. * License: www.highcharts.com/license
  5. */
  6. 'use strict';
  7. import H from '../parts/Globals.js';
  8. import '../parts/Utilities.js';
  9. import '../parts/Options.js';
  10. import derivedSeriesMixin from '../mixins/derived-series.js';
  11. var correctFloat = H.correctFloat,
  12. seriesType = H.seriesType,
  13. merge = H.merge;
  14. /**
  15. * The pareto series type.
  16. *
  17. * @private
  18. * @class
  19. * @name Highcharts.seriesTypes.pareto
  20. *
  21. * @augments Highcharts.Series
  22. */
  23. seriesType('pareto', 'line'
  24. /**
  25. * A pareto diagram is a type of chart that contains both bars and a line graph,
  26. * where individual values are represented in descending order by bars, and the
  27. * cumulative total is represented by the line.
  28. *
  29. * @sample {highcharts} highcharts/demo/pareto/
  30. * Pareto diagram
  31. *
  32. * @extends plotOptions.line
  33. * @since 6.0.0
  34. * @product highcharts
  35. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  36. * borderWidth, crisp, colorAxis, depth, data, edgeColor,
  37. * edgeWidth, findNearestPointBy, gapSize, gapUnit, grouping,
  38. * groupPadding, groupZPadding, maxPointWidth, keys,
  39. * negativeColor, pointInterval, pointIntervalUnit, pointPadding,
  40. * pointPlacement, pointRange, pointStart, pointWidth, shadow,
  41. * step, softThreshold, stacking, threshold, zoneAxis, zones
  42. * @optionparent plotOptions.pareto
  43. */
  44. , {
  45. /**
  46. * Higher zIndex than column series to draw line above shapes.
  47. */
  48. zIndex: 3
  49. }, merge(derivedSeriesMixin, {
  50. /**
  51. * Calculate sum and return percent points.
  52. *
  53. * @private
  54. * @function Highcharts.Series#setDerivedData
  55. *
  56. * @return {Array<Array<number,number>>}
  57. * Returns array of points [x,y]
  58. */
  59. setDerivedData: function () {
  60. if (this.baseSeries.yData.length > 1) {
  61. var xValues = this.baseSeries.xData,
  62. yValues = this.baseSeries.yData,
  63. sum = this.sumPointsPercents(yValues, xValues, null, true);
  64. this.setData(
  65. this.sumPointsPercents(yValues, xValues, sum, false),
  66. false
  67. );
  68. }
  69. },
  70. /**
  71. * Calculate y sum and each percent point.
  72. *
  73. * @private
  74. * @function Highcharts.Series#sumPointsPercents
  75. *
  76. * @param {Array<number>} yValues
  77. * Y values
  78. *
  79. * @param {Array<number>} xValues
  80. * X values
  81. *
  82. * @param {number} sum
  83. * Sum of all y values
  84. *
  85. * @param {boolean} [isSum]
  86. * Declares if calculate sum of all points
  87. *
  88. * @return {number|Array<number,number>}
  89. * Returns sum of points or array of points [x,sum]
  90. */
  91. sumPointsPercents: function (yValues, xValues, sum, isSum) {
  92. var sumY = 0,
  93. sumPercent = 0,
  94. percentPoints = [],
  95. percentPoint;
  96. yValues.forEach(function (point, i) {
  97. if (point !== null) {
  98. if (isSum) {
  99. sumY += point;
  100. } else {
  101. percentPoint = (point / sum) * 100;
  102. percentPoints.push([
  103. xValues[i],
  104. correctFloat(sumPercent + percentPoint)
  105. ]);
  106. sumPercent += percentPoint;
  107. }
  108. }
  109. });
  110. return isSum ? sumY : percentPoints;
  111. }
  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. * @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. */