<commit_before>/**
 * view 中缓存 scale 的类
 */
import { each, get, isNumber } from '@antv/util';
import { Scale } from '../../dependents';
import { Data, ScaleOption } from '../../interface';
import { createScaleByField, syncScale } from '../../util/scale';

interface ScaleMeta {
  readonly key: string;
  readonly scale: Scale;
  scaleDef: ScaleOption;
}

export class ScalePool {
  /** 所有的 scales */
  private scales: Record<string, ScaleMeta> = {};
  /** 需要同步的 scale 分组， key: scaleKeyArray */
  private syncScales: Record<string, string[]> = {};

  /**
   * 创建 scale
   * @param field
   * @param data
   * @param scaleDef
   * @param key
   */
  public createScale(field: string, data: Data, scaleDef: ScaleOption, key: string): Scale {
    const scale = createScaleByField(field, data, scaleDef);

    // 缓存起来
    this.cacheScale(scale, scaleDef, key);

    return scale;
  }

  /**
   * 同步 scale
   */
  public sync() {
    // 对于 syncScales 中每一个 syncKey 下面的 scale 数组进行同步处理
    each(this.syncScales, (scaleKeys: string[], syncKey: string) => {
      // min, max, values
      let min = Number.MAX_SAFE_INTEGER;
      let max = Number.MIN_SAFE_INTEGER;
      const values = [];

      // 1. 遍历求得最大最小值，values 等
      each(scaleKeys, (key: string) => {
        const scale = this.getScale(key);

        max = isNumber(scale.max) ? Math.max(max, scale.max) : max;
        min = isNumber(scale.min) ? Math.min(min, scale.min) : min;

        // 去重
        each(scale.values, (v: any) => {
          if (!values.includes(v)) {
            values.push(v);
          }
        });
      });

      // 2. 同步
      each(scaleKeys, (key: string) => {
        const scale = this.getScale(key);
        scale.change({
          min,
          max,
          values,
        });
      });
    });<commit_msg>fix(sync-scale): category scale sync only sync values<commit_after>/**
 * view 中缓存 scale 的类
 */
import { each, get, isNumber } from '@antv/util';
import { Scale } from '../../dependents';
import { Data, ScaleOption } from '../../interface';
import { createScaleByField, syncScale } from '../../util/scale';

interface ScaleMeta {
  readonly key: string;
  readonly scale: Scale;
  scaleDef: ScaleOption;
}

export class ScalePool {
  /** 所有的 scales */
  private scales: Record<string, ScaleMeta> = {};
  /** 需要同步的 scale 分组， key: scaleKeyArray */
  private syncScales: Record<string, string[]> = {};

  /**
   * 创建 scale
   * @param field
   * @param data
   * @param scaleDef
   * @param key
   */
  public createScale(field: string, data: Data, scaleDef: ScaleOption, key: string): Scale {
    const scale = createScaleByField(field, data, scaleDef);

    // 缓存起来
    this.cacheScale(scale, scaleDef, key);

    return scale;
  }

  /**
   * 同步 scale
   */
  public sync() {
    // 对于 syncScales 中每一个 syncKey 下面的 scale 数组进行同步处理
    each(this.syncScales, (scaleKeys: string[], syncKey: string) => {
      // min, max, values
      let min = Number.MAX_SAFE_INTEGER;
      let max = Number.MIN_SAFE_INTEGER;
      const values = [];

      // 1. 遍历求得最大最小值，values 等
      each(scaleKeys, (key: string) => {
        const scale = this.getScale(key);

        max = isNumber(scale.max) ? Math.max(max, scale.max) : max;
        min = isNumber(scale.min) ? Math.min(min, scale.min) : min;

        // 去重
        each(scale.values, (v: any) => {
          if (!values.includes(v)) {
            values.push(v);
          }
        });
      });

      // 2. 同步
      each(scaleKeys, (key: string) => {
        const scale = this.getScale(key);

        if (scale.isContinuous) {
          scale.change({
            min,
            max,
            values,
          });
        } else if (scale.isCategory) {
          scale.change({
            values,
          });
        }
      });
    });
{'fraction_non_alphanumeric': 0.1496437054631829, 'fraction_numerical': 0.0010556875164951175, 'mean_word_length': 2.142620232172471, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5368481', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1288, 'n_words': 311}