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

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

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

var _heatmap = require('@vx/heatmap');

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


var data = (0, _mockData.genBins)(16, 16);

// accessors
var x = function x(d) {
  return d.bin;
};
var y = function y(d) {
  return d.bins;
};
var z = function z(d) {
  return d.count;
};

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: 10,
    left: 20,
    right: 20,
    bottom: 110
  } : _ref$margin,
      _ref$separation = _ref.separation,
      separation = _ref$separation === undefined ? 20 : _ref$separation;

  if (width < 10) return null;

  // bounds
  var size = width > margin.left + margin.right ? width - margin.left - margin.right - separation : width;
  var xMax = size / 2;
  var yMax = height - margin.bottom - margin.top;
  var maxBucketSize = (0, _d3Array.max)(data, function (d) {
    return y(d).length;
  });
  var bWidth = xMax / data.length;
  var bHeight = yMax / maxBucketSize;
  var colorMax = (0, _d3Array.max)(data, function (d) {
    return (0, _d3Array.max)(y(d), z);
  });

  // scales
  var xScale = (0, _scale.scaleLinear)({
    range: [0, xMax],
    domain: [0, data.length]
  });
  var yScale = (0, _scale.scaleLinear)({
    range: [yMax, 0],
    domain: [0, maxBucketSize]
  });
  var colorScale = (0, _scale.scaleLinear)({
    range: ['#77312f', '#f33d15'],
    domain: [0, colorMax]
  });
  var colorScale2 = (0, _scale.scaleLinear)({
    range: ['#122549', '#b4fbde'],
    domain: [0, colorMax]
  });
  var opacityScale = (0, _scale.scaleLinear)({
    range: [0.1, 1],
    domain: [0, colorMax]
  });

  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 62
    }
  }, _react2.default.createElement('rect', { x: 0, y: 0, width: width, height: height, rx: 14, fill: '#28272c', __source: {
      fileName: _jsxFileName,
      lineNumber: 63
    }
  }), _react2.default.createElement(_group.Group, { top: margin.top, left: margin.left, __source: {
      fileName: _jsxFileName,
      lineNumber: 64
    }
  }, _react2.default.createElement(_heatmap.HeatmapCircle, {
    data: data,
    xScale: xScale,
    yScale: yScale,
    colorScale: colorScale,
    opacityScale: opacityScale,
    radius: (0, _d3Array.min)([bWidth, bHeight]) / 2,
    gap: 2,
    onClick: function onClick(data) {
      return function (event) {
        if (!events) return;
        alert('clicked: ' + (0, _stringify2.default)(data.bin));
      };
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 65
    }
  })), _react2.default.createElement(_group.Group, { top: margin.top, left: xMax + margin.left + separation, __source: {
      fileName: _jsxFileName,
      lineNumber: 79
    }
  }, _react2.default.createElement(_heatmap.HeatmapRect, {
    data: data,
    xScale: xScale,
    yScale: yScale,
    colorScale: colorScale2,
    opacityScale: opacityScale,
    binWidth: bWidth,
    binHeight: bWidth,
    gap: 2,
    onClick: function onClick(data) {
      return function (event) {
        if (!events) return;
        alert('clicked: ' + (0, _stringify2.default)(data.bin));
      };
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 80
    }
  })));
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvdGlsZXMvaGVhdG1hcC5qcyJdLCJuYW1lcyI6WyJSZWFjdCIsIkdyb3VwIiwiZ2VuQmlucyIsInNjYWxlQmFuZCIsInNjYWxlTGluZWFyIiwiSGVhdG1hcENpcmNsZSIsIkhlYXRtYXBSZWN0IiwiZXh0ZW50IiwibWluIiwibWF4IiwiZGF0YSIsIngiLCJkIiwiYmluIiwieSIsImJpbnMiLCJ6I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