1import * as d3 from 'd3';
2import * as d3ScaleChromatic from 'd3-scale-chromatic';
3
4export function getColorScale(colorScheme: any, lightTheme: boolean, maxValue: number, minValue = 0): (d: any) => any {
5  //@ts-ignore
6  const colorInterpolator = d3ScaleChromatic[colorScheme.value];
7  const colorScaleInverted = colorScheme.invert === 'always' || colorScheme.invert === (lightTheme ? 'light' : 'dark');
8
9  const start = colorScaleInverted ? maxValue : minValue;
10  const end = colorScaleInverted ? minValue : maxValue;
11
12  return d3.scaleSequential(colorInterpolator).domain([start, end]);
13}
14
15export function getOpacityScale(
16  options: { cardColor?: null; colorScale?: any; exponent?: any },
17  maxValue: number,
18  minValue = 0
19): any {
20  let legendOpacityScale;
21  if (options.colorScale === 'linear') {
22    legendOpacityScale = d3.scaleLinear().domain([minValue, maxValue]).range([0, 1]);
23  } else if (options.colorScale === 'sqrt') {
24    legendOpacityScale = d3.scalePow().exponent(options.exponent).domain([minValue, maxValue]).range([0, 1]);
25  }
26  return legendOpacityScale;
27}
28