import { useMemo } from 'react';
import { scaleLinear } from 'd3-scale';
import { line as d3Line, curveCatmullRom } from 'd3-shape';
import { SOLID_PARTY_VALUE } from './constants';
export default function useChartScales(area, range) {
  const {
    width,
    height,
    padding
  } = area;
  return useMemo(() => {
    const x = scaleLinear().domain([range.x.min, range.x.max]).range([0, width]);
    const y = scaleLinear().domain([range.y.max, range.y.min]).range([height, 0]);
    const yInner = scaleLinear().domain([range.y.max, range.y.min]).range([height - padding.bottom - padding.top, padding.top]);
    const color = scaleLinear().domain([SOLID_PARTY_VALUE * -1, SOLID_PARTY_VALUE]).range(['#3571C0', '#FE5C40']).clamp(true);
    const fade = scaleLinear().domain([range.y.penultimate, range.y.max]).range([0, 1]);
    const colorBinary = value => value === 'gop' ? '#FE5C40' : '#3571C0';
    const line = d3Line().x(d => x(d.value)).y(d => yInner(d.year)).curve(curveCatmullRom.alpha(0.1));
    return {
      x,
      y,
      yInner,
      color,
      colorBinary,
      fade,
      line
    };
  }, [width, height, padding]);
}