tiling.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * DevExtreme (viz/tree_map/tiling.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _isFunction = require("../../core/utils/type").isFunction;
  11. var _normalizeEnum = require("../core/utils").normalizeEnum;
  12. var _round = Math.round;
  13. var algorithms = {};
  14. var defaultAlgorithm;
  15. exports.getAlgorithm = function(value) {
  16. return algorithms[_normalizeEnum(value)] || _isFunction(value) && value || defaultAlgorithm
  17. };
  18. exports.addAlgorithm = function(name, callback) {
  19. algorithms[name] = callback
  20. };
  21. exports.setDefaultAlgorithm = function(name) {
  22. defaultAlgorithm = algorithms[name]
  23. };
  24. var directionToIndexOffsets = {};
  25. directionToIndexOffsets[-1] = [2, 0];
  26. directionToIndexOffsets[1] = [0, 2];
  27. var getStaticSideIndex = function(rect) {
  28. return rect[2] - rect[0] < rect[3] - rect[1] ? 0 : 1
  29. };
  30. exports.getStaticSideIndex = getStaticSideIndex;
  31. exports.buildSidesData = function(rect, directions, _staticSideIndex) {
  32. var staticSideIndex = void 0 !== _staticSideIndex ? _staticSideIndex : getStaticSideIndex(rect);
  33. var variedSideIndex = 1 - staticSideIndex;
  34. var staticSideDirection = directions[staticSideIndex];
  35. var variedSideDirection = directions[variedSideIndex];
  36. var staticSideIndexOffsets = directionToIndexOffsets[staticSideDirection];
  37. var variedSideIndexOffsets = directionToIndexOffsets[variedSideDirection];
  38. return {
  39. staticSide: rect[2 + staticSideIndex] - rect[staticSideIndex],
  40. variedSide: rect[2 + variedSideIndex] - rect[variedSideIndex],
  41. static1: staticSideIndex + staticSideIndexOffsets[0],
  42. static2: staticSideIndex + staticSideIndexOffsets[1],
  43. varied1: variedSideIndex + variedSideIndexOffsets[0],
  44. varied2: variedSideIndex + variedSideIndexOffsets[1],
  45. staticDir: staticSideDirection,
  46. variedDir: variedSideDirection
  47. }
  48. };
  49. exports.calculateRectangles = function(nodes, head, totalRect, sidesData, rowData) {
  50. var i;
  51. var ii;
  52. var variedSidePart = [0, 0, 0, 0];
  53. var static1 = sidesData.static1;
  54. var static2 = sidesData.static2;
  55. var position = totalRect[static1];
  56. var dir = sidesData.staticDir;
  57. var side = sidesData.staticSide;
  58. var sum = rowData.sum;
  59. var rect;
  60. var delta;
  61. variedSidePart[sidesData.varied1] = totalRect[sidesData.varied1];
  62. variedSidePart[sidesData.varied2] = totalRect[sidesData.varied1] + sidesData.variedDir * rowData.side;
  63. for (i = head, ii = head + rowData.count; i < ii; ++i) {
  64. rect = variedSidePart.slice();
  65. rect[static1] = position;
  66. delta = _round(side * nodes[i].value / sum) || 0;
  67. sum -= nodes[i].value;
  68. side -= delta;
  69. position += dir * delta;
  70. rect[static2] = position;
  71. nodes[i].rect = rect
  72. }
  73. totalRect[sidesData.varied1] = variedSidePart[sidesData.varied2]
  74. };