'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _group = require('@vx/group');

var _hierarchy = require('@vx/hierarchy');

var _d3Hierarchy = require('d3-hierarchy');

var _mockData = require('@vx/mock-data');

var _scale = require('@vx/scale');

var _d3Interpolate = require('d3-interpolate');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _jsxFileName = '/Users/hshoff/code/vx/packages/vx-demo/components/tiles/treemap.js';

exports.default = function (_ref) {
  var width = _ref.width,
      height = _ref.height,
      _ref$events = _ref.events,
      events = _ref$events === undefined ? false : _ref$events,
      _ref$margin = _ref.margin,
      margin = _ref$margin === undefined ? {
    top: 0,
    left: 30,
    right: 40,
    bottom: 80
  } : _ref$margin;

  if (width < 10) return null;
  var color = (0, _scale.scaleLinear)({
    domain: [0, Math.max.apply(Math, (0, _toConsumableArray3.default)(_mockData.shakespeare.map(function (d) {
      return d.size || 0;
    })))],
    range: ['#0373d9', '#00ff70']
  });
  var nodes = (0, _d3Hierarchy.stratify)().id(function (d) {
    return d.id;
  }).parentId(function (d) {
    return d.parent;
  })(_mockData.shakespeare).sum(function (d) {
    return d.size || 0;
  });
  var data = (0, _d3Hierarchy.hierarchy)(nodes).sort(function (a, b) {
    return b.value - a.value;
  });
  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 31
    }
  }, _react2.default.createElement('rect', { width: width, height: height, rx: 14, fill: '#3436b8', __source: {
      fileName: _jsxFileName,
      lineNumber: 32
    }
  }), _react2.default.createElement(_hierarchy.Treemap, {
    top: margin.top,
    root: data,
    size: [width, height - margin.top - margin.bottom],
    tile: _d3Hierarchy.treemapSquarify,
    round: true,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 33
    }
  }, function (_ref2) {
    var data = _ref2.data;

    return _react2.default.createElement(_group.Group, {
      __source: {
        fileName: _jsxFileName,
        lineNumber: 42
      }
    }, data.descendants().reverse().map(function (node, i) {
      return _react2.default.createElement(_group.Group, {
        top: node.y0,
        left: node.x0,
        key: 'node-' + i,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 47
        }
      }, node.depth == 1 && _react2.default.createElement('rect', {
        id: 'rect-' + i,
        width: node.x1 - node.x0,
        height: node.y1 - node.y0,
        fill: 'transparent',
        stroke: '#3436b8',
        strokeWidth: 4,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 53
        }
      }), node.depth > 2 && _react2.default.createElement('rect', {
        id: 'rect-' + i,
        width: node.x1 - node.x0,
        height: node.y1 - node.y0,
        fill: color(node.value),
        stroke: '#3436b8',
        __source: {
          fileName: _jsxFileName,
          lineNumber: 63
        }
      }));
    }));
  }));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvdHJlZW1hcC5qcyJdLCJuYW1lcyI6WyJSZWFjdCIsIkdyb3VwIiwiVHJlZW1hcCIsImhpZXJhcmNoeSIsInN0cmF0aWZ5Iiwic2hha2VzcGVhcmUiLCJ0cmVlbWFwU3F1YXJpZnkiLCJzY2FsZUxpbmVhciIsImludGVycG9sYXRlUmdiIiwid2lkdGgiLCJoZWlnaHQiLCJldmVudHMiLCJtYXJnaW4iLCJ0b3AiLCJsZWZ0IiwicmlnaHQiLCJib3R0b20iLCJjb2xvciIsImRvbWFpbiIsIk1hdGgiLCJtYXgiLCJtYXAiLCJkIiwic2l6ZSIsInJhbmdlIiwibm9kZXMiLCJpZCIsInBhcmVudElkIiwicGFyZW50Iiwic3VtIiwiZGF0YSIsInNvcnQiLCJhIiwiYiIsInZhbHVlIiwiZGVzY2VuZGFudHMiLCJyZXZlcnNlIiwibm9kZSIsImkiLCJ5MCIsIngwIiwiZGVwdGgiLCJ4MSIsInkxIl0sIm1hcHBpbmdzIj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