pareto.src.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * Pareto series type for Highcharts
  5. *
  6. * (c) 2010-2021 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/Series/Series.js'], _modules['Core/Utilities.js']], function (H, Series, U) {
  32. /* *
  33. *
  34. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  35. *
  36. * */
  37. var noop = H.noop;
  38. var addEvent = U.addEvent,
  39. defined = U.defined;
  40. /* ************************************************************************** *
  41. *
  42. * DERIVED SERIES MIXIN
  43. *
  44. * ************************************************************************** */
  45. /**
  46. * Provides methods for auto setting/updating series data based on the based
  47. * series data.
  48. *
  49. * @private
  50. * @mixin derivedSeriesMixin
  51. */
  52. var derivedSeriesMixin = {
  53. hasDerivedData: true,
  54. /* eslint-disable valid-jsdoc */
  55. /**
  56. * Initialise series
  57. *
  58. * @private
  59. * @function derivedSeriesMixin.init
  60. * @return {void}
  61. */
  62. init: function () {
  63. Series.prototype.init.apply(this,
  64. arguments);
  65. this.initialised = false;
  66. this.baseSeries = null;
  67. this.eventRemovers = [];
  68. this.addEvents();
  69. },
  70. /**
  71. * Method to be implemented - inside the method the series has already
  72. * access to the base series via m `this.baseSeries` and the bases data is
  73. * initialised. It should return data in the format accepted by
  74. * `Series.setData()` method
  75. *
  76. * @private
  77. * @function derivedSeriesMixin.setDerivedData
  78. * @return {Array<Highcharts.PointOptionsType>}
  79. * An array of data
  80. */
  81. setDerivedData: noop,
  82. /**
  83. * Sets base series for the series
  84. *
  85. * @private
  86. * @function derivedSeriesMixin.setBaseSeries
  87. * @return {void}
  88. */
  89. setBaseSeries: function () {
  90. var chart = this.chart,
  91. baseSeriesOptions = this.options.baseSeries,
  92. baseSeries = (defined(baseSeriesOptions) &&
  93. (chart.series[baseSeriesOptions] ||
  94. chart.get(baseSeriesOptions)));
  95. this.baseSeries = baseSeries || null;
  96. },
  97. /**
  98. * Adds events for the series
  99. *
  100. * @private
  101. * @function derivedSeriesMixin.addEvents
  102. * @return {void}
  103. */
  104. addEvents: function () {
  105. var derivedSeries = this,
  106. chartSeriesLinked;
  107. chartSeriesLinked = addEvent(this.chart, 'afterLinkSeries', function () {
  108. derivedSeries.setBaseSeries();
  109. if (derivedSeries.baseSeries && !derivedSeries.initialised) {
  110. derivedSeries.setDerivedData();
  111. derivedSeries.addBaseSeriesEvents();
  112. derivedSeries.initialised = true;
  113. }
  114. });
  115. this.eventRemovers.push(chartSeriesLinked);
  116. },
  117. /**
  118. * Adds events to the base series - it required for recalculating the data
  119. * in the series if the base series is updated / removed / etc.
  120. *
  121. * @private
  122. * @function derivedSeriesMixin.addBaseSeriesEvents
  123. * @return {void}
  124. */
  125. addBaseSeriesEvents: function () {
  126. var derivedSeries = this,
  127. updatedDataRemover,
  128. destroyRemover;
  129. updatedDataRemover = addEvent(derivedSeries.baseSeries, 'updatedData', function () {
  130. derivedSeries.setDerivedData();
  131. });
  132. destroyRemover = addEvent(derivedSeries.baseSeries, 'destroy', function () {
  133. derivedSeries.baseSeries = null;
  134. derivedSeries.initialised = false;
  135. });
  136. derivedSeries.eventRemovers.push(updatedDataRemover, destroyRemover);
  137. },
  138. /**
  139. * Destroys the series
  140. *
  141. * @private
  142. * @function derivedSeriesMixin.destroy
  143. */
  144. destroy: function () {
  145. this.eventRemovers.forEach(function (remover) {
  146. remover();
  147. });
  148. Series.prototype.destroy.apply(this, arguments);
  149. }
  150. /* eslint-disable valid-jsdoc */
  151. };
  152. return derivedSeriesMixin;
  153. });
  154. _registerModule(_modules, 'Series/ParetoSeries/ParetoSeries.js', [_modules['Mixins/DerivedSeries.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (DerivedSeriesMixin, SeriesRegistry, U) {
  155. /* *
  156. *
  157. * (c) 2010-2021 Sebastian Bochan
  158. *
  159. * License: www.highcharts.com/license
  160. *
  161. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  162. *
  163. * */
  164. var __extends = (this && this.__extends) || (function () {
  165. var extendStatics = function (d,
  166. b) {
  167. extendStatics = Object.setPrototypeOf ||
  168. ({ __proto__: [] } instanceof Array && function (d,
  169. b) { d.__proto__ = b; }) ||
  170. function (d,
  171. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  172. return extendStatics(d, b);
  173. };
  174. return function (d, b) {
  175. extendStatics(d, b);
  176. function __() { this.constructor = d; }
  177. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  178. };
  179. })();
  180. var LineSeries = SeriesRegistry.seriesTypes.line;
  181. var correctFloat = U.correctFloat,
  182. merge = U.merge,
  183. extend = U.extend;
  184. /* *
  185. *
  186. * Class
  187. *
  188. * */
  189. /**
  190. * The pareto series type.
  191. *
  192. * @private
  193. * @class
  194. * @name Highcharts.seriesTypes.pareto
  195. *
  196. * @augments Highcharts.Series
  197. */
  198. var ParetoSeries = /** @class */ (function (_super) {
  199. __extends(ParetoSeries, _super);
  200. function ParetoSeries() {
  201. /* *
  202. *
  203. * Static properties
  204. *
  205. * */
  206. var _this = _super !== null && _super.apply(this,
  207. arguments) || this;
  208. /* *
  209. *
  210. * Properties
  211. *
  212. * */
  213. _this.data = void 0;
  214. _this.points = void 0;
  215. _this.options = void 0;
  216. return _this;
  217. }
  218. /* *
  219. *
  220. * Functions
  221. *
  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. ParetoSeries.prototype.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. * Calculate sum and return percent points.
  270. *
  271. * @private
  272. * @function Highcharts.Series#setDerivedData
  273. * @requires modules/pareto
  274. */
  275. ParetoSeries.prototype.setDerivedData = function () {
  276. var xValues = this.baseSeries.xData,
  277. yValues = this.baseSeries.yData,
  278. sum = this.sumPointsPercents(yValues,
  279. xValues,
  280. null,
  281. true);
  282. this.setData(this.sumPointsPercents(yValues, xValues, sum, false), false);
  283. };
  284. /**
  285. * A pareto diagram is a type of chart that contains both bars and a line
  286. * graph, where individual values are represented in descending order by
  287. * bars, and the cumulative total is represented by the line.
  288. *
  289. * @sample {highcharts} highcharts/demo/pareto/
  290. * Pareto diagram
  291. *
  292. * @extends plotOptions.line
  293. * @since 6.0.0
  294. * @product highcharts
  295. * @excluding allAreas, boostThreshold, borderColor, borderRadius,
  296. * borderWidth, crisp, colorAxis, depth, data, dragDrop,
  297. * edgeColor, edgeWidth, findNearestPointBy, gapSize, gapUnit,
  298. * grouping, groupPadding, groupZPadding, maxPointWidth, keys,
  299. * negativeColor, pointInterval, pointIntervalUnit,
  300. * pointPadding, pointPlacement, pointRange, pointStart,
  301. * pointWidth, shadow, step, softThreshold, stacking,
  302. * threshold, zoneAxis, zones, boostBlending
  303. * @requires modules/pareto
  304. * @optionparent plotOptions.pareto
  305. */
  306. ParetoSeries.defaultOptions = merge(LineSeries.defaultOptions, {
  307. /**
  308. * Higher zIndex than column series to draw line above shapes.
  309. */
  310. zIndex: 3
  311. });
  312. return ParetoSeries;
  313. }(LineSeries));
  314. extend(ParetoSeries.prototype, {
  315. addBaseSeriesEvents: DerivedSeriesMixin.addBaseSeriesEvents,
  316. addEvents: DerivedSeriesMixin.addEvents,
  317. destroy: DerivedSeriesMixin.destroy,
  318. hasDerivedData: DerivedSeriesMixin.hasDerivedData,
  319. init: DerivedSeriesMixin.init,
  320. setBaseSeries: DerivedSeriesMixin.setBaseSeries
  321. });
  322. SeriesRegistry.registerSeriesType('pareto', ParetoSeries);
  323. /* *
  324. *
  325. * Default export
  326. *
  327. * */
  328. /* *
  329. *
  330. * API options
  331. *
  332. * */
  333. /**
  334. * A `pareto` series. If the [type](#series.pareto.type) option is not
  335. * specified, it is inherited from [chart.type](#chart.type).
  336. *
  337. * @extends series,plotOptions.pareto
  338. * @since 6.0.0
  339. * @product highcharts
  340. * @excluding data, dataParser, dataURL, boostThreshold, boostBlending
  341. * @requires modules/pareto
  342. * @apioption series.pareto
  343. */
  344. /**
  345. * An integer identifying the index to use for the base series, or a string
  346. * representing the id of the series.
  347. *
  348. * @type {number|string}
  349. * @default undefined
  350. * @apioption series.pareto.baseSeries
  351. */
  352. /**
  353. * An array of data points for the series. For the `pareto` series type,
  354. * points are calculated dynamically.
  355. *
  356. * @type {Array<Array<number|string>|*>}
  357. * @extends series.column.data
  358. * @since 6.0.0
  359. * @product highcharts
  360. * @apioption series.pareto.data
  361. */
  362. ''; // adds the doclets above to the transpiled file
  363. return ParetoSeries;
  364. });
  365. _registerModule(_modules, 'masters/modules/pareto.src.js', [], function () {
  366. });
  367. }));