'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

var _clipPath = require('@vx/clip-path');

var _voronoi = require('@vx/voronoi');

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

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

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

  if (width < 10) return _react2.default.createElement('div', {
    __source: {
      fileName: _jsxFileName,
      lineNumber: 18
    }
  });
  var innerWidth = width - margin.left - margin.right;
  var innerHeight = height - margin.top - margin.bottom;

  var data = Array(150).fill(null).map(function () {
    return {
      x: Math.random() * innerWidth,
      y: Math.random() * innerHeight,
      id: Math.random().toString(36).slice(2)
    };
  });

  var voronoiLayout = (0, _voronoi.voronoi)({
    x: function x(d) {
      return d.x;
    },
    y: function y(d) {
      return d.y;
    },
    width: innerWidth,
    height: innerHeight
  });

  var polygons = voronoiLayout.polygons(data);

  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 38
    }
  }, _react2.default.createElement(_gradient.GradientOrangeRed, { id: 'voronoi_orange_red', __source: {
      fileName: _jsxFileName,
      lineNumber: 39
    }
  }), _react2.default.createElement(_gradient.GradientPinkRed, { id: 'voronoi_pink_red', __source: {
      fileName: _jsxFileName,
      lineNumber: 40
    }
  }), _react2.default.createElement(_clipPath.RectClipPath, {
    id: 'voronoi_clip',
    width: innerWidth,
    height: innerHeight,
    rx: 14,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 41
    }
  }), _react2.default.createElement(_group.Group, {
    top: margin.top,
    left: margin.left,
    clipPath: 'url(#voronoi_clip)',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 47
    }
  }, polygons.map(function (polygon) {
    return _react2.default.createElement(_voronoi.VoronoiPolygon, {
      key: 'polygon-' + polygon.data.id,
      polygon: polygon,
      fill: function fill(d) {
        return d.id.toLowerCase() <= 'a' ? 'url(#voronoi_orange_red)' : 'url(#voronoi_pink_red)';
      },
      stroke: '#fff',
      strokeWidth: 1,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 53
      }
    });
  }), data.map(function (d) {
    return _react2.default.createElement('circle', {
      key: 'circle-' + d.id,
      r: 2,
      cx: d.x,
      cy: d.y,
      fill: '#ffffff',
      fillOpacity: 0.2,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 65
      }
    });
  })));
};