You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

104 lines
3.9 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.DEFAULT_MARGINS = exports.MarginPropType = undefined;
  6. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Copyright (c) 2016 - 2017 Uber Technologies, Inc.
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. exports.getInnerDimensions = getInnerDimensions;
  26. exports.getRadialLayoutMargin = getRadialLayoutMargin;
  27. var _propTypes = require('prop-types');
  28. var _propTypes2 = _interopRequireDefault(_propTypes);
  29. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30. /**
  31. * Get the dimensions of the component for the future use.
  32. * @param {Object} props Props.
  33. * @param {Object} defaultMargins Object with default margins.
  34. * @returns {Object} Dimensions of the component.
  35. */
  36. function getInnerDimensions(props, defaultMargins) {
  37. var margin = props.margin,
  38. width = props.width,
  39. height = props.height;
  40. var marginProps = _extends({}, defaultMargins, typeof margin === 'number' ? {
  41. left: margin,
  42. right: margin,
  43. top: margin,
  44. bottom: margin
  45. } : margin);
  46. var _marginProps$left = marginProps.left,
  47. marginLeft = _marginProps$left === undefined ? 0 : _marginProps$left,
  48. _marginProps$top = marginProps.top,
  49. marginTop = _marginProps$top === undefined ? 0 : _marginProps$top,
  50. _marginProps$right = marginProps.right,
  51. marginRight = _marginProps$right === undefined ? 0 : _marginProps$right,
  52. _marginProps$bottom = marginProps.bottom,
  53. marginBottom = _marginProps$bottom === undefined ? 0 : _marginProps$bottom;
  54. return {
  55. marginLeft: marginLeft,
  56. marginTop: marginTop,
  57. marginRight: marginRight,
  58. marginBottom: marginBottom,
  59. innerHeight: height - marginBottom - marginTop,
  60. innerWidth: width - marginLeft - marginRight
  61. };
  62. }
  63. /**
  64. * Calculate the margin of the sunburst,
  65. * so it can be at the center of the container
  66. * @param {Number} width - the width of the container
  67. * @param {Number} height - the height of the container
  68. * @param {Number} radius - the max radius of the sunburst
  69. * @return {Object} an object includes {bottom, left, right, top}
  70. */
  71. function getRadialLayoutMargin(width, height, radius) {
  72. var marginX = width / 2 - radius;
  73. var marginY = height / 2 - radius;
  74. return {
  75. bottom: marginY,
  76. left: marginX,
  77. right: marginX,
  78. top: marginY
  79. };
  80. }
  81. var MarginPropType = exports.MarginPropType = _propTypes2.default.oneOfType([_propTypes2.default.shape({
  82. left: _propTypes2.default.number,
  83. top: _propTypes2.default.number,
  84. right: _propTypes2.default.number,
  85. bottom: _propTypes2.default.number
  86. }), _propTypes2.default.number]);
  87. var DEFAULT_MARGINS = exports.DEFAULT_MARGINS = {
  88. left: 40,
  89. right: 10,
  90. top: 10,
  91. bottom: 40
  92. };