'use strict';

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

var _stringify = require('babel-runtime/core-js/json/stringify');

var _stringify2 = _interopRequireDefault(_stringify);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

var _shape = require('@vx/shape');

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

var _gradient = require('@vx/gradient');

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

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


var raw = {
  name: '$',
  children: [{
    name: 'A',
    children: [{ name: 'A1' }, { name: 'A2' }, {
      name: 'C',
      children: [{
        name: 'C1'
      }]
    }]
  }, {
    name: 'B',
    children: [{ name: 'B1' }, { name: 'B2' }, { name: 'B3' }]
  }, {
    name: 'X',
    children: [{
      name: 'Z'
    }]
  }]
};

function Node(_ref) {
  var node = _ref.node,
      events = _ref.events;

  var width = 40;
  var height = 20;
  return _react2.default.createElement(_group.Group, { top: node.y, left: node.x, __source: {
      fileName: _jsxFileName,
      lineNumber: 45
    }
  }, node.depth === 0 && _react2.default.createElement('rect', { width: width, height: height, y: -height / 2, x: -width / 2, fill: 'url(\'#top\')', __source: {
      fileName: _jsxFileName,
      lineNumber: 47
    }
  }), node.depth !== 0 && _react2.default.createElement('circle', {
    r: 12,
    fill: '#306c90',
    stroke: node.children ? 'white' : '#ddf163',
    onClick: function onClick() {
      if (!events) return;
      alert('clicked: ' + (0, _stringify2.default)(node.data.name));
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 50
    }
  }), _react2.default.createElement('text', {
    dy: '.33em',
    fontSize: 9,
    fontFamily: 'Arial',
    textAnchor: 'middle',
    style: { pointerEvents: 'none' },
    fill: node.depth === 0 ? '#286875' : node.children ? 'white' : '#ddf163',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 60
    }
  }, node.data.name));
}

function Link(_ref2) {
  var link = _ref2.link;

  return _react2.default.createElement(_shape.LinkVertical, { data: link, stroke: '#f7f7f3', strokeWidth: '1', strokeOpacity: 0.2, fill: 'none', __source: {
      fileName: _jsxFileName,
      lineNumber: 76
    }
  });
}

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

  if (width < 10) return null;
  var data = (0, _d3Hierarchy.hierarchy)(raw);
  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 94
    }
  }, _react2.default.createElement(_gradient.LinearGradient, { id: 'top', from: '#79d259', to: '#37ac8c', __source: {
      fileName: _jsxFileName,
      lineNumber: 95
    }
  }), _react2.default.createElement('rect', { width: width, height: height, rx: 14, fill: '#306c90', __source: {
      fileName: _jsxFileName,
      lineNumber: 96
    }
  }), _react2.default.createElement(_hierarchy.Cluster, {
    top: margin.top,
    left: margin.left,
    root: data,
    size: [width - margin.left - margin.right, height - margin.top - margin.bottom],
    nodeComponent: function nodeComponent(_ref4) {
      var node = _ref4.node;
      return _react2.default.createElement(Node, { node: node, events: events, __source: {
          fileName: _jsxFileName,
          lineNumber: 102
        }
      });
    },
    linkComponent: Link,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 97
    }
  }));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvZGVuZHJvZ3JhbS5qcyJdLCJuYW1lcyI6WyJSZWFjdCIsIkdyb3VwIiwiQ2x1c3RlciIsIkxpbmtWZXJ0aWNhbCIsImhpZXJhcmNoeSIsIkxpbmVhckdyYWRpZW50IiwicmF3IiwibmFtZSIsImNoaWxkcmVuIiwiTm9kZSIsIm5vZGUiLCJldmVudHMiLCJ3aWR0aCIsImhlaWdodCIsInkiLCJ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