'use strict';

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

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

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 _gradient = require('@vx/gradient');

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

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

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

var _d3TimeFormat = require('d3-time-format');

var _d3Shape = require('d3-shape');

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

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


var data = _mockData.browserUsage;
var keys = (0, _keys2.default)(data[0]).filter(function (k) {
  return k !== 'date';
});
var browserNames = [].concat((0, _toConsumableArray3.default)(keys)).reverse();
var parseDate = (0, _d3TimeFormat.timeParse)("%Y %b %d");
var _x = function _x(d) {
  return parseDate(d.date);
};
var stack = (0, _d3Shape.stack)().keys(keys);

exports.default = function (_ref) {
  var width = _ref.width,
      height = _ref.height,
      margin = _ref.margin;

  if (width < 10) return null;

  // bounds
  var yMax = height - margin.top - margin.bottom;
  var xMax = width - margin.left - margin.right;

  // scales
  var xScale = (0, _scale.scaleTime)({
    range: [0, xMax],
    domain: (0, _d3Array.extent)(data, _x)
  });
  var yScale = (0, _scale.scaleLinear)({
    range: [yMax, 0]
  });

  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 38
    }
  }, _react2.default.createElement(_gradient.GradientOrangeRed, { id: 'OrangeRed', __source: {
      fileName: _jsxFileName,
      lineNumber: 39
    }
  }), _react2.default.createElement('rect', {
    x: 0,
    y: 0,
    width: width,
    height: height,
    fill: '#f38181',
    rx: 14,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 40
    }
  }), _react2.default.createElement(_shape.AreaStack, {
    reverse: true,
    top: margin.top,
    left: margin.left,
    keys: keys,
    data: data,
    x: function x(d) {
      return xScale(_x(d.data));
    },
    y0: function y0(d) {
      return yScale(d[0] / 100);
    },
    y1: function y1(d) {
      return yScale(d[1] / 100);
    },
    strokeWidth: 0,
    fill: 'url(#OrangeRed)',
    fillOpacity: '1',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 48
    }
  }));
};