{"size": 1460, "ext": "js", "max_stars_repo_path": "src/elements/bubble/transforms.js", "max_stars_repo_name": "slightly-askew/portfolio-2017", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/elements/bubble/transforms.js", "max_issues_repo_name": "slightly-askew/portfolio-2017", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/elements/bubble/transforms.js", "max_forks_repo_name": "slightly-askew/portfolio-2017", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.3333333333, "max_line_length": 76, "alphanum_fraction": 0.645890411}
//@flow

//types

type coordinates = {
  "x": number,
  "y": number
};
type Axis = "x" | "y";

//switches the coordinates of the axis
export const morph = (coordinates: coordinates): coordinates => ({
  x: coordinates["y"],
  y: coordinates["x"]
});

export const flip = (dimensions: coordinates) => (...axis: Array<Axis>) => (
  coordinates: coordinates
): coordinates => {
  const flipCoordinate = axis => dimensions[axis] - coordinates[axis];

  const newCoords = axis.reduce((obj, key): any => {
    obj[key] = flipCoordinate(key);
    return obj;
  }, {});

  return Object.assign({}, coordinates, newCoords);
};

export const flipPosition = (
  svgDimensions: coordinates,
  selfDimensions: coordinates
) => (...axis: Array<Axis>) => (coordinates: coordinates): coordinates => {
  const flipPosition = axis => {
    return svgDimensions[axis] - coordinates[axis] - selfDimensions[axis];
  };

  const flippedPositions = axis.reduce((obj, key): any => {
    obj[key] = flipPosition(key);
    return obj;
  }, {});

  return Object.assign({}, coordinates, flippedPositions);
};

export const offsetPath = (
  pathOffsets: coordinates,
  thresholds: coordinates = { x: 0, y: 0 }
) => (coordinates: coordinates): coordinates => {
  const offsetCoordinate = axis =>
    coordinates[axis] > thresholds[axis]
      ? coordinates[axis] + pathOffsets[axis]
      : coordinates[axis];

  return {
    x: offsetCoordinate("x"),
    y: offsetCoordinate("y")
  };
};
