{"size": 1750, "ext": "js", "max_stars_repo_path": "src/components/report/visualization/specificity/data/get-data.js", "max_stars_repo_name": "knightjdr/covid-site", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/report/visualization/specificity/data/get-data.js", "max_issues_repo_name": "knightjdr/covid-site", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/report/visualization/specificity/data/get-data.js", "max_forks_repo_name": "knightjdr/covid-site", "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": 26.1194029851, "max_line_length": 111, "alphanum_fraction": 0.6211428571}
import defineAxis from '../../data/define-axis';
import defineMidline from '../../data/define-midline';
import filterPreys from '../../data/filter-preys';
import getDimensions from '../../data/get-dimensions';
import scaleData from '../../data/scale-data';

const convertSpecificityToNumber = (preys) => {
  const max = preys.reduce((accum, prey) => (
    prey.y !== 'Infinity' && prey.y > accum ? prey.y : accum
  ), 0);
  return preys.map((prey) => {
    if (prey.y === 'Infinity') {
      return {
        ...prey,
        highlight: true,
        y: max,
      };
    }
    return {
      ...prey,
    };
  });
};

const getData = (preys, ref, options) => {
  if (!ref.current || !options.condition) {
    return {};
  }
  const dimensions = getDimensions(ref);

  const filterOptions = {
    ...options,
    xCondition: options.condition,
    xMetric: 'count',
    yCondition: options.condition,
    yMetric: 'specificity',
  };
  let filteredPreys = filterPreys(preys, filterOptions);
  filteredPreys = convertSpecificityToNumber(filteredPreys);

  const ticks = {
    x: defineAxis(filteredPreys, { log: options.log, scale: options.scale, vertex: 'x' }),
    y: defineAxis(filteredPreys, { log: options.log, scale: options.scale, vertex: 'y' }),
  };

  const scaledData = scaleData(filteredPreys, ticks, { ...dimensions, log: options.log });

  const midline = options.midline ? defineMidline(scaledData.ticks, dimensions.axisLength, options.log) : null;

  return {
    ...dimensions,
    log: options.log,
    midline,
    points: scaledData.points,
    x: {
      label: 'spectral count',
      ticks: scaledData.ticks.x,
    },
    y: {
      label: 'specificity',
      ticks: scaledData.ticks.y,
    },
  };
};

export default getData;
