'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: 34
    }
  }, _react2.default.createElement(_gradient.GradientPinkBlue, { id: 'gradients', __source: {
      fileName: _jsxFileName,
      lineNumber: 35
    }
  }), _react2.default.createElement('rect', { x: 0, y: 0, rx: 14, width: width, height: height, fill: 'url(\'#gradients\')', __source: {
      fileName: _jsxFileName,
      lineNumber: 36
    }
  }), _react2.default.createElement(_group.Group, { top: height / 2 - margin.top, left: width / 2, __source: {
      fileName: _jsxFileName,
      lineNumber: 37
    }
  }, _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: 52
        }
      }, arc.data.label);
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 38
    }
  }), _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: 67
        }
      }, arc.data.letter);
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 58
    }
  })));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvcGllLmpzIl0sIm5hbWVzIjpbIlJlYWN0IiwiUGllIiwiR3JvdXAiLCJHcmFkaWVudFBpbmtCbHVlIiwibGV0dGVyRnJlcXVlbmN5IiwiYnJvd3NlclVzYWdlIiwibGV0dGVycyIsInNsaWNlIiwiYnJvd3NlcnMiLCJmaWx0ZXIiLCJrIiwibWFwIiwibGFiZWwiLCJ1c2FnZSIsIkxhYmVsIiwieCIsInkiLCJjaGlsZH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