<commit_before>import scale from 'd3-scale';
import { colorScale as colors, parameterMax, unusedColor } from '../utils/map-settings';

console.log(scale)

/**
* Generate the color scale based on domain and range
* @param {array} Array of data values
* @param {number} Max value to clamp upper range to
* @return {function} d3 scale function
*/

// PREVIOUS CODE for the inputs for genereateColorStops
// generateColorStops (latestStore.storage.hasGeo[this.state.selectedParameter], parameterMax[this.state.selectedParameter])
export function generateColorStops (parameter) {
  const colorScale = generateColorScale(parameterMax[parameter]);

  let stops = colors.map((c) => {
    return [colorScale.invertExtent(c)[0], c];
  });

  // And add one stop to the beginning to account for interpolation
  stops.unshift([-1, unusedColor]);

  return stops;
}

export function generateColorScale (parameterMax) {
  // From older version of functioning color scale
  // if (!data || !Array.isArray(data)) {
  //   return;
  // }

  // let max = d3Max(data, (d) => {
  //   return (d.convertedValue !== undefined) ? d.convertedValue : d.properties.convertedValue;
  // });

  // max = Math.min(max, parameterMax);

  // Clamp to max value for the parameter

  const colorScale = scale.quantize().domain([0, parameterMax]).range(colors);

  return colorScale;
}<commit_msg>Fix d3 import.<commit_after>var d3 = require('d3');
import { colorScale as colors, parameterMax, unusedColor } from '../utils/map-settings';

/**
* Generate the color scale based on domain and range
* @param {array} Array of data values
* @param {number} Max value to clamp upper range to
* @return {function} d3 scale function
*/

// PREVIOUS CODE for the inputs for genereateColorStops
// generateColorStops (latestStore.storage.hasGeo[this.state.selectedParameter], parameterMax[this.state.selectedParameter])
export function generateColorStops (parameter) {
  const colorScale = generateColorScale(parameterMax[parameter]);

  let stops = colors.map((c) => {
    return [colorScale.invertExtent(c)[0], c];
  });

  // And add one stop to the beginning to account for interpolation
  stops.unshift([-1, unusedColor]);

  return stops;
}

export function generateColorScale (parameterMax) {
  // From older version of functioning color scale
  // if (!data || !Array.isArray(data)) {
  //   return;
  // }

  // let max = d3Max(data, (d) => {
  //   return (d.convertedValue !== undefined) ? d.convertedValue : d.properties.convertedValue;
  // });

  // max = Math.min(max, parameterMax);

  // Clamp to max value for the parameter

  const colorScale = d3.scaleQuantize().domain([0, parameterMax]).range(colors);

  return colorScale;
}
{'fraction_non_alphanumeric': 0.13022567517573067, 'fraction_numerical': 0.005549389567147614, 'mean_word_length': 4.082706766917293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506990', 'n_tokens_mistral': 814, 'n_tokens_neox': 788, 'n_words': 240}