<commit_before>import * as _ from '@antv/util';
import { ShapeDrawCFG, ShapePoint } from '../../interface';
import { padEnd } from '../../util/helper';
import { doAnimate } from '../animate';
import Element from '../element';
import { registerShape, registerShapeFactory } from './base';

function sortValue(value) {
  const array = !_.isArray(value) ? [value] : value;
  // 从大到小排序
  const sorted = array.sort((a, b) => b - a);
  return padEnd(sorted, 4, sorted[sorted.length - 1]);
}

function parseValue(value) {
  const array = !_.isArray(value) ? [value] : value;

  const min = array[0]; // 最小值
  const max = array[array.length - 1]; // 最大值
  const min1 = array.length > 1 ? array[1] : min;
  const max1 = array.length > 3 ? array[3] : max;
  const median = array.length > 2 ? array[2] : min1;

  return {
    min, // 最小值
    max, // 最大值
    min1,
    max1,
    median,
  };
}

// get candle shape's key points
function getCandlePoints(x: number, y: number[], size: number) {
  const yValues = sortValue(y);
  return [
    { x, y: yValues[0] },
    { x, y: yValues[1] },
    { x: x - size / 2, y: yValues[2] },
    { x: x - size / 2, y: yValues[1] },
    { x: x + size / 2, y: yValues[1] },
    { x: x + size / 2, y: yValues[2] },
    { x, y: yValues[2] },
    { x, y: yValues[3] },
  ];
}

function getCandlePath(points) {
  return [
    ['M', points[0].x, points[0].y],
    ['L', points[1].x, points[1].y],
    ['M', points[2].x, points[2].y],
    ['L', points[3].x, points[3].y],
    ['L', points[4].x, points[4].y],
    ['L', points[5].x, points[5].y],
    ['Z'],
    ['M', points[6].x, points[6].y],
    ['L', points[7].x, points[7].y],
  ];
}

function getBoxPoints(x: number, y: number | number[], size: number) {
  const halfSize = size / 2;
  let pointsArray;
  if (_.isArray(y)) {
    // 2维
    const { min, max, median, min1, max1 } = parseValue(y);
    pointsArray = [
      [x - halfSize, max],
      [x + halfSize, max],
      [x, max],
      [x, max1],
      [x - halfSize, min1],
      [x - halfSize, max1],
      [x + halfSize, max1],
      [x + halfSize, min1],
      [x, min1],
      [x, min],
      [x - halfSize, min],
      [x + halfSize, min],
      [x - halfSize, median],
      [x + halfSize, median],
    ];
  } else {
    // 只有一个维度
    y = y || 0.5;
    const { min, max, median, min1, max1 } = parseValue(y);
    pointsArray = [
      [min, y - halfSize],
      [min, y + halfSize],
      [min, y],
      [min1, y],
      [min1, y - halfSize],
      [min1, y + halfSize],
      [max1, y + halfSize],
      [max1, y - halfSize],
      [max1, y],
      [max, y],
      [max, y - halfSize],
      [max, y + halfSize],
      [median, y - halfSize],
      [median, y + halfSize],
    ];
  }

  return pointsArray.map((arr) => {
    return {
      x: arr[0],
      y: arr[1],
    };
  });
}

function getBoxPath(points) {
  return [
    ['M', points[0].x, points[0].y],
    ['L', points[1].x, points[1].y],
    ['M', points[2].x, points[2].y],
    ['L', points[3].x, points[3].y],
    ['M', points[4].x, points[4].y],
    ['L', points[5].x, points[5].y],
    ['L', points[6].x, points[6].y],
    ['L', points[7].x, points[7].y],
    ['L', points[4].x, points[4].y], // 封闭 z
    ['Z'],
    ['M', points[8].x, points[8].y],
    ['L', points[9].x, points[9].y],
    ['M', points[10].x, points[10].y],
    ['L', points[11].x, points[11].y],
    ['M', points[12].x, points[12].y],
    ['L', points[13].x, points[13].y],
  ];
}

const SchemaShapeFactory = registerShapeFactory('schema', {
  defaultShapeType: '', // 'schema' is for some custom shapes, so will not specify defaultShapeType
});<commit_msg>chore: rename & add definitions<commit_after>import * as _ from '@antv/util';
import { PathCommand } from '../../dependents';
import { Point, ShapeDrawCFG, ShapePoint } from '../../interface';
import { padEnd } from '../../util/helper';
import { doAnimate } from '../animate';
import Element from '../element';
import { registerShape, registerShapeFactory } from './base';

