pareto.src.js 11 KB

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