variable-pie.src.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * Variable Pie module for Highcharts
  5. *
  6. * (c) 2010-2021 Grzegorz Blachliński
  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/variable-pie', ['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, 'Series/VariablePie/VariablePieSeries.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, U) {
  32. /* *
  33. *
  34. * Variable Pie module for Highcharts
  35. *
  36. * (c) 2010-2021 Grzegorz Blachliński
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. var __extends = (this && this.__extends) || (function () {
  44. var extendStatics = function (d,
  45. b) {
  46. extendStatics = Object.setPrototypeOf ||
  47. ({ __proto__: [] } instanceof Array && function (d,
  48. b) { d.__proto__ = b; }) ||
  49. function (d,
  50. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  51. return extendStatics(d, b);
  52. };
  53. return function (d, b) {
  54. extendStatics(d, b);
  55. function __() { this.constructor = d; }
  56. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  57. };
  58. })();
  59. var PieSeries = SeriesRegistry.seriesTypes.pie;
  60. var arrayMax = U.arrayMax,
  61. arrayMin = U.arrayMin,
  62. clamp = U.clamp,
  63. extend = U.extend,
  64. fireEvent = U.fireEvent,
  65. merge = U.merge,
  66. pick = U.pick;
  67. /* *
  68. *
  69. * Class
  70. *
  71. * */
  72. /**
  73. * The variablepie series type.
  74. *
  75. * @private
  76. * @class
  77. * @name Highcharts.seriesTypes.variablepie
  78. *
  79. * @augments Highcharts.Series
  80. */
  81. var VariablePieSeries = /** @class */ (function (_super) {
  82. __extends(VariablePieSeries, _super);
  83. function VariablePieSeries() {
  84. /* *
  85. *
  86. * Static Properties
  87. *
  88. * */
  89. var _this = _super !== null && _super.apply(this,
  90. arguments) || this;
  91. /* *
  92. *
  93. * Properties
  94. *
  95. * */
  96. _this.data = void 0;
  97. _this.options = void 0;
  98. _this.points = void 0;
  99. _this.radii = void 0;
  100. return _this;
  101. /* eslint-enable valid-jsdoc */
  102. }
  103. /* *
  104. *
  105. * Functions
  106. *
  107. * */
  108. /* eslint-disable valid-jsdoc */
  109. /**
  110. * Before standard translate method for pie chart it is needed to calculate
  111. * min/max radius of each pie slice based on its Z value.
  112. * @private
  113. */
  114. VariablePieSeries.prototype.calculateExtremes = function () {
  115. var series = this,
  116. chart = series.chart,
  117. plotWidth = chart.plotWidth,
  118. plotHeight = chart.plotHeight,
  119. seriesOptions = series.options,
  120. slicingRoom = 2 * (seriesOptions.slicedOffset || 0),
  121. zMin,
  122. zMax,
  123. zData = series.zData,
  124. smallestSize = Math.min(plotWidth,
  125. plotHeight) - slicingRoom,
  126. // Min and max size of pie slice:
  127. extremes = {},
  128. // In pie charts size of a pie is changed to make space for
  129. // dataLabels, then series.center is changing.
  130. positions = series.center || series.getCenter();
  131. ['minPointSize', 'maxPointSize'].forEach(function (prop) {
  132. var length = seriesOptions[prop],
  133. isPercent = /%$/.test(length);
  134. length = parseInt(length, 10);
  135. extremes[prop] = isPercent ?
  136. smallestSize * length / 100 :
  137. length * 2; // Because it should be radius, not diameter.
  138. });
  139. series.minPxSize = positions[3] + extremes.minPointSize;
  140. series.maxPxSize = clamp(positions[2], positions[3] + extremes.minPointSize, extremes.maxPointSize);
  141. if (zData.length) {
  142. zMin = pick(seriesOptions.zMin, arrayMin(zData.filter(series.zValEval)));
  143. zMax = pick(seriesOptions.zMax, arrayMax(zData.filter(series.zValEval)));
  144. this.getRadii(zMin, zMax, series.minPxSize, series.maxPxSize);
  145. }
  146. };
  147. /**
  148. * Finding radius of series points based on their Z value and min/max Z
  149. * value for all series.
  150. *
  151. * @private
  152. * @function Highcharts.Series#getRadii
  153. *
  154. * @param {number} zMin
  155. * Min threshold for Z value. If point's Z value is smaller that zMin, point
  156. * will have the smallest possible radius.
  157. *
  158. * @param {number} zMax
  159. * Max threshold for Z value. If point's Z value is bigger that zMax, point
  160. * will have the biggest possible radius.
  161. *
  162. * @param {number} minSize
  163. * Minimal pixel size possible for radius.
  164. *
  165. * @param {numbner} maxSize
  166. * Minimal pixel size possible for radius.
  167. */
  168. VariablePieSeries.prototype.getRadii = function (zMin, zMax, minSize, maxSize) {
  169. var i = 0,
  170. pos,
  171. zData = this.zData,
  172. len = zData.length,
  173. radii = [],
  174. options = this.options,
  175. sizeByArea = options.sizeBy !== 'radius',
  176. zRange = zMax - zMin,
  177. value,
  178. radius;
  179. // Calculate radius for all pie slice's based on their Z values
  180. for (i; i < len; i++) {
  181. // if zData[i] is null/undefined/string we need to take zMin for
  182. // smallest radius.
  183. value = this.zValEval(zData[i]) ? zData[i] : zMin;
  184. if (value <= zMin) {
  185. radius = minSize / 2;
  186. }
  187. else if (value >= zMax) {
  188. radius = maxSize / 2;
  189. }
  190. else {
  191. // Relative size, a number between 0 and 1
  192. pos = zRange > 0 ? (value - zMin) / zRange : 0.5;
  193. if (sizeByArea) {
  194. pos = Math.sqrt(pos);
  195. }
  196. radius = Math.ceil(minSize + pos * (maxSize - minSize)) / 2;
  197. }
  198. radii.push(radius);
  199. }
  200. this.radii = radii;
  201. };
  202. /**
  203. * It is needed to null series.center on chart redraw. Probably good idea
  204. * will be to add this option in directly in pie series.
  205. * @private
  206. */
  207. VariablePieSeries.prototype.redraw = function () {
  208. this.center = null;
  209. _super.prototype.redraw.apply(this, arguments);
  210. };
  211. /**
  212. * Extend translate by updating radius for each pie slice instead of using
  213. * one global radius.
  214. * @private
  215. */
  216. VariablePieSeries.prototype.translate = function (positions) {
  217. this.generatePoints();
  218. var series = this,
  219. cumulative = 0,
  220. precision = 1000, // issue #172
  221. options = series.options,
  222. slicedOffset = options.slicedOffset,
  223. connectorOffset = slicedOffset + (options.borderWidth || 0),
  224. finalConnectorOffset,
  225. start,
  226. end,
  227. angle,
  228. startAngle = options.startAngle || 0,
  229. startAngleRad = Math.PI / 180 * (startAngle - 90),
  230. endAngleRad = Math.PI / 180 * (pick(options.endAngle,
  231. startAngle + 360) - 90),
  232. circ = endAngleRad - startAngleRad, // 2 * Math.PI,
  233. points = series.points,
  234. // the x component of the radius vector for a given point
  235. radiusX,
  236. radiusY,
  237. labelDistance = options.dataLabels.distance,
  238. ignoreHiddenPoint = options.ignoreHiddenPoint,
  239. i,
  240. len = points.length,
  241. point,
  242. pointRadii,
  243. pointRadiusX,
  244. pointRadiusY;
  245. series.startAngleRad = startAngleRad;
  246. series.endAngleRad = endAngleRad;
  247. // Use calculateExtremes to get series.radii array.
  248. series.calculateExtremes();
  249. // Get positions - either an integer or a percentage string must be
  250. // given. If positions are passed as a parameter, we're in a
  251. // recursive loop for adjusting space for data labels.
  252. if (!positions) {
  253. series.center = positions = series.getCenter();
  254. }
  255. // Calculate the geometry for each point
  256. for (i = 0; i < len; i++) {
  257. point = points[i];
  258. pointRadii = series.radii[i];
  259. // Used for distance calculation for specific point.
  260. point.labelDistance = pick(point.options.dataLabels &&
  261. point.options.dataLabels.distance, labelDistance);
  262. // Saved for later dataLabels distance calculation.
  263. series.maxLabelDistance = Math.max(series.maxLabelDistance || 0, point.labelDistance);
  264. // set start and end angle
  265. start = startAngleRad + (cumulative * circ);
  266. if (!ignoreHiddenPoint || point.visible) {
  267. cumulative += point.percentage / 100;
  268. }
  269. end = startAngleRad + (cumulative * circ);
  270. // set the shape
  271. point.shapeType = 'arc';
  272. point.shapeArgs = {
  273. x: positions[0],
  274. y: positions[1],
  275. r: pointRadii,
  276. innerR: positions[3] / 2,
  277. start: Math.round(start * precision) / precision,
  278. end: Math.round(end * precision) / precision
  279. };
  280. // The angle must stay within -90 and 270 (#2645)
  281. angle = (end + start) / 2;
  282. if (angle > 1.5 * Math.PI) {
  283. angle -= 2 * Math.PI;
  284. }
  285. else if (angle < -Math.PI / 2) {
  286. angle += 2 * Math.PI;
  287. }
  288. // Center for the sliced out slice
  289. point.slicedTranslation = {
  290. translateX: Math.round(Math.cos(angle) * slicedOffset),
  291. translateY: Math.round(Math.sin(angle) * slicedOffset)
  292. };
  293. // set the anchor point for tooltips
  294. radiusX = Math.cos(angle) * positions[2] / 2;
  295. radiusY = Math.sin(angle) * positions[2] / 2;
  296. pointRadiusX = Math.cos(angle) * pointRadii;
  297. pointRadiusY = Math.sin(angle) * pointRadii;
  298. point.tooltipPos = [
  299. positions[0] + radiusX * 0.7,
  300. positions[1] + radiusY * 0.7
  301. ];
  302. point.half = angle < -Math.PI / 2 || angle > Math.PI / 2 ?
  303. 1 :
  304. 0;
  305. point.angle = angle;
  306. // Set the anchor point for data labels. Use point.labelDistance
  307. // instead of labelDistance // #1174
  308. // finalConnectorOffset - not override connectorOffset value.
  309. finalConnectorOffset = Math.min(connectorOffset, point.labelDistance / 5); // #1678
  310. point.labelPosition = {
  311. natural: {
  312. // initial position of the data label - it's utilized
  313. // for finding the final position for the label
  314. x: positions[0] + pointRadiusX +
  315. Math.cos(angle) * point.labelDistance,
  316. y: positions[1] + pointRadiusY +
  317. Math.sin(angle) * point.labelDistance
  318. },
  319. 'final': {
  320. // used for generating connector path -
  321. // initialized later in drawDataLabels function
  322. // x: undefined,
  323. // y: undefined
  324. },
  325. // left - pie on the left side of the data label
  326. // right - pie on the right side of the data label
  327. alignment: point.half ? 'right' : 'left',
  328. connectorPosition: {
  329. breakAt: {
  330. x: positions[0] + pointRadiusX +
  331. Math.cos(angle) * finalConnectorOffset,
  332. y: positions[1] + pointRadiusY +
  333. Math.sin(angle) * finalConnectorOffset
  334. },
  335. touchingSliceAt: {
  336. x: positions[0] + pointRadiusX,
  337. y: positions[1] + pointRadiusY
  338. }
  339. }
  340. };
  341. }
  342. fireEvent(series, 'afterTranslate');
  343. };
  344. /**
  345. * For arrayMin and arrayMax calculations array shouldn't have
  346. * null/undefined/string values. In this case it is needed to check if
  347. * points Z value is a Number.
  348. * @private
  349. */
  350. VariablePieSeries.prototype.zValEval = function (zVal) {
  351. if (typeof zVal === 'number' && !isNaN(zVal)) {
  352. return true;
  353. }
  354. return null;
  355. };
  356. /**
  357. * A variable pie series is a two dimensional series type, where each point
  358. * renders an Y and Z value. Each point is drawn as a pie slice where the
  359. * size (arc) of the slice relates to the Y value and the radius of pie
  360. * slice relates to the Z value.
  361. *
  362. * @sample {highcharts} highcharts/demo/variable-radius-pie/
  363. * Variable-radius pie chart
  364. *
  365. * @extends plotOptions.pie
  366. * @excluding dragDrop
  367. * @since 6.0.0
  368. * @product highcharts
  369. * @requires modules/variable-pie.js
  370. * @optionparent plotOptions.variablepie
  371. */
  372. VariablePieSeries.defaultOptions = merge(PieSeries.defaultOptions, {
  373. /**
  374. * The minimum size of the points' radius related to chart's `plotArea`.
  375. * If a number is set, it applies in pixels.
  376. *
  377. * @sample {highcharts} highcharts/variable-radius-pie/min-max-point-size/
  378. * Example of minPointSize and maxPointSize
  379. * @sample {highcharts} highcharts/variable-radius-pie/min-point-size-100/
  380. * minPointSize set to 100
  381. *
  382. * @type {number|string}
  383. * @since 6.0.0
  384. */
  385. minPointSize: '10%',
  386. /**
  387. * The maximum size of the points' radius related to chart's `plotArea`.
  388. * If a number is set, it applies in pixels.
  389. *
  390. * @sample {highcharts} highcharts/variable-radius-pie/min-max-point-size/
  391. * Example of minPointSize and maxPointSize
  392. *
  393. * @type {number|string}
  394. * @since 6.0.0
  395. */
  396. maxPointSize: '100%',
  397. /**
  398. * The minimum possible z value for the point's radius calculation. If
  399. * the point's Z value is smaller than zMin, the slice will be drawn
  400. * according to the zMin value.
  401. *
  402. * @sample {highcharts} highcharts/variable-radius-pie/zmin-5/
  403. * zMin set to 5, smaller z values are treated as 5
  404. * @sample {highcharts} highcharts/variable-radius-pie/zmin-zmax/
  405. * Series limited by both zMin and zMax
  406. *
  407. * @type {number}
  408. * @since 6.0.0
  409. */
  410. zMin: void 0,
  411. /**
  412. * The maximum possible z value for the point's radius calculation. If
  413. * the point's Z value is bigger than zMax, the slice will be drawn
  414. * according to the zMax value
  415. *
  416. * @sample {highcharts} highcharts/variable-radius-pie/zmin-zmax/
  417. * Series limited by both zMin and zMax
  418. *
  419. * @type {number}
  420. * @since 6.0.0
  421. */
  422. zMax: void 0,
  423. /**
  424. * Whether the pie slice's value should be represented by the area or
  425. * the radius of the slice. Can be either `area` or `radius`. The
  426. * default, `area`, corresponds best to the human perception of the size
  427. * of each pie slice.
  428. *
  429. * @sample {highcharts} highcharts/variable-radius-pie/sizeby/
  430. * Difference between area and radius sizeBy
  431. *
  432. * @type {Highcharts.VariablePieSizeByValue}
  433. * @since 6.0.0
  434. */
  435. sizeBy: 'area',
  436. tooltip: {
  437. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}<br/>Value: {point.y}<br/>Size: {point.z}<br/>'
  438. }
  439. });
  440. return VariablePieSeries;
  441. }(PieSeries));
  442. extend(VariablePieSeries.prototype, {
  443. pointArrayMap: ['y', 'z'],
  444. parallelArrays: ['x', 'y', 'z']
  445. });
  446. SeriesRegistry.registerSeriesType('variablepie', VariablePieSeries);
  447. /* *
  448. *
  449. * Default Export
  450. *
  451. * */
  452. /* *
  453. *
  454. * API Declarations
  455. *
  456. * */
  457. /**
  458. * @typedef {"area"|"radius"} Highcharts.VariablePieSizeByValue
  459. */
  460. ''; // detach doclets above
  461. /* *
  462. *
  463. * API Options
  464. *
  465. * */
  466. /**
  467. * A `variablepie` series. If the [type](#series.variablepie.type) option is not
  468. * specified, it is inherited from [chart.type](#chart.type).
  469. *
  470. * @extends series,plotOptions.variablepie
  471. * @excluding dataParser, dataURL, stack, xAxis, yAxis, dataSorting,
  472. * boostThreshold, boostBlending
  473. * @product highcharts
  474. * @requires modules/variable-pie.js
  475. * @apioption series.variablepie
  476. */
  477. /**
  478. * An array of data points for the series. For the `variablepie` series type,
  479. * points can be given in the following ways:
  480. *
  481. * 1. An array of arrays with 2 values. In this case, the numerical values will
  482. * be interpreted as `y, z` options. Example:
  483. * ```js
  484. * data: [
  485. * [40, 75],
  486. * [50, 50],
  487. * [60, 40]
  488. * ]
  489. * ```
  490. *
  491. * 2. An array of objects with named values. The following snippet shows only a
  492. * few settings, see the complete options set below. If the total number of
  493. * data points exceeds the series'
  494. * [turboThreshold](#series.variablepie.turboThreshold), this option is not
  495. * available.
  496. * ```js
  497. * data: [{
  498. * y: 1,
  499. * z: 4,
  500. * name: "Point2",
  501. * color: "#00FF00"
  502. * }, {
  503. * y: 7,
  504. * z: 10,
  505. * name: "Point1",
  506. * color: "#FF00FF"
  507. * }]
  508. * ```
  509. *
  510. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  511. * Arrays of numeric x and y
  512. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  513. * Arrays of datetime x and y
  514. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  515. * Arrays of point.name and y
  516. * @sample {highcharts} highcharts/series/data-array-of-objects/
  517. * Config objects
  518. *
  519. * @type {Array<Array<(number|string),number>|*>}
  520. * @extends series.pie.data
  521. * @excluding marker, x
  522. * @product highcharts
  523. * @apioption series.variablepie.data
  524. */
  525. ''; // adds doclets above to transpiled file
  526. return VariablePieSeries;
  527. });
  528. _registerModule(_modules, 'masters/modules/variable-pie.src.js', [], function () {
  529. });
  530. }));