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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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; };
  6. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7. var _react = require('react');
  8. var _react2 = _interopRequireDefault(_react);
  9. var _xyPlot = require('../plot/xy-plot');
  10. var _xyPlot2 = _interopRequireDefault(_xyPlot);
  11. var _polygonSeries = require('../plot/series/polygon-series');
  12. var _polygonSeries2 = _interopRequireDefault(_polygonSeries);
  13. var _markSeries = require('../plot/series/mark-series');
  14. var _markSeries2 = _interopRequireDefault(_markSeries);
  15. var _labelSeries = require('../plot/series/label-series');
  16. var _labelSeries2 = _interopRequireDefault(_labelSeries);
  17. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  18. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  20. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Copyright (c) 2016 - 2017 Uber Technologies, Inc.
  21. //
  22. // Permission is hereby granted, free of charge, to any person obtaining a copy
  23. // of this software and associated documentation files (the "Software"), to deal
  24. // in the Software without restriction, including without limitation the rights
  25. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  26. // copies of the Software, and to permit persons to whom the Software is
  27. // furnished to do so, subject to the following conditions:
  28. //
  29. // The above copyright notice and this permission notice shall be included in
  30. // all copies or substantial portions of the Software.
  31. //
  32. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  33. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  35. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  36. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  37. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  38. // THE SOFTWARE.
  39. var MARGIN_ADJUST = 1.2;
  40. var TreemapSVG = function (_React$Component) {
  41. _inherits(TreemapSVG, _React$Component);
  42. function TreemapSVG() {
  43. _classCallCheck(this, TreemapSVG);
  44. return _possibleConstructorReturn(this, (TreemapSVG.__proto__ || Object.getPrototypeOf(TreemapSVG)).apply(this, arguments));
  45. }
  46. _createClass(TreemapSVG, [{
  47. key: 'getCircularNodes',
  48. value: function getCircularNodes() {
  49. var _props = this.props,
  50. animation = _props.animation,
  51. hideRootNode = _props.hideRootNode,
  52. nodes = _props.nodes,
  53. onLeafMouseOver = _props.onLeafMouseOver,
  54. onLeafMouseOut = _props.onLeafMouseOut,
  55. onLeafClick = _props.onLeafClick,
  56. scales = _props.scales,
  57. style = _props.style;
  58. var _nodes$reduce = nodes.reduce(function (acc, node, index) {
  59. if (!index && hideRootNode) {
  60. return acc;
  61. }
  62. var x = node.x,
  63. y = node.y,
  64. r = node.r;
  65. return {
  66. maxY: Math.max(y + r, acc.maxY),
  67. minY: Math.min(y - r, acc.minY),
  68. maxX: Math.max(x + MARGIN_ADJUST * r, acc.maxX),
  69. minX: Math.min(x - MARGIN_ADJUST * r, acc.minX),
  70. rows: acc.rows.concat([{
  71. x: x,
  72. y: y,
  73. size: r,
  74. color: scales.color(node)
  75. }])
  76. };
  77. }, {
  78. rows: [],
  79. maxY: -Infinity,
  80. minY: Infinity,
  81. maxX: -Infinity,
  82. minX: Infinity
  83. }),
  84. rows = _nodes$reduce.rows,
  85. minY = _nodes$reduce.minY,
  86. maxY = _nodes$reduce.maxY,
  87. minX = _nodes$reduce.minX,
  88. maxX = _nodes$reduce.maxX;
  89. return {
  90. updatedNodes: _react2.default.createElement(_markSeries2.default, {
  91. animation: animation,
  92. className: 'rv-treemap__leaf rv-treemap__leaf--circle',
  93. onSeriesMouseEnter: onLeafMouseOver,
  94. onSeriesMouseLeave: onLeafMouseOut,
  95. onSeriesClick: onLeafClick,
  96. data: rows,
  97. colorType: 'literal',
  98. getColor: function getColor(d) {
  99. return d.color;
  100. },
  101. sizeType: 'literal',
  102. getSize: function getSize(d) {
  103. return d.size;
  104. },
  105. style: style
  106. }),
  107. minY: minY,
  108. maxY: maxY,
  109. minX: minX,
  110. maxX: maxX
  111. };
  112. }
  113. }, {
  114. key: 'getNonCircularNodes',
  115. value: function getNonCircularNodes() {
  116. var _props2 = this.props,
  117. animation = _props2.animation,
  118. hideRootNode = _props2.hideRootNode,
  119. nodes = _props2.nodes,
  120. onLeafMouseOver = _props2.onLeafMouseOver,
  121. onLeafMouseOut = _props2.onLeafMouseOut,
  122. onLeafClick = _props2.onLeafClick,
  123. scales = _props2.scales,
  124. style = _props2.style;
  125. var color = scales.color;
  126. return nodes.reduce(function (acc, node, index) {
  127. if (!index && hideRootNode) {
  128. return acc;
  129. }
  130. var x0 = node.x0,
  131. x1 = node.x1,
  132. y1 = node.y1,
  133. y0 = node.y0;
  134. var x = x0;
  135. var y = y0;
  136. var nodeHeight = y1 - y0;
  137. var nodeWidth = x1 - x0;
  138. acc.maxY = Math.max(y + nodeHeight, acc.maxY);
  139. acc.minY = Math.min(y, acc.minY);
  140. acc.maxX = Math.max(x + nodeWidth, acc.maxX);
  141. acc.minX = Math.min(x, acc.minX);
  142. var data = [{ x: x, y: y }, { x: x, y: y + nodeHeight }, { x: x + nodeWidth, y: y + nodeHeight }, { x: x + nodeWidth, y: y }];
  143. acc.updatedNodes = acc.updatedNodes.concat([_react2.default.createElement(_polygonSeries2.default, {
  144. animation: animation,
  145. className: 'rv-treemap__leaf',
  146. key: index,
  147. color: color(node),
  148. type: 'literal',
  149. onSeriesMouseEnter: onLeafMouseOver,
  150. onSeriesMouseLeave: onLeafMouseOut,
  151. onSeriesClick: onLeafClick,
  152. data: data,
  153. style: _extends({}, style, node.style)
  154. })]);
  155. return acc;
  156. }, {
  157. updatedNodes: [],
  158. maxY: -Infinity,
  159. minY: Infinity,
  160. maxX: -Infinity,
  161. minX: Infinity
  162. });
  163. }
  164. }, {
  165. key: 'render',
  166. value: function render() {
  167. var _props3 = this.props,
  168. className = _props3.className,
  169. height = _props3.height,
  170. mode = _props3.mode,
  171. nodes = _props3.nodes,
  172. width = _props3.width;
  173. var useCirclePacking = mode === 'circlePack';
  174. var _ref = useCirclePacking ? this.getCircularNodes() : this.getNonCircularNodes(),
  175. minY = _ref.minY,
  176. maxY = _ref.maxY,
  177. minX = _ref.minX,
  178. maxX = _ref.maxX,
  179. updatedNodes = _ref.updatedNodes;
  180. var labels = nodes.reduce(function (acc, node) {
  181. if (!node.data.title) {
  182. return acc;
  183. }
  184. return acc.concat(_extends({}, node.data, {
  185. x: node.x0 || node.x,
  186. y: node.y0 || node.y,
  187. label: '' + node.data.title
  188. }));
  189. }, []);
  190. return _react2.default.createElement(
  191. _xyPlot2.default,
  192. _extends({
  193. className: 'rv-treemap ' + (useCirclePacking ? 'rv-treemap-circle-packed' : '') + ' ' + className,
  194. width: width,
  195. height: height,
  196. yDomain: [maxY, minY],
  197. xDomain: [minX, maxX],
  198. colorType: 'literal',
  199. hasTreeStructure: true
  200. }, this.props),
  201. updatedNodes,
  202. _react2.default.createElement(_labelSeries2.default, { data: labels })
  203. );
  204. }
  205. }]);
  206. return TreemapSVG;
  207. }(_react2.default.Component);
  208. TreemapSVG.displayName = 'TreemapSVG';
  209. exports.default = TreemapSVG;