pareto.src.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /**
  2. * @license Highcharts JS v7.0.2 (2019-01-17)
  3. *
  4. * Pareto series type for Highcharts
  5. *
  6. * (c) 2010-2019 Sebastian Bochan
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define(function () {
  17. return factory;
  18. });
  19. } else {
  20. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  21. }
  22. }(function (Highcharts) {
  23. var derivedSeriesMixin = (function (H) {
  24. var Series = H.Series,
  25. addEvent = H.addEvent,
  26. noop = H.noop;
  27. /* ************************************************************************** *
  28. *
  29. * DERIVED SERIES MIXIN
  30. *
  31. * ************************************************************************** */
  32. /**
  33. * Provides methods for auto setting/updating series data based on the based
  34. * series data.
  35. *
  36. * @private
  37. * @mixin derivedSeriesMixin
  38. */
  39. var derivedSeriesMixin = {
  40. /**
  41. * Initialise series
  42. *
  43. * @private
  44. * @function derivedSeriesMixin.init
  45. */
  46. init: function () {
  47. Series.prototype.init.apply(this, arguments);
  48. this.initialised = false;
  49. this.baseSeries = null;
  50. this.eventRemovers = [];
  51. this.addEvents();
  52. },
  53. /**
  54. * Method to be implemented - inside the method the series has already
  55. * access to the base series via m `this.baseSeries` and the bases data is
  56. * initialised. It should return data in the format accepted by
  57. * `Series.setData()` method
  58. *
  59. * @private
  60. * @function derivedSeriesMixin.setDerivedData
  61. *
  62. * @return {Array<*>}
  63. * An array of data
  64. */
  65. setDerivedData: noop,
  66. /**
  67. * Sets base series for the series
  68. *
  69. * @private
  70. * @function derivedSeriesMixin.setBaseSeries
  71. */
  72. setBaseSeries: function () {
  73. var chart = this.chart,
  74. baseSeriesOptions = this.options.baseSeries,
  75. baseSeries =
  76. baseSeriesOptions &&
  77. (chart.series[baseSeriesOptions] || chart.get(baseSeriesOptions));
  78. this.baseSeries = baseSeries || null;
  79. },
  80. /**
  81. * Adds events for the series
  82. *
  83. * @private
  84. * @function derivedSeriesMixin.addEvents
  85. */
  86. addEvents: function () {
  87. var derivedSeries = this,
  88. chartSeriesLinked;
  89. chartSeriesLinked = addEvent(
  90. this.chart,
  91. 'afterLinkSeries',
  92. function () {
  93. derivedSeries.setBaseSeries();
  94. if (derivedSeries.baseSeries && !derivedSeries.initialised) {
  95. derivedSeries.setDerivedData();
  96. derivedSeries.addBaseSeriesEvents();
  97. derivedSeries.initialised = true;
  98. }
  99. }
  100. );
  101. this.eventRemovers.push(
  102. chartSeriesLinked
  103. );
  104. },
  105. /**
  106. * Adds events to the base series - it required for recalculating the data
  107. * in the series if the base series is updated / removed / etc.
  108. *
  109. * @private
  110. * @function derivedSeriesMixin.addBaseSeriesEvents
  111. */
  112. addBaseSeriesEvents: function () {
  113. var derivedSeries = this,
  114. updatedDataRemover,
  115. destroyRemover;
  116. updatedDataRemover = addEvent(
  117. derivedSeries.baseSeries,
  118. 'updatedData',
  119. function () {
  120. derivedSeries.setDerivedData();
  121. }
  122. );
  123. destroyRemover = addEvent(
  124. derivedSeries.baseSeries,
  125. 'destroy',
  126. function () {
  127. derivedSeries.baseSeries = null;
  128. derivedSeries.initialised = false;
  129. }
  130. );
  131. derivedSeries.eventRemovers.push(
  132. updatedDataRemover,
  133. destroyRemover
  134. );
  135. },
  136. /**
  137. * Destroys the series
  138. *
  139. * @private
  140. * @function derivedSeriesMixin.destroy
  141. */
  142. destroy: function () {
  143. this.eventRemovers.forEach(function (remover) {
  144. remover();
  145. });
  146. Series.prototype.destroy.apply(this, arguments);
  147. }
  148. };
  149. return derivedSeriesMixin;
  150. }(Highcharts));
  151. (function (H, derivedSeriesMixin) {
  152. /* *
  153. * (c) 2010-2017 Sebastian Bochan
  154. *
  155. * License: www.highcharts.com/license
  156. */
  157. var correctFloat = H.correctFloat,
  158. seriesType = H.seriesType,
  159. merge = H.merge;
  160. /**
  161. * The pareto series type.
  162. *
  163. * @private
  164. * @class
  165. * @name Highcharts.seriesTypes.pareto
  166. *
  167. * @augments Highcharts.Series
  168. */
  169. seriesType('pareto', 'line'
  170. /**
  171. * A pareto diagram is a type of chart that contains both bars and a line graph,
  172. * where individual values are represented in descending order by bars, and the
  173. * cumulative total is represented by the line.
  174. *
  175. * @sample {highcharts} highcharts/demo/pareto/
  176. * Pareto diagram
  177. *
  178. * @extends plotOptions.line
  179. * @since 6.0.0
  180. * @product highcharts
  181. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  182. * borderWidth, crisp, colorAxis, depth, data, edgeColor,
  183. * edgeWidth, findNearestPointBy, gapSize, gapUnit, grouping,
  184. * groupPadding, groupZPadding, maxPointWidth, keys,
  185. * negativeColor, pointInterval, pointIntervalUnit, pointPadding,
  186. * pointPlacement, pointRange, pointStart, pointWidth, shadow,
  187. * step, softThreshold, stacking, threshold, zoneAxis, zones
  188. * @optionparent plotOptions.pareto
  189. */
  190. , {
  191. /**
  192. * Higher zIndex than column series to draw line above shapes.
  193. */
  194. zIndex: 3
  195. }, merge(derivedSeriesMixin, {
  196. /**
  197. * Calculate sum and return percent points.
  198. *
  199. * @private
  200. * @function Highcharts.Series#setDerivedData
  201. *
  202. * @return {Array<Array<number,number>>}
  203. * Returns array of points [x,y]
  204. */
  205. setDerivedData: function () {
  206. if (this.baseSeries.yData.length > 1) {
  207. var xValues = this.baseSeries.xData,
  208. yValues = this.baseSeries.yData,
  209. sum = this.sumPointsPercents(yValues, xValues, null, true);
  210. this.setData(
  211. this.sumPointsPercents(yValues, xValues, sum, false),
  212. false
  213. );
  214. }
  215. },
  216. /**
  217. * Calculate y sum and each percent point.
  218. *
  219. * @private
  220. * @function Highcharts.Series#sumPointsPercents
  221. *
  222. * @param {Array<number>} yValues
  223. * Y values
  224. *
  225. * @param {Array<number>} xValues
  226. * X values
  227. *
  228. * @param {number} sum
  229. * Sum of all y values
  230. *
  231. * @param {boolean} [isSum]
  232. * Declares if calculate sum of all points
  233. *
  234. * @return {number|Array<number,number>}
  235. * Returns sum of points or array of points [x,sum]
  236. */
  237. sumPointsPercents: function (yValues, xValues, sum, isSum) {
  238. var sumY = 0,
  239. sumPercent = 0,
  240. percentPoints = [],
  241. percentPoint;
  242. yValues.forEach(function (point, i) {
  243. if (point !== null) {
  244. if (isSum) {
  245. sumY += point;
  246. } else {
  247. percentPoint = (point / sum) * 100;
  248. percentPoints.push([
  249. xValues[i],
  250. correctFloat(sumPercent + percentPoint)
  251. ]);
  252. sumPercent += percentPoint;
  253. }
  254. }
  255. });
  256. return isSum ? sumY : percentPoints;
  257. }
  258. }));
  259. /**
  260. * A `pareto` series. If the [type](#series.pareto.type) option is not
  261. * specified, it is inherited from [chart.type](#chart.type).
  262. *
  263. * @extends series,plotOptions.pareto
  264. * @since 6.0.0
  265. * @product highcharts
  266. * @excluding data, dataParser, dataURL
  267. * @apioption series.pareto
  268. */
  269. /**
  270. * An integer identifying the index to use for the base series, or a string
  271. * representing the id of the series.
  272. *
  273. * @type {number|string}
  274. * @default undefined
  275. * @apioption series.pareto.baseSeries
  276. */
  277. /**
  278. * An array of data points for the series. For the `pareto` series type,
  279. * points are calculated dynamically.
  280. *
  281. * @type {Array<Array<number|string>|*>}
  282. * @extends series.column.data
  283. * @since 6.0.0
  284. * @product highcharts
  285. * @apioption series.pareto.data
  286. */
  287. }(Highcharts, derivedSeriesMixin));
  288. return (function () {
  289. }());
  290. }));