Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

125 righe
4.5 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. 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.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. var _react = require('react');
  25. var _react2 = _interopRequireDefault(_react);
  26. var _propTypes = require('prop-types');
  27. var _propTypes2 = _interopRequireDefault(_propTypes);
  28. var _animation = require('../animation');
  29. var _animation2 = _interopRequireDefault(_animation);
  30. var _scalesUtils = require('../utils/scales-utils');
  31. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  32. var ANIMATED_PROPS = ['colorRange', 'colorDomain', 'color', 'opacityRange', 'opacityDomain', 'opacity', 'x0', 'x1', 'y0', 'y1', 'r'];
  33. function TreemapLeaf(props) {
  34. var animation = props.animation,
  35. getLabel = props.getLabel,
  36. mode = props.mode,
  37. node = props.node,
  38. onLeafClick = props.onLeafClick,
  39. onLeafMouseOver = props.onLeafMouseOver,
  40. onLeafMouseOut = props.onLeafMouseOut,
  41. r = props.r,
  42. scales = props.scales,
  43. x0 = props.x0,
  44. x1 = props.x1,
  45. y0 = props.y0,
  46. y1 = props.y1,
  47. style = props.style;
  48. if (animation) {
  49. return _react2.default.createElement(
  50. _animation2.default,
  51. _extends({}, props, { animatedProps: ANIMATED_PROPS }),
  52. _react2.default.createElement(TreemapLeaf, _extends({}, props, { animation: null }))
  53. );
  54. }
  55. var useCirclePacking = mode === 'circlePack';
  56. var background = scales.color(node);
  57. var opacity = scales.opacity(node);
  58. var color = (0, _scalesUtils.getFontColorFromBackground)(background);
  59. var data = node.data;
  60. var title = getLabel(data);
  61. var leafStyle = _extends({
  62. top: useCirclePacking ? y0 - r : y0,
  63. left: useCirclePacking ? x0 - r : x0,
  64. width: useCirclePacking ? r * 2 : x1 - x0,
  65. height: useCirclePacking ? r * 2 : y1 - y0,
  66. background: background,
  67. opacity: opacity,
  68. color: color
  69. }, style, node.data.style);
  70. return _react2.default.createElement(
  71. 'div',
  72. {
  73. className: 'rv-treemap__leaf ' + (useCirclePacking ? 'rv-treemap__leaf--circle' : ''),
  74. onMouseEnter: function onMouseEnter(event) {
  75. return onLeafMouseOver(node, event);
  76. },
  77. onMouseLeave: function onMouseLeave(event) {
  78. return onLeafMouseOut(node, event);
  79. },
  80. onClick: function onClick(event) {
  81. return onLeafClick(node, event);
  82. },
  83. style: leafStyle
  84. },
  85. _react2.default.createElement(
  86. 'div',
  87. { className: 'rv-treemap__leaf__content' },
  88. title
  89. )
  90. );
  91. }
  92. TreemapLeaf.propTypes = {
  93. animation: _animation.AnimationPropType,
  94. height: _propTypes2.default.number.isRequired,
  95. mode: _propTypes2.default.string,
  96. node: _propTypes2.default.object.isRequired,
  97. onLeafClick: _propTypes2.default.func,
  98. onLeafMouseOver: _propTypes2.default.func,
  99. onLeafMouseOut: _propTypes2.default.func,
  100. scales: _propTypes2.default.object.isRequired,
  101. width: _propTypes2.default.number.isRequired,
  102. r: _propTypes2.default.number.isRequired,
  103. x0: _propTypes2.default.number.isRequired,
  104. x1: _propTypes2.default.number.isRequired,
  105. y0: _propTypes2.default.number.isRequired,
  106. y1: _propTypes2.default.number.isRequired
  107. };
  108. exports.default = TreemapLeaf;