var SMALL_TYPE = 'small';
var LARGE_TYPE = 'large';
var SMALL_SIZE = 16;
var DEFAULT_SIZE = 24;
var LARGE_SIZE = 70;
var LARGE_STROKE_WIDTH = 5;
var CIRCLE_DEG = 360;
/**
 * svg 尺寸
 * @param size
 * @returns {{width: number, height: number}}
 */

export function getWrapBounds(size) {
  var width = DEFAULT_SIZE;
  var height = DEFAULT_SIZE;

  switch (size) {
    case SMALL_TYPE:
      width = SMALL_SIZE;
      height = SMALL_SIZE;
      break;

    case LARGE_TYPE:
      width = LARGE_SIZE;
      height = LARGE_SIZE;
      break;

    default:
  }

  return {
    width: width,
    height: height
  };
}
/**
 * 圆弧属性
 */

export function getPathAttr(radius, data, total) {
  var strokeWidth = getStrokeWidth(radius);
  var realRadius = radius - strokeWidth;
  var start = 0;
  return data.map(function (_ref) {
    var value = _ref.value,
        stroke = _ref.stroke,
        name = _ref.name;
    var rate = getRate(value, total);
    var end = start + rate;
    var d = getDirection(radius, radius, realRadius, start, end);
    start = end;
    return {
      name: name,
      strokeWidth: strokeWidth,
      stroke: stroke,
      d: d
    };
  });
}
/**
 * 计算 path 路径
 * @param x
 * @param y
 * @param radius
 * @param startAngle
 * @param endAngle
 * @returns {string}
 */

export function getDirection(x, y, radius, startAngle, endAngle) {
  var start = polarToCartesian(x, y, radius, endAngle);
  var end = polarToCartesian(x, y, radius, startAngle);
  var largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';
  return "M ".concat(start.x, " ").concat(start.y, " A ").concat(radius, " ").concat(radius, ", 0 ").concat(largeArcFlag, ", 0, ").concat(end.x, " ").concat(end.y);
}
export function getStrokeWidth(radius) {
  return radius < DEFAULT_SIZE ? Math.floor(radius * 0.3) : LARGE_STROKE_WIDTH;
}
export function arraySum(arr) {
  var init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  return arr.reduce(function (accu, curr) {
    return accu + curr;
  }, init);
}
/**
 * 获取圆弧端点
 * @param centerX
 * @param centerY
 * @param radius
 * @param angleInDegrees
 * @returns {{x: *, y: *}}
 */

function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
  var angleInRadians = (angleInDegrees - 90) * Math.PI / 180;
  return {
    x: centerX + radius * Math.cos(angleInRadians),
    y: centerY + radius * Math.sin(angleInRadians)
  };
}
/**
 * 圆弧所对的圆心角
 * @param current
 * @param total
 * @returns {number}
 */


function getRate(current, total) {
  return current / total * CIRCLE_DEG;
}