<commit_before>import Component from './component';
import { ChartState, Options } from '@t/store/store';
import {
  BoxPlotResponderModel,
  BulletResponderModel,
  CircleResponderModel,
  HeatmapRectResponderModel,
  RectResponderModel,
  ResponderModel,
  SectorResponderModel,
} from '@t/components/series';
import {
  isClickSameCircleResponder,
  isClickSameDataResponder,
  isClickSameGroupedRectResponder,
  isClickSameNameResponder,
} from '@src/helpers/responders';
import { includes } from '@src/helpers/utils';
import { TooltipModelName } from '@t/components/tooltip';
import { LineTypeEventDetectType } from '@t/options';

interface SelectedSeriesEventModel {
  models: ResponderModel[];
  name: string;
  eventDetectType?: LineTypeEventDetectType;
  alias?: string;
}

export type ResponderSeriesModel = { [key in TooltipModelName]: ResponderModel[] };

type ActiveSeriesNames = { [key in TooltipModelName]: string[] };

export default class SelectedSeries extends Component {
  models: ResponderSeriesModel = {} as ResponderSeriesModel;

  activeSeriesNames: ActiveSeriesNames = {} as ActiveSeriesNames;

  isShow = false;

  // eslint-disable-next-line complexity
  isClickSameSeries({ models, name, eventDetectType, alias }: SelectedSeriesEventModel) {
    switch (name) {
      case 'heatmap':
        return isClickSameNameResponder<HeatmapRectResponderModel>(
          models as HeatmapRectResponderModel[],
          this.models[name] as HeatmapRectResponderModel[]
        );
      case 'bullet':
        return isClickSameNameResponder<BulletResponderModel>(
          models as BulletResponderModel[],
          this.models[name] as BulletResponderModel[]
        );
      case 'radar':
      case 'bubble':
      case 'scatter':
      case 'area':
      case 'line':
        return isClickSameCircleResponder(
          models as CircleResponderModel[],
          this.models[name] as CircleResponderModel[]
        );
      case 'pie':
        return isClickSameDataResponder<SectorResponderModel>(
          models as SectorResponderModel[],
          this.models[alias ?? name] as SectorResponderModel[]
        );
      case 'column':
      case 'bar':
        return eventDetectType === 'grouped'
          ? isClickSameGroupedRectResponder(
              models as RectResponderModel[],
              this.models[name] as RectResponderModel[]
            )
          : isClickSameDataResponder<RectResponderModel>(
              models as RectResponderModel[],
              this.models[name] as RectResponderModel[]
            );
      case 'boxPlot':
        return isClickSameDataResponder<BoxPlotResponderModel>(
          models as BoxPlotResponderModel[],
          this.models[name] as BoxPlotResponderModel[]
        );
      default:
        return false;
    }
  }

  private getSeriesNames(selectedSeries: ResponderModel[], name: string) {
    const names: string[] = [];

    if (includes(['line', 'area', 'radar', 'bubble', 'scatter', 'bullet', 'boxPlot'], name)) {
      selectedSeries.forEach((model) => {
        const label = (model as CircleResponderModel | BulletResponderModel | BoxPlotResponderModel)
          .name;
        if (label) {
          names.push(label);
        }
      });
    } else if (includes(['bar', 'column'], name)) {
      selectedSeries.forEach((model) => {
        const label = (model as RectResponderModel).data?.label;
        if (label) {
          names.push(label);
        }
      });
    } else if (name === 'pie') {
      Object.keys(this.models)
        .flatMap((key) => this.models[key])
        .forEach((model) => {
          const label = (model as SectorResponderModel).data?.rootParentName;
          if (label) {
            names.push(label);
          }
        });
    }

    return names;
  }

