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

  if (width < 10) return null;

  // bounds
  var size = width > margin.left + margin.right ? width - margin.left - margin.right : width;
  var xMax = size / 2;
  var yMax = height - margin.bottom;
  var dMin = (0, _d3Array.min)(data, function (d) {
    return (0, _d3Array.min)(y(d), x);
  });
  var dMax = (0, _d3Array.max)(data, function (d) {
    return (0, _d3Array.max)(y(d), x);
  });
  var dStep = dMax / data[0].bins.length;
  var bWidth = xMax / data.length;
  var bHeight = yMax / data[0].bins.length;
  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, _d3Array.extent)(data, x)
  });
  var yScale = (0, _scale.scaleLinear)({
    range: [yMax, 0],
    domain: [dMin, dMax]
  });
  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: [.1, 1],
    domain: [0, colorMax]
  });

  return _react2.default.createElement('svg', { width: width, height: height, __source: {
      fileName: _jsxFileName,
      lineNumber: 64
    }
  }, _react2.default.createElement('rect', {
    x: 0,
    y: 0,
    width: width,
    height: height,
    rx: 14,
    fill: '#28272c',
    __source: {
      fileName: _jsxFileName,
      lineNumber: 65
    }
  }), _react2.default.createElement(_group.Group, { top: margin.top, left: 5, __source: {
      fileName: _jsxFileName,
      lineNumber: 73
    }
  }, _react2.default.createElement(_heatmap.HeatmapCircle, {
    data: data,
    xScale: xScale,
    yScale: yScale,
    colorScale: colorScale,
    opacityScale: opacityScale,
    radius: (bWidth + 4) / 2,
    step: dStep,
    gap: 4,
    onClick: function onClick(data) {
      return function (event) {
        if (!events) return;
        alert('clicked: ' + (0, _stringify2.default)(data.bin));
      };
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 74
    }
  })), _react2.default.createElement(_group.Group, { top: margin.top, left: xMax + margin.left, __source: {
      fileName: _jsxFileName,
      lineNumber: 89
    }
  }, _react2.default.createElement(_heatmap.HeatmapRect, {
    data: data,
    xScale: xScale,
    yScale: yScale,
    colorScale: colorScale2,
    opacityScale: opacityScale,
    binWidth: bWidth,
    binHeight: bWidth,
    step: dStep,
    gap: 0,
    onClick: function onClick(data) {
      return function (event) {
        if (!events) return;
        alert('clicked: ' + (0, _stringify2.default)(data.bin));
      };
    },
    __source: {
      fileName: _jsxFileName,
      lineNumber: 90
    }
  })));
};