Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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