'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.xScaleLinear = xScaleLinear;
exports.xScaleTime = xScaleTime;
exports.xScaleBand = xScaleBand;
exports.yScaleLinear = yScaleLinear;
exports.xScaleLinearDataList = xScaleLinearDataList;
exports.yScaleLinearDataList = yScaleLinearDataList;
exports.xScaleTimeList = xScaleTimeList;

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

var array = _interopRequireWildcard(_d3Array);

var _d3Axis = require('d3-axis');

var axis = _interopRequireWildcard(_d3Axis);

var _d3Format = require('d3-format');

var format = _interopRequireWildcard(_d3Format);

var _d3Scale = require('d3-scale');

var scale = _interopRequireWildcard(_d3Scale);

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

var shape = _interopRequireWildcard(_d3Shape);

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

var timeFormat = _interopRequireWildcard(_d3TimeFormat);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var d3 = Object.assign({}, shape, format, axis, array, scale, timeFormat);
function getMax(data, axisType) {
  return d3.max(data, function (d) {
    return d[axisType];
  });
}

function getMin(data, axisType) {
  return d3.min(data, function (d) {
    return d[axisType];
  });
}

function xScaleLinear(data, width) {
  return d3.scaleLinear().domain([0, getMax(data, 'x')]).range([0, width]);
}

function xScaleTime(data, width) {
  return d3.scaleTime().domain(d3.extent(data, function (d) {
    return d.x;
  })).rangeRound([0, width]);
}

function xScaleBand(data, width, paddingPercent) {
  return d3.scaleBand().domain(data.map(function (d) {
    return d.x;
  })).rangeRound([0, width]).padding(paddingPercent);
}

function yScaleLinear(data, height, yBuffer) {
  return d3.scaleLinear().domain([0, getMax(data, 'y') + yBuffer]).range([height, 0]);
}

function getMaxFromList(dataList, axisType) {
  return d3.max(dataList.map(function (data) {
    return getMax(data, axisType);
  }));
}

function getMinFromList(dataList, axisType) {
  return d3.min(dataList.map(function (data) {
    return getMin(data, axisType);
  }));
}
function xScaleLinearDataList(dataList, width) {
  return d3.scaleLinear().domain([0, getMaxFromList(dataList, 'x')]).range([0, width]);
}

function yScaleLinearDataList(dataList, width) {
  return d3.scaleLinear().domain([getMinFromList(dataList, 'y'), getMaxFromList(dataList, 'y')]).range([0, width]);
}
function xScaleTimeList(dataList, width) {
  return d3.scaleTime().domain(getMinFromList(dataList, 'x'), getMaxFromList(dataList, 'y')).rangeRound([0, width]);
}
//# sourceMappingURL=utils.js.map