TreemapAlgorithmGroup.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* *
  2. *
  3. * (c) 2014-2021 Highsoft AS
  4. *
  5. * Authors: Jon Arild Nygard / Oystein Moseng
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. /* *
  14. *
  15. * Class
  16. *
  17. * */
  18. var TreemapAlgorithmGroup = /** @class */ (function () {
  19. /* *
  20. *
  21. * Constructor
  22. *
  23. * */
  24. function TreemapAlgorithmGroup(h, w, d, p) {
  25. this.height = h;
  26. this.width = w;
  27. this.plot = p;
  28. this.direction = d;
  29. this.startDirection = d;
  30. this.total = 0;
  31. this.nW = 0;
  32. this.lW = 0;
  33. this.nH = 0;
  34. this.lH = 0;
  35. this.elArr = [];
  36. this.lP = {
  37. total: 0,
  38. lH: 0,
  39. nH: 0,
  40. lW: 0,
  41. nW: 0,
  42. nR: 0,
  43. lR: 0,
  44. aspectRatio: function (w, h) {
  45. return Math.max((w / h), (h / w));
  46. }
  47. };
  48. }
  49. /* *
  50. *
  51. * Functions
  52. *
  53. * */
  54. /* eslint-disable valid-jsdoc */
  55. TreemapAlgorithmGroup.prototype.addElement = function (el) {
  56. this.lP.total = this.elArr[this.elArr.length - 1];
  57. this.total = this.total + el;
  58. if (this.direction === 0) {
  59. // Calculate last point old aspect ratio
  60. this.lW = this.nW;
  61. this.lP.lH = this.lP.total / this.lW;
  62. this.lP.lR = this.lP.aspectRatio(this.lW, this.lP.lH);
  63. // Calculate last point new aspect ratio
  64. this.nW = this.total / this.height;
  65. this.lP.nH = this.lP.total / this.nW;
  66. this.lP.nR = this.lP.aspectRatio(this.nW, this.lP.nH);
  67. }
  68. else {
  69. // Calculate last point old aspect ratio
  70. this.lH = this.nH;
  71. this.lP.lW = this.lP.total / this.lH;
  72. this.lP.lR = this.lP.aspectRatio(this.lP.lW, this.lH);
  73. // Calculate last point new aspect ratio
  74. this.nH = this.total / this.width;
  75. this.lP.nW = this.lP.total / this.nH;
  76. this.lP.nR = this.lP.aspectRatio(this.lP.nW, this.nH);
  77. }
  78. this.elArr.push(el);
  79. };
  80. TreemapAlgorithmGroup.prototype.reset = function () {
  81. this.nW = 0;
  82. this.lW = 0;
  83. this.elArr = [];
  84. this.total = 0;
  85. };
  86. return TreemapAlgorithmGroup;
  87. }());
  88. /* *
  89. *
  90. * Default Export
  91. *
  92. * */
  93. export default TreemapAlgorithmGroup;