'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: 32
    }
  }, _react2.default.createElement('rect', { width: width, height: height, rx: 14, fill: '#3436b8', __source: {
      fileName: _jsxFileName,
      lineNumber: 33
    }
  }), _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: 34
    }
  }, function (_ref2) {
    var data = _ref2.data;

    return _react2.default.createElement(_group.Group, {
      __source: {
        fileName: _jsxFileName,
        lineNumber: 43
      }
    }, 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: 48
        }
      }, 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: 50
        }
      }), 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: 60
        }
      }));
    }));
  }));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvdHJlZW1hcC5qcyJdLCJuYW1lcyI6WyJSZWFjdCIsIkdyb3VwIiwiVHJlZW1hcCIsImhpZXJhcmNoeSIsInN0cmF0aWZ5Iiwic2hha2VzcGVhcmUiLCJ0cmVlbWFwU3F1YXJpZnkiLCJzY2FsZUxpbmVhciIsImludGVycG9sYXRlUmdiIiwid2lkdGgiLCJoZWlnaHQiLCJldmVudHMiLCJtYXJnaW4iLCJ0b3AiLCJsZWZ0IiwicmlnaHQiLCJib3R0b20iLCJjb2xvciIsImRvbWFpbiIsIk1hdGgiLCJtYXgiLCJtYXAiLCJkIiwic2l6ZSIsInJhbmdlIiwibm9kZXMiLCJpZCIsInBhcmVudElkIiwicGFyZW50Iiwic3VtIiwiZGF0YSIsInNvcnQiLCJhIiwiYiIsInZhbHVlIiwiZGVzY2VuZGFudHMiLCJyZXZlcnNlIiwibm9kZSIsImkiLCJ5MCIsIngwIiwiZGVwdGgiLCJ4MSIsInkxIl0sIm1hcHBpbmdzIjoiOzs7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