'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

var _scale = require('@vx/scale');

var _curve = require('@vx/curve');

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

var _d3Array = require('d3-array');

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/lineradial.js';


var x = function x(d) {
  return new Date(d.date);
};
var y = function y(d) {
  return d.close;
};

var capPoints = [_mockData.appleStock[0]].concat([_mockData.appleStock[_mockData.appleStock.length - 1]]);

function LineRadialTile(_ref) {
  var width = _ref.width,
      height = _ref.height,
      _ref$margin = _ref.margin,
      margin = _ref$margin === undefined ? {
    top: 10,
    left: 10,
    right: 10,
    bottom: 120
  } : _ref$margin;

  if (width < 10) return null;

  var radius = Math.min(width, height) / 2;

  var xScale = (0, _scale.scaleTime)({
    range: [0, Math.PI * 2],
    domain: (0, _d3Array.extent)(_mockData.appleStock, x)
  });
  var yScale = (0, _scale.scaleLog)({
    range: [0, height / 2 - 20],
    domain: (0, _d3Array.extent)(_mockData.appleStock, y)
  });
  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 40
    }
  }, _react2.default.createElement(_gradient.LinearGradient, {
    from: '#e5fd3d',
    to: '#aeeef8',
    id: 'line-gradient',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 41
    }
  }), _react2.default.createElement('rect', {
    x: 0,
    y: 0,
    width: width,
    height: height,
    fill: '#744cca',
    rx: 14,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 46
    }
  }), _react2.default.createElement(_group.Group, { top: height / 2, left: width / 2, __source: {
      fileName: _jsxFileName,
      lineNumber: 54
    }
  }, yScale.ticks().map(function (tick, i) {
    return _react2.default.createElement('g', { key: 'radial-grid-' + i, __source: {
        fileName: _jsxFileName,
        lineNumber: 57
      }
    }, _react2.default.createElement('circle', {
      r: yScale(tick),
      stroke: '#aeeef8',
      strokeWidth: 1,
      fill: '#aeeef8',
      fillOpacity: 1 / (i + 1) - 1 / i * 0.2,
      strokeOpacity: 0.2,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 58
      }
    }), _react2.default.createElement('text', {
      y: -yScale(tick),
      textAnchor: 'middle',
      dy: '-.33em',
      fontSize: 8,
      fill: '#aeeef8',
      fillOpacity: 0.6,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 66
      }
    }, tick));
  }), _react2.default.createElement(_shape.LineRadial, {
    data: _mockData.appleStock,
    angle: function angle(d) {
      return xScale(x(d));
    },
    radius: function radius(d) {
      return yScale(y(d));
    },
    fill: 'none',
    stroke: "url('#line-gradient')",
    strokeWidth: 2,
    strokeOpacity: 0.8,
    curve: _curve.curveBasisOpen,
    strokeLinecap: 'round',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 79
    }
  }), capPoints.map(function (d, i) {
    return _react2.default.createElement('circle', {
      key: 'line-cap-' + i,
      cy: -yScale(y(d)),
      cx: xScale(x(d)) * Math.PI / 180,
      r: 3,
      fill: '#dff84d',
      __source: {
        fileName: _jsxFileName,
        lineNumber: 92
      }
    });
  })));
}