  getSelectedSeriesModels(selectedSeriesEventModel: SelectedSeriesEventModel) {
    const { models, eventDetectType, name } = selectedSeriesEventModel;
    let selectedSeriesModels = models;<commit_msg>fix: resolve selected pie series (#416)<commit_after>import Component from './component';
import { ChartState, Options } from '@t/store/store';
import {
  BoxPlotResponderModel,
  BulletResponderModel,
  CircleResponderModel,
  HeatmapRectResponderModel,
  RectResponderModel,
  ResponderModel,
  SectorResponderModel,
} from '@t/components/series';
import {
  isClickSameCircleResponder,
  isClickSameDataResponder,
  isClickSameGroupedRectResponder,
  isClickSameNameResponder,
} from '@src/helpers/responders';
import { includes } from '@src/helpers/utils';
import { TooltipModelName } from '@t/components/tooltip';
import { LineTypeEventDetectType } from '@t/options';

interface SelectedSeriesEventModel {
  models: ResponderModel[];
  name: string;
  eventDetectType?: LineTypeEventDetectType;
  alias?: string;
}

export type ResponderSeriesModel = { [key in TooltipModelName]: ResponderModel[] };

type ActiveSeriesNames = { [key in TooltipModelName]: string[] };

export default class SelectedSeries extends Component {
  models: ResponderSeriesModel = {} as ResponderSeriesModel;

  activeSeriesNames: ActiveSeriesNames = {} as ActiveSeriesNames;

  isShow = false;

  // eslint-disable-next-line complexity
  isClickSameSeries({ models, name, eventDetectType, alias }: SelectedSeriesEventModel) {
    switch (name) {
      case 'heatmap':
        return isClickSameNameResponder<HeatmapRectResponderModel>(
          models as HeatmapRectResponderModel[],
          this.models[name] as HeatmapRectResponderModel[]
        );
      case 'bullet':
        return isClickSameNameResponder<BulletResponderModel>(
          models as BulletResponderModel[],
          this.models[name] as BulletResponderModel[]
        );
      case 'radar':
      case 'bubble':
      case 'scatter':
      case 'area':
      case 'line':
        return isClickSameCircleResponder(
          models as CircleResponderModel[],
          this.models[name] as CircleResponderModel[]
        );
      case 'pie':
        return isClickSameDataResponder<SectorResponderModel>(
          models as SectorResponderModel[],
          this.models[alias || name] as SectorResponderModel[]
        );
      case 'column':
      case 'bar':
        return eventDetectType === 'grouped'
          ? isClickSameGroupedRectResponder(
              models as RectResponderModel[],
              this.models[name] as RectResponderModel[]
            )
          : isClickSameDataResponder<RectResponderModel>(
              models as RectResponderModel[],
              this.models[name] as RectResponderModel[]
            );
      case 'boxPlot':
        return isClickSameDataResponder<BoxPlotResponderModel>(
          models as BoxPlotResponderModel[],
          this.models[name] as BoxPlotResponderModel[]
        );
      default:
        return false;
    }
  }

  private getSeriesNames(selectedSeries: ResponderModel[], name: string) {
    const names: string[] = [];

    if (includes(['line', 'area', 'radar', 'bubble', 'scatter', 'bullet', 'boxPlot'], name)) {
      selectedSeries.forEach((model) => {
        const label = (model as CircleResponderModel | BulletResponderModel | BoxPlotResponderModel)
          .name;
        if (label) {
          names.push(label);
        }
      });
    } else if (includes(['bar', 'column'], name)) {
      selectedSeries.forEach((model) => {
        const label = (model as RectResponderModel).data?.label;
        if (label) {
          names.push(label);
        }
      });
    } else if (name === 'pie') {
      Object.keys(this.models)
        .flatMap((key) => this.models[key])
        .forEach((model) => {
          const label =
            (model as SectorResponderModel).data?.rootParentName ||
            (model as SectorResponderModel).data?.label;
          if (label) {
            names.push(label);
          }
        });
    }

    return names;
  }

  getSelectedSeriesModels(selectedSeriesEventModel: SelectedSeriesEventModel) {
    const { models, eventDetectType, name } = selectedSeriesEventModel;
    let selectedSeriesModels = models;
{'fraction_non_alphanumeric': 0.10789766407119021, 'fraction_numerical': 0.0003707823507601038, 'mean_word_length': 2.970559371933268, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '2207704', 'n_tokens_mistral': 2366, 'n_tokens_neox': 2222, 'n_words': 489}