'use strict';

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

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');

var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

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

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

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

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


var letters = _mockData.letterFrequency.slice(0, 4);
var browsers = (0, _keys2.default)(_mockData.browserUsage[0]).filter(function (k) {
  return k !== "date";
}).map(function (k) {
  return { label: k, usage: _mockData.browserUsage[0][k] };
});

function Label(_ref) {
  var x = _ref.x,
      y = _ref.y,
      children = _ref.children;

  return _react2.default.createElement('text', {
    fill: 'white',
    textAnchor: 'middle',
    x: x,
    y: y,
    dy: '.33em',
    fontSize: 9,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 14
    }
  }, children);
}

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

  if (width < 10) return null;
  var radius = Math.min(width, height) / 2;
  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 41
    }
  }, _react2.default.createElement(_gradient.GradientPinkBlue, { id: 'gradients', __source: {
      fileName: _jsxFileName,
      lineNumber: 42
    }
  }), _react2.default.createElement('rect', {
    x: 0,
    y: 0,
    rx: 14,
    width: width,
    height: height,
    fill: 'url(\'#gradients\')',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 43
    }
  }), _react2.default.createElement(_group.Group, { top: height / 2 - margin.top, left: width / 2, __source: {
      fileName: _jsxFileName,
      lineNumber: 51
    }
  }, _react2.default.createElement(_shape.Arc, {
    data: browsers,
    pieValue: function pieValue(d) {
      return d.usage;
    },
    outerRadius: radius - 80,
    innerRadius: radius - 120,
    fill: 'white',
    fillOpacity: function fillOpacity(d) {
      return 1 / (d.index + 2);
    },
    cornerRadius: 3,
    padAngle: 0,
    centroid: function centroid(_centroid2, arc) {
      var _centroid = (0, _slicedToArray3.default)(_centroid2, 2),
          x = _centroid[0],
          y = _centroid[1];

      var startAngle = arc.startAngle,
          endAngle = arc.endAngle;

      if (endAngle - startAngle < .1) return null;
      return _react2.default.createElement(Label, { x: x, y: y, __source: {
          fileName: _jsxFileName,
          lineNumber: 65
        }
      }, arc.data.label);
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 52
    }
  }), _react2.default.createElement(_shape.Arc, {
    data: letters,
    pieValue: function pieValue(d) {
      return d.frequency;
    },
    outerRadius: radius - 135,
    fill: 'black',
    fillOpacity: function fillOpacity(d) {
      return 1 / (d.index + 2);
    },
    centroid: function centroid(_centroid4, arc) {
      var _centroid3 = (0, _slicedToArray3.default)(_centroid4, 2),
          x = _centroid3[0],
          y = _centroid3[1];

      return _react2.default.createElement(Label, { x: x, y: y, __source: {
          fileName: _jsxFileName,
          lineNumber: 76
        }
      }, arc.data.letter);
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 68
    }
  })));
};