'use strict';

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

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

var _stringify2 = _interopRequireDefault(_stringify);

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');

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

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


var data = _mockData.letterFrequency.slice(5);

function round(value, precision) {
  var multiplier = Math.pow(10, precision || 0);
  return Math.round(value * multiplier) / multiplier;
}

// accessors
var x = function x(d) {
  return d.letter;
};
var y = function y(d) {
  return +d.frequency * 100;
};

exports.default = function (_ref) {
  var width = _ref.width,
      height = _ref.height,
      _ref$events = _ref.events,
      events = _ref$events === undefined ? false : _ref$events;

  if (width < 10) return null;

  // bounds
  var xMax = width;
  var yMax = height - 120;

  // scales
  var xScale = (0, _scale.scaleBand)({
    rangeRound: [0, xMax],
    domain: data.map(x),
    padding: 0.4
  });
  var yScale = (0, _scale.scaleLinear)({
    rangeRound: [yMax, 0],
    domain: [0, (0, _d3Array.max)(data, y)]
  });

  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 39
    }
  }, _react2.default.createElement(_gradient.GradientTealBlue, { id: 'teal', __source: {
      fileName: _jsxFileName,
      lineNumber: 40
    }
  }), _react2.default.createElement('rect', { x: 0, y: 0, width: width, height: height, fill: 'url(#teal)', rx: 14, __source: {
      fileName: _jsxFileName,
      lineNumber: 41
    }
  }), _react2.default.createElement(_group.Group, { top: 40, __source: {
      fileName: _jsxFileName,
      lineNumber: 42
    }
  }, data.map(function (d, i) {
    var barHeight = yMax - yScale(y(d));
    return _react2.default.createElement(_group.Group, { key: 'bar-' + x(d), __source: {
        fileName: _jsxFileName,
        lineNumber: 46
      }
    }, _react2.default.createElement(_shape.Bar, {
      width: xScale.bandwidth(),
      height: barHeight,
      x: xScale(x(d)),
      y: yMax - barHeight,
      fill: 'rgba(23, 233, 217, .5)',
      data: { x: x(d), y: y(d) },
      onClick: function onClick(data) {
        return function (event) {
          if (!events) return;
          alert('clicked: ' + (0, _stringify2.default)(data));
        };
      },
      __source: {
        fileName: _jsxFileName,
        lineNumber: 47
      }
    }));
  })));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvYmFycy5qcyJdLCJuYW1lcyI6WyJSZWFjdCIsIkJhciIsIkdyb3VwIiwiR3JhZGllbnRUZWFsQmx1ZSIsImxldHRlckZyZXF1ZW5jeSIsInNjYWxlQmFuZCIsInNjYWxlTGluZWFyIiwiZXh0ZW50IiwibWF4IiwiZGF0YSIsInNsaWNlIiwicm91bmQiLCJ2YWx1ZSIsInByZWNpc2lvbiIsIm11bHRpcGxpZXIiLCJNYXRoIiwicG93IiwieCIsImQiLCJsZXR0ZXIiLCJ5IiwiZnJlcXVlbmN5Iiwid2lkdGgiLCJoZWlnaHQiLCJldmVudHMiLCJ4TWF4IiwieU1heCIsInhTY2FsZSIsInJhbmdlUm91bmQiLCJkb21haW4iLCJtYXAiLCJwYWRkaW5nIiwieVNjYWxlIiwiaSIsImJhckhlaWdodCIsImJhbmR3aWR0aCIsImFsZXJ0Il0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsQUFBTzs7OztBQUNQLEFBQVM7O0FBQ1QsQUFBUzs7QUFDVCxBQUFTOztBQUNULEFBQVM7O0FBQ1QsQUFBUyxBQUFXOztBQUNwQixBQUFTLEFBQVE7Ozs7Ozs7QUFFakIsSUFBTSxPQUFPLDBCQUFBLEFBQWdCLE1BQTdCLEFBQWEsQUFBc0I7O0FBRW5DLFNBQUEsQUFBUyxNQUFULEFBQWUsT0FBZixBQUFzQixXQUFXLEFBQy9CO01B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