pareto.src.js 11 KB

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