'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/pie.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.Pie, {
    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 < 0.1) return null;
      return _react2.default.createElement(Label, { x: x, y: y, __source: {
          fileName: _jsxFileName,
          lineNumber: 66
        }
      }, arc.data.label);
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 52
    }
  }), _react2.default.createElement(_shape.Pie, {
    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: 81
        }
      }, arc.data.letter);
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 72
    }
  })));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvcGllLmpzIl0sIm5hbWVzIjpbIlJlYWN0IiwiUGllIiwiR3JvdXAiLCJHcmFkaWVudFBpbmtCbHVlIiwibGV0dGVyRnJlcXVlbmN5IiwiYnJvd3NlclVzYWdlIiwibGV0dGVycyIsInNsaWNlIiwiYnJvd3NlcnMiLCJmaWx0ZXIiLCJrIiwibWFwIiwibGFiZWwiLCJ1c2FnZSIs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