pareto.src.js 11 KB

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