<commit_before>import _ from 'lodash';
import { getNiceTickValues, getTickValuesFixedDomain } from 'recharts-scale';
import * as d3Scales from 'd3-scale';
import {
  stack as shapeStack, stackOrderNone, stackOffsetExpand,
  stackOffsetNone, stackOffsetSilhouette, stackOffsetWiggle,
} from 'd3-shape';
import { isNumOrStr, uniqueId, isNumber, getPercentValue, mathSign, findEntryInArray } from './DataUtils';
import ReferenceDot from '../cartesian/ReferenceDot';
import ReferenceLine from '../cartesian/ReferenceLine';
import ReferenceArea from '../cartesian/ReferenceArea';
import ErrorBar from '../cartesian/ErrorBar';
import Legend from '../component/Legend';
import { findAllByType, findChildByType, getDisplayName } from './ReactUtils';

export const getValueByDataKey = (obj, dataKey, defaultValue) => {
  if (_.isNil(obj) || _.isNil(dataKey)) { return defaultValue; }

  if (isNumOrStr(dataKey)) { return _.get(obj, dataKey, defaultValue); }

  if (_.isFunction(dataKey)) { return dataKey(obj); }

  return defaultValue;
};
/**
 * Get domain of data by key
 * @param  {Array}   data      The data displayed in the chart
 * @param  {String}  key       The unique key of a group of data
 * @param  {String}  type      The type of axis
 * @param  {Boolean} filterNil Whether or not filter nil values
 * @return {Array} Domain of data
 */
export const getDomainOfDataByKey = (data, key, type, filterNil) => {
  const flattenData = _.flatMap(data, entry => getValueByDataKey(entry, key));

  if (type === 'number') {
    const domain = flattenData.filter(isNumber);

    return [Math.min.apply(null, domain), Math.max.apply(null, domain)];
  }

  const validateData = filterNil ?
    flattenData.filter(entry => !_.isNil(entry)) :
    flattenData;

  return validateData.map(entry => (isNumOrStr(entry) ? entry : ''));
};

export const calculateActiveTickIndex = (coordinate, ticks, unsortedTicks, axis) => {
  let index = -1;
  const len = ticks.length;

  if (len > 1) {
    if (axis && axis.axisType === 'angleAxis' &&
      Math.abs(Math.abs(axis.range[1] - axis.range[0]) - 360) <= 1e-6) {
      const { range } = axis;
      // ticks are distributed in a circle
      for (let i = 0; i < len; i++) {
        const before = i > 0 ? unsortedTicks[i - 1].coordinate : unsortedTicks[len - 1].coordinate;
        const cur = unsortedTicks[i].coordinate;
        const after = i >= len - 1 ? unsortedTicks[0].coordinate : unsortedTicks[i + 1].coordinate;
        let sameDirectionCoord;

        if (mathSign(cur - before) !== mathSign(after - cur)) {
          const diffInterval = [];
          if (mathSign(after - cur) === mathSign(range[1] - range[0])) {<commit_msg>fix: fix axis type error (#1501)<commit_after>import _ from 'lodash';
import { getNiceTickValues, getTickValuesFixedDomain } from 'recharts-scale';
import * as d3Scales from 'd3-scale';
import {
  stack as shapeStack, stackOrderNone, stackOffsetExpand,
  stackOffsetNone, stackOffsetSilhouette, stackOffsetWiggle,
} from 'd3-shape';
import { isNumOrStr, uniqueId, isNumber, getPercentValue, mathSign, findEntryInArray } from './DataUtils';
import ReferenceDot from '../cartesian/ReferenceDot';
import ReferenceLine from '../cartesian/ReferenceLine';
import ReferenceArea from '../cartesian/ReferenceArea';
import ErrorBar from '../cartesian/ErrorBar';
import Legend from '../component/Legend';
import { findAllByType, findChildByType, getDisplayName } from './ReactUtils';

export const getValueByDataKey = (obj, dataKey, defaultValue) => {
  if (_.isNil(obj) || _.isNil(dataKey)) { return defaultValue; }

  if (isNumOrStr(dataKey)) { return _.get(obj, dataKey, defaultValue); }

  if (_.isFunction(dataKey)) { return dataKey(obj); }

  return defaultValue;
};
/**
 * Get domain of data by key
 * @param  {Array}   data      The data displayed in the chart
 * @param  {String}  key       The unique key of a group of data
 * @param  {String}  type      The type of axis
 * @param  {Boolean} filterNil Whether or not filter nil values
 * @return {Array} Domain of data
 */
export const getDomainOfDataByKey = (data, key, type, filterNil) => {
  const flattenData = _.flatMap(data, entry => getValueByDataKey(entry, key));

  if (type === 'number') {
    const domain = flattenData.filter(entry => (isNumber(entry) ? entry : parseFloat(entry, 10)));

    return [Math.min.apply(null, domain), Math.max.apply(null, domain)];
  }

  const validateData = filterNil ?
    flattenData.filter(entry => !_.isNil(entry)) :
    flattenData;

  return validateData.map(entry => (isNumOrStr(entry) ? entry : ''));
};

export const calculateActiveTickIndex = (coordinate, ticks, unsortedTicks, axis) => {
  let index = -1;
  const len = ticks.length;

  if (len > 1) {
    if (axis && axis.axisType === 'angleAxis' &&
      Math.abs(Math.abs(axis.range[1] - axis.range[0]) - 360) <= 1e-6) {
      const { range } = axis;
      // ticks are distributed in a circle
      for (let i = 0; i < len; i++) {
        const before = i > 0 ? unsortedTicks[i - 1].coordinate : unsortedTicks[len - 1].coordinate;
        const cur = unsortedTicks[i].coordinate;
        const after = i >= len - 1 ? unsortedTicks[0].coordinate : unsortedTicks[i + 1].coordinate;
        let sameDirectionCoord;

        if (mathSign(cur - before) !== mathSign(after - cur)) {
          const diffInterval = [];
          if (mathSign(after - cur) === mathSign(range[1] - range[0])) {
{'fraction_non_alphanumeric': 0.13721144967682364, 'fraction_numerical': 0.00886426592797784, 'mean_word_length': 3.7301310043668123, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, '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': '3478018', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1659, 'n_words': 481}