pareto.src.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /**
  2. * @license Highcharts JS v8.2.0 (2020-08-20)
  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/Utilities.js'], _modules['Mixins/DerivedSeries.js']], function (U, derivedSeriesMixin) {
  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. seriesType = U.seriesType;
  168. /**
  169. * The pareto series type.
  170. *
  171. * @private
  172. * @class
  173. * @name Highcharts.seriesTypes.pareto
  174. *
  175. * @augments Highcharts.Series
  176. */
  177. seriesType('pareto', 'line'
  178. /**
  179. * A pareto diagram is a type of chart that contains both bars and a line
  180. * graph, where individual values are represented in descending order by
  181. * bars, and the cumulative total is represented by the line.
  182. *
  183. * @sample {highcharts} highcharts/demo/pareto/
  184. * Pareto diagram
  185. *
  186. * @extends plotOptions.line
  187. * @since 6.0.0
  188. * @product highcharts
  189. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  190. * borderWidth, crisp, colorAxis, depth, data, dragDrop,
  191. * edgeColor, edgeWidth, findNearestPointBy, gapSize, gapUnit,
  192. * grouping, groupPadding, groupZPadding, maxPointWidth, keys,
  193. * negativeColor, pointInterval, pointIntervalUnit,
  194. * pointPadding, pointPlacement, pointRange, pointStart,
  195. * pointWidth, shadow, step, softThreshold, stacking,
  196. * threshold, zoneAxis, zones, boostBlending
  197. * @requires modules/pareto
  198. * @optionparent plotOptions.pareto
  199. */
  200. , {
  201. /**
  202. * Higher zIndex than column series to draw line above shapes.
  203. */
  204. zIndex: 3
  205. },
  206. /* eslint-disable no-invalid-this, valid-jsdoc */
  207. merge(derivedSeriesMixin, {
  208. /**
  209. * Calculate sum and return percent points.
  210. *
  211. * @private
  212. * @function Highcharts.Series#setDerivedData
  213. * @requires modules/pareto
  214. */
  215. setDerivedData: function () {
  216. var xValues = this.baseSeries.xData,
  217. yValues = this.baseSeries.yData,
  218. sum = this.sumPointsPercents(yValues,
  219. xValues,
  220. null,
  221. true);
  222. this.setData(this.sumPointsPercents(yValues, xValues, sum, false), false);
  223. },
  224. /**
  225. * Calculate y sum and each percent point.
  226. *
  227. * @private
  228. * @function Highcharts.Series#sumPointsPercents
  229. *
  230. * @param {Array<number>} yValues
  231. * Y values
  232. *
  233. * @param {Array<number>} xValues
  234. * X values
  235. *
  236. * @param {number} sum
  237. * Sum of all y values
  238. *
  239. * @param {boolean} [isSum]
  240. * Declares if calculate sum of all points
  241. *
  242. * @return {number|Array<number,number>}
  243. * Returns sum of points or array of points [x,sum]
  244. *
  245. * @requires modules/pareto
  246. */
  247. sumPointsPercents: function (yValues, xValues, sum, isSum) {
  248. var sumY = 0,
  249. sumPercent = 0,
  250. percentPoints = [],
  251. percentPoint;
  252. yValues.forEach(function (point, i) {
  253. if (point !== null) {
  254. if (isSum) {
  255. sumY += point;
  256. }
  257. else {
  258. percentPoint = (point / sum) * 100;
  259. percentPoints.push([
  260. xValues[i],
  261. correctFloat(sumPercent + percentPoint)
  262. ]);
  263. sumPercent += percentPoint;
  264. }
  265. }
  266. });
  267. return (isSum ? sumY : percentPoints);
  268. }
  269. })
  270. /* eslint-enable no-invalid-this, valid-jsdoc */
  271. );
  272. /**
  273. * A `pareto` series. If the [type](#series.pareto.type) option is not
  274. * specified, it is inherited from [chart.type](#chart.type).
  275. *
  276. * @extends series,plotOptions.pareto
  277. * @since 6.0.0
  278. * @product highcharts
  279. * @excluding data, dataParser, dataURL, boostThreshold, boostBlending
  280. * @requires modules/pareto
  281. * @apioption series.pareto
  282. */
  283. /**
  284. * An integer identifying the index to use for the base series, or a string
  285. * representing the id of the series.
  286. *
  287. * @type {number|string}
  288. * @default undefined
  289. * @apioption series.pareto.baseSeries
  290. */
  291. /**
  292. * An array of data points for the series. For the `pareto` series type,
  293. * points are calculated dynamically.
  294. *
  295. * @type {Array<Array<number|string>|*>}
  296. * @extends series.column.data
  297. * @since 6.0.0
  298. * @product highcharts
  299. * @apioption series.pareto.data
  300. */
  301. ''; // adds the doclets above to the transpiled file
  302. });
  303. _registerModule(_modules, 'masters/modules/pareto.src.js', [], function () {
  304. });
  305. }));