dependency-wheel.src.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * Dependency wheel module
  5. *
  6. * (c) 2010-2021 Torstein Honsi
  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/dependency-wheel', ['highcharts', 'highcharts/modules/sankey'], 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/DependencyWheel/DependencyWheelPoint.js', [_modules['Mixins/Nodes.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (NodesMixin, SeriesRegistry, U) {
  32. /* *
  33. *
  34. * Dependency wheel module
  35. *
  36. * (c) 2018-2021 Torstein Honsi
  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 SankeySeries = SeriesRegistry.seriesTypes.sankey;
  60. var extend = U.extend;
  61. /* *
  62. *
  63. * Class
  64. *
  65. * */
  66. var DependencyWheelPoint = /** @class */ (function (_super) {
  67. __extends(DependencyWheelPoint, _super);
  68. function DependencyWheelPoint() {
  69. /* *
  70. *
  71. * Properties
  72. *
  73. * */
  74. var _this = _super !== null && _super.apply(this,
  75. arguments) || this;
  76. _this.angle = void 0;
  77. _this.fromNode = void 0;
  78. _this.index = void 0;
  79. _this.linksFrom = void 0;
  80. _this.linksTo = void 0;
  81. _this.options = void 0;
  82. _this.series = void 0;
  83. _this.shapeArgs = void 0;
  84. _this.toNode = void 0;
  85. return _this;
  86. /* eslint-enable valid-jsdoc */
  87. }
  88. /* *
  89. *
  90. * Functions
  91. *
  92. * */
  93. /* eslint-disable valid-jsdoc */
  94. /**
  95. * Return a text path that the data label uses.
  96. * @private
  97. */
  98. DependencyWheelPoint.prototype.getDataLabelPath = function (label) {
  99. var renderer = this.series.chart.renderer,
  100. shapeArgs = this.shapeArgs,
  101. upperHalf = this.angle < 0 || this.angle > Math.PI,
  102. start = shapeArgs.start || 0,
  103. end = shapeArgs.end || 0;
  104. if (!this.dataLabelPath) {
  105. this.dataLabelPath = renderer
  106. .arc({
  107. open: true,
  108. longArc: Math.abs(Math.abs(start) - Math.abs(end)) < Math.PI ? 0 : 1
  109. })
  110. // Add it inside the data label group so it gets destroyed
  111. // with the label
  112. .add(label);
  113. }
  114. this.dataLabelPath.attr({
  115. x: shapeArgs.x,
  116. y: shapeArgs.y,
  117. r: (shapeArgs.r +
  118. (this.dataLabel.options.distance || 0)),
  119. start: (upperHalf ? start : end),
  120. end: (upperHalf ? end : start),
  121. clockwise: +upperHalf
  122. });
  123. return this.dataLabelPath;
  124. };
  125. DependencyWheelPoint.prototype.isValid = function () {
  126. // No null points here
  127. return true;
  128. };
  129. return DependencyWheelPoint;
  130. }(SankeySeries.prototype.pointClass));
  131. extend(DependencyWheelPoint.prototype, {
  132. setState: NodesMixin.setNodeState
  133. });
  134. /* *
  135. *
  136. * Default Export
  137. *
  138. * */
  139. return DependencyWheelPoint;
  140. });
  141. _registerModule(_modules, 'Series/DependencyWheel/DependencyWheelSeries.js', [_modules['Core/Animation/AnimationUtilities.js'], _modules['Series/DependencyWheel/DependencyWheelPoint.js'], _modules['Core/Globals.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (A, DependencyWheelPoint, H, SeriesRegistry, U) {
  142. /* *
  143. *
  144. * Dependency wheel module
  145. *
  146. * (c) 2018-2021 Torstein Honsi
  147. *
  148. * License: www.highcharts.com/license
  149. *
  150. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  151. *
  152. * */
  153. var __extends = (this && this.__extends) || (function () {
  154. var extendStatics = function (d,
  155. b) {
  156. extendStatics = Object.setPrototypeOf ||
  157. ({ __proto__: [] } instanceof Array && function (d,
  158. b) { d.__proto__ = b; }) ||
  159. function (d,
  160. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  161. return extendStatics(d, b);
  162. };
  163. return function (d, b) {
  164. extendStatics(d, b);
  165. function __() { this.constructor = d; }
  166. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  167. };
  168. })();
  169. var animObject = A.animObject;
  170. var deg2rad = H.deg2rad;
  171. var _a = SeriesRegistry.seriesTypes,
  172. PieSeries = _a.pie,
  173. SankeySeries = _a.sankey;
  174. var extend = U.extend,
  175. merge = U.merge;
  176. /* *
  177. *
  178. * Class
  179. *
  180. * */
  181. /**
  182. * @private
  183. * @class
  184. * @name Highcharts.seriesTypes.dependencywheel
  185. *
  186. * @augments Highcharts.seriesTypes.sankey
  187. */
  188. var DependencyWheelSeries = /** @class */ (function (_super) {
  189. __extends(DependencyWheelSeries, _super);
  190. function DependencyWheelSeries() {
  191. /* *
  192. *
  193. * Static Properties
  194. *
  195. * */
  196. var _this = _super !== null && _super.apply(this,
  197. arguments) || this;
  198. /* *
  199. *
  200. * Properties
  201. *
  202. * */
  203. _this.data = void 0;
  204. _this.options = void 0;
  205. _this.nodeColumns = void 0;
  206. _this.nodes = void 0;
  207. _this.points = void 0;
  208. return _this;
  209. /* eslint-enable valid-jsdoc */
  210. }
  211. /* *
  212. *
  213. * Functions
  214. *
  215. * */
  216. /* eslint-disable valid-jsdoc */
  217. DependencyWheelSeries.prototype.animate = function (init) {
  218. if (!init) {
  219. var duration = animObject(this.options.animation).duration,
  220. step_1 = (duration / 2) / this.nodes.length;
  221. this.nodes.forEach(function (point, i) {
  222. var graphic = point.graphic;
  223. if (graphic) {
  224. graphic.attr({ opacity: 0 });
  225. setTimeout(function () {
  226. if (point.graphic) {
  227. point.graphic.animate({ opacity: 1 }, { duration: step_1 });
  228. }
  229. }, step_1 * i);
  230. }
  231. }, this);
  232. this.points.forEach(function (point) {
  233. var graphic = point.graphic;
  234. if (!point.isNode && graphic) {
  235. graphic.attr({ opacity: 0 })
  236. .animate({
  237. opacity: 1
  238. }, this.options.animation);
  239. }
  240. }, this);
  241. }
  242. };
  243. DependencyWheelSeries.prototype.createNode = function (id) {
  244. var node = SankeySeries.prototype.createNode.call(this,
  245. id);
  246. node.index = this.nodes.length - 1;
  247. /**
  248. * Return the sum of incoming and outgoing links.
  249. * @private
  250. */
  251. node.getSum = function () {
  252. return node.linksFrom
  253. .concat(node.linksTo)
  254. .reduce(function (acc, link) {
  255. return acc + link.weight;
  256. }, 0);
  257. };
  258. /**
  259. * Get the offset in weight values of a point/link.
  260. * @private
  261. */
  262. node.offset = function (point) {
  263. var offset = 0,
  264. i,
  265. links = node.linksFrom.concat(node.linksTo),
  266. sliced;
  267. /**
  268. * @private
  269. */
  270. function otherNode(link) {
  271. if (link.fromNode === node) {
  272. return link.toNode;
  273. }
  274. return link.fromNode;
  275. }
  276. // Sort and slice the links to avoid links going out of each
  277. // node crossing each other.
  278. links.sort(function (a, b) {
  279. return otherNode(a).index - otherNode(b).index;
  280. });
  281. for (i = 0; i < links.length; i++) {
  282. if (otherNode(links[i]).index > node.index) {
  283. links = links.slice(0, i).reverse().concat(links.slice(i).reverse());
  284. sliced = true;
  285. break;
  286. }
  287. }
  288. if (!sliced) {
  289. links.reverse();
  290. }
  291. for (i = 0; i < links.length; i++) {
  292. if (links[i] === point) {
  293. return offset;
  294. }
  295. offset += links[i].weight;
  296. }
  297. };
  298. return node;
  299. };
  300. /**
  301. * Dependency wheel has only one column, it runs along the perimeter.
  302. * @private
  303. */
  304. DependencyWheelSeries.prototype.createNodeColumns = function () {
  305. var columns = [this.createNodeColumn()];
  306. this.nodes.forEach(function (node) {
  307. node.column = 0;
  308. columns[0].push(node);
  309. });
  310. return columns;
  311. };
  312. /**
  313. * Translate from vertical pixels to perimeter.
  314. * @private
  315. */
  316. DependencyWheelSeries.prototype.getNodePadding = function () {
  317. return this.options.nodePadding / Math.PI;
  318. };
  319. /**
  320. * @private
  321. * @todo Override the refactored sankey translateLink and translateNode
  322. * functions instead of the whole translate function.
  323. */
  324. DependencyWheelSeries.prototype.translate = function () {
  325. var options = this.options,
  326. factor = 2 * Math.PI /
  327. (this.chart.plotHeight + this.getNodePadding()),
  328. center = this.getCenter(),
  329. startAngle = (options.startAngle - 90) * deg2rad;
  330. SankeySeries.prototype.translate.call(this);
  331. this.nodeColumns[0].forEach(function (node) {
  332. // Don't render the nodes if sum is 0 #12453
  333. if (node.sum) {
  334. var shapeArgs = node.shapeArgs,
  335. centerX_1 = center[0],
  336. centerY_1 = center[1],
  337. r = center[2] / 2,
  338. innerR_1 = r - options.nodeWidth,
  339. start = startAngle + factor * (shapeArgs.y || 0),
  340. end = startAngle +
  341. factor * ((shapeArgs.y || 0) + (shapeArgs.height || 0));
  342. // Middle angle
  343. node.angle = start + (end - start) / 2;
  344. node.shapeType = 'arc';
  345. node.shapeArgs = {
  346. x: centerX_1,
  347. y: centerY_1,
  348. r: r,
  349. innerR: innerR_1,
  350. start: start,
  351. end: end
  352. };
  353. node.dlBox = {
  354. x: centerX_1 + Math.cos((start + end) / 2) * (r + innerR_1) / 2,
  355. y: centerY_1 + Math.sin((start + end) / 2) * (r + innerR_1) / 2,
  356. width: 1,
  357. height: 1
  358. };
  359. // Draw the links from this node
  360. node.linksFrom.forEach(function (point) {
  361. if (point.linkBase) {
  362. var distance_1;
  363. var corners = point.linkBase.map(function (top,
  364. i) {
  365. var angle = factor * top,
  366. x = Math.cos(startAngle + angle) * (innerR_1 + 1),
  367. y = Math.sin(startAngle + angle) * (innerR_1 + 1),
  368. curveFactor = options.curveFactor;
  369. // The distance between the from and to node
  370. // along the perimeter. This affect how curved
  371. // the link is, so that links between neighbours
  372. // don't extend too far towards the center.
  373. distance_1 = Math.abs(point.linkBase[3 - i] * factor - angle);
  374. if (distance_1 > Math.PI) {
  375. distance_1 = 2 * Math.PI - distance_1;
  376. }
  377. distance_1 = distance_1 * innerR_1;
  378. if (distance_1 < innerR_1) {
  379. curveFactor *= (distance_1 / innerR_1);
  380. }
  381. return {
  382. x: centerX_1 + x,
  383. y: centerY_1 + y,
  384. cpX: centerX_1 + (1 - curveFactor) * x,
  385. cpY: centerY_1 + (1 - curveFactor) * y
  386. };
  387. });
  388. point.shapeArgs = {
  389. d: [[
  390. 'M',
  391. corners[0].x, corners[0].y
  392. ], [
  393. 'A',
  394. innerR_1, innerR_1,
  395. 0,
  396. 0,
  397. 1,
  398. corners[1].x, corners[1].y
  399. ], [
  400. 'C',
  401. corners[1].cpX, corners[1].cpY,
  402. corners[2].cpX, corners[2].cpY,
  403. corners[2].x, corners[2].y
  404. ], [
  405. 'A',
  406. innerR_1, innerR_1,
  407. 0,
  408. 0,
  409. 1,
  410. corners[3].x, corners[3].y
  411. ], [
  412. 'C',
  413. corners[3].cpX, corners[3].cpY,
  414. corners[0].cpX, corners[0].cpY,
  415. corners[0].x, corners[0].y
  416. ]]
  417. };
  418. }
  419. });
  420. }
  421. });
  422. };
  423. /**
  424. * A dependency wheel chart is a type of flow diagram, where all nodes are
  425. * laid out in a circle, and the flow between the are drawn as link bands.
  426. *
  427. * @sample highcharts/demo/dependency-wheel/
  428. * Dependency wheel
  429. *
  430. * @extends plotOptions.sankey
  431. * @exclude dataSorting
  432. * @since 7.1.0
  433. * @product highcharts
  434. * @requires modules/dependency-wheel
  435. * @optionparent plotOptions.dependencywheel
  436. */
  437. DependencyWheelSeries.defaultOptions = merge(SankeySeries.defaultOptions, {
  438. /**
  439. * The center of the wheel relative to the plot area. Can be
  440. * percentages or pixel values. The default behaviour is to
  441. * center the wheel inside the plot area.
  442. *
  443. * @type {Array<number|string|null>}
  444. * @default [null, null]
  445. * @product highcharts
  446. */
  447. center: [null, null],
  448. curveFactor: 0.6,
  449. /**
  450. * The start angle of the dependency wheel, in degrees where 0 is up.
  451. */
  452. startAngle: 0
  453. });
  454. return DependencyWheelSeries;
  455. }(SankeySeries));
  456. extend(DependencyWheelSeries.prototype, {
  457. orderNodes: false,
  458. getCenter: PieSeries.prototype.getCenter
  459. });
  460. DependencyWheelSeries.prototype.pointClass = DependencyWheelPoint;
  461. SeriesRegistry.registerSeriesType('dependencywheel', DependencyWheelSeries);
  462. /* *
  463. *
  464. * Default Export
  465. *
  466. * */
  467. /* *
  468. *
  469. * API Options
  470. *
  471. * */
  472. /**
  473. * A `dependencywheel` series. If the [type](#series.dependencywheel.type)
  474. * option is not specified, it is inherited from [chart.type](#chart.type).
  475. *
  476. * @extends series,plotOptions.dependencywheel
  477. * @exclude dataSorting
  478. * @product highcharts
  479. * @requires modules/sankey
  480. * @requires modules/dependency-wheel
  481. * @apioption series.dependencywheel
  482. */
  483. /**
  484. * A collection of options for the individual nodes. The nodes in a dependency
  485. * diagram are auto-generated instances of `Highcharts.Point`, but options can
  486. * be applied here and linked by the `id`.
  487. *
  488. * @extends series.sankey.nodes
  489. * @type {Array<*>}
  490. * @product highcharts
  491. * @excluding offset
  492. * @apioption series.dependencywheel.nodes
  493. */
  494. /**
  495. * An array of data points for the series. For the `dependencywheel` series
  496. * type, points can be given in the following way:
  497. *
  498. * An array of objects with named values. The following snippet shows only a
  499. * few settings, see the complete options set below. If the total number of data
  500. * points exceeds the series' [turboThreshold](#series.area.turboThreshold),
  501. * this option is not available.
  502. *
  503. * ```js
  504. * data: [{
  505. * from: 'Category1',
  506. * to: 'Category2',
  507. * weight: 2
  508. * }, {
  509. * from: 'Category1',
  510. * to: 'Category3',
  511. * weight: 5
  512. * }]
  513. * ```
  514. *
  515. * @type {Array<*>}
  516. * @extends series.sankey.data
  517. * @product highcharts
  518. * @excluding outgoing, dataLabels
  519. * @apioption series.dependencywheel.data
  520. */
  521. /**
  522. * Individual data label for each node. The options are the same as
  523. * the ones for [series.dependencywheel.dataLabels](#series.dependencywheel.dataLabels).
  524. *
  525. * @apioption series.dependencywheel.nodes.dataLabels
  526. */
  527. ''; // adds doclets above to the transpiled file
  528. return DependencyWheelSeries;
  529. });
  530. _registerModule(_modules, 'masters/modules/dependency-wheel.src.js', [], function () {
  531. });
  532. }));