'use strict';

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

var _stringify = require('babel-runtime/core-js/json/stringify');

var _stringify2 = _interopRequireDefault(_stringify);

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

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

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

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

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

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

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


var data = _mockData.cityTemperature.slice(0, 4);
var keys = (0, _keys2.default)(data[0]).filter(function (d) {
  return d !== 'date';
});
var parseDate = (0, _d3TimeFormat.timeParse)('%Y%m%d');
var format = (0, _d3TimeFormat.timeFormat)('%b %d');
var formatDate = function formatDate(date) {
  return format(parseDate(date));
};

// accessors
var y0 = function y0(d) {
  return d.date;
};
var x = function x(d) {
  return d.value;
};

exports.default = function (_ref) {
  var width = _ref.width,
      height = _ref.height,
      _ref$events = _ref.events,
      events = _ref$events === undefined ? false : _ref$events,
      _ref$margin = _ref.margin,
      margin = _ref$margin === undefined ? {
    top: 20,
    left: 50,
    right: 10,
    bottom: 0
  } : _ref$margin;

  if (width < 10) return null;

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

  // // scales
  var y0Scale = (0, _scale.scaleBand)({
    rangeRound: [0, yMax],
    domain: data.map(y0),
    padding: 0.2,
    tickFormat: function tickFormat() {
      return function (val) {
        return formatDate(val);
      };
    }
  });

  var y1Scale = (0, _scale.scaleBand)({
    rangeRound: [0, y0Scale.bandwidth()],
    domain: keys,
    padding: 0.1
  });

  var xScale = (0, _scale.scaleLinear)({
    rangeRound: [xMax, 0],
    domain: [0, (0, _d3Array.max)(data, function (d) {
      return (0, _d3Array.max)(keys, function (key) {
        return d[key];
      });
    })]
  });

  var zScale = (0, _scale.scaleOrdinal)({
    domain: keys,
    range: ['#aeeef8', '#e5fd3d', '#9caff6']
  });

  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 67
    }
  }, _react2.default.createElement('rect', { x: 0, y: 0, width: width, height: height, fill: '#612efb', rx: 14, __source: {
      fileName: _jsxFileName,
      lineNumber: 68
    }
  }), _react2.default.createElement(_group.Group, { top: margin.top, left: margin.left, __source: {
      fileName: _jsxFileName,
      lineNumber: 69
    }
  }, _react2.default.createElement(_shape.BarGroupHorizontal, {
    data: data,
    keys: keys,
    width: xMax,
    y0: y0,
    y0Scale: y0Scale,
    y1Scale: y1Scale,
    xScale: xScale,
    zScale: zScale,
    rx: 4,
    onClick: function onClick(data) {
      return function (event) {
        if (!events) return;
        alert('clicked: ' + (0, _stringify2.default)(data));
      };
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 70
    }
  }), _react2.default.createElement(_axis.AxisLeft, {
    scale: y0Scale,
    stroke: '#e5fd3d',
    tickStroke: '#e5fd3d',
    hideAxisLine: true,
    tickLabelProps: function tickLabelProps(value, index) {
      return {
        fill: '#e5fd3d',
        fontSize: 11,
        textAnchor: 'end',
        dy: '0.33em'
      };
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 85
    }
  })));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvYmFyZ3JvdXBob3Jpem9udGFsLmpzIl0sIm5hbWVzIjpbIlJlYWN0IiwiQmFyR3JvdXBIb3Jpem9udGFsIiwiR3JvdXAiLCJBeGlzTGVmdCIsImNpdHlUZW1wZXJhdHVyZSIsInNjYWxlQmFuZCIsInNjYWxlTGluZWFyIiwic2NhbGVPcmRpbmFsIiwidGltZVBhcnNlIiwidGltZUZvcm1hdCIsImV4dGVudCIsIm1heCIsImRhdGEiLCJzbGljZSI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