function getCandleYValues(value: number | number[]) {
  const array = !_.isArray(value) ? [value] : value;
  // 从大到小排序
  const sorted = array.sort((a, b) => b - a);
  return padEnd(sorted, 4, sorted[sorted.length - 1]);
}

function parseValue(value: number[]) {
  const array = !_.isArray(value) ? [value] : value;

  const min = array[0]; // 最小值
  const max = array[array.length - 1]; // 最大值
  const min1 = array.length > 1 ? array[1] : min;
  const max1 = array.length > 3 ? array[3] : max;
  const median = array.length > 2 ? array[2] : min1;

  return {
    min, // 最小值
    max, // 最大值
    min1,
    max1,
    median,
  };
}

// get candle shape's key points
function getCandlePoints(x: number, y: number[], size: number): Point[] {
  const yValues = getCandleYValues(y);
  return [
    { x, y: yValues[0] },
    { x, y: yValues[1] },
    { x: x - size / 2, y: yValues[2] },
    { x: x - size / 2, y: yValues[1] },
    { x: x + size / 2, y: yValues[1] },
    { x: x + size / 2, y: yValues[2] },
    { x, y: yValues[2] },
    { x, y: yValues[3] },
  ];
}

function getCandlePath(points): PathCommand[] {
  return [
    ['M', points[0].x, points[0].y],
    ['L', points[1].x, points[1].y],
    ['M', points[2].x, points[2].y],
    ['L', points[3].x, points[3].y],
    ['L', points[4].x, points[4].y],
    ['L', points[5].x, points[5].y],
    ['Z'],
    ['M', points[6].x, points[6].y],
    ['L', points[7].x, points[7].y],
  ];
}

function getBoxPoints(x: number, y: number | number[], size: number): Point[] {
  const halfSize = size / 2;
  let pointsArray;
  if (_.isArray(y)) {
    // 2维
    const { min, max, median, min1, max1 } = parseValue(y);
    pointsArray = [
      [x - halfSize, max],
      [x + halfSize, max],
      [x, max],
      [x, max1],
      [x - halfSize, min1],
      [x - halfSize, max1],
      [x + halfSize, max1],
      [x + halfSize, min1],
      [x, min1],
      [x, min],
      [x - halfSize, min],
      [x + halfSize, min],
      [x - halfSize, median],
      [x + halfSize, median],
    ];
  } else {
    // 只有一个维度
    y = y || 0.5;
    const { min, max, median, min1, max1 } = parseValue([y]);
    pointsArray = [
      [min, y - halfSize],
      [min, y + halfSize],
      [min, y],
      [min1, y],
      [min1, y - halfSize],
      [min1, y + halfSize],
      [max1, y + halfSize],
      [max1, y - halfSize],
      [max1, y],
      [max, y],
      [max, y - halfSize],
      [max, y + halfSize],
      [median, y - halfSize],
      [median, y + halfSize],
    ];
  }

  return pointsArray.map((arr) => {
    return {
      x: arr[0],
      y: arr[1],
    };
  });
}

function getBoxPath(points): PathCommand[] {
  return [
    ['M', points[0].x, points[0].y],
    ['L', points[1].x, points[1].y],
    ['M', points[2].x, points[2].y],
    ['L', points[3].x, points[3].y],
    ['M', points[4].x, points[4].y],
    ['L', points[5].x, points[5].y],
    ['L', points[6].x, points[6].y],
    ['L', points[7].x, points[7].y],
    ['L', points[4].x, points[4].y], // 封闭 z
    ['Z'],
    ['M', points[8].x, points[8].y],
    ['L', points[9].x, points[9].y],
    ['M', points[10].x, points[10].y],
    ['L', points[11].x, points[11].y],
    ['M', points[12].x, points[12].y],
    ['L', points[13].x, points[13].y],
  ];
}

const SchemaShapeFactory = registerShapeFactory('schema', {
  defaultShapeType: '', // 'schema' is for some custom shapes, so will not specify defaultShapeType
});
{'fraction_non_alphanumeric': 0.2210086299892125, 'fraction_numerical': 0.027777777777777776, 'mean_word_length': 2.4821596244131454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '492114', 'n_tokens_mistral': 2955, 'n_tokens_neox': 2914, 'n_words': 723}