export function getSeriesName()

in packages/charts/src/chart_types/xy_chart/utils/series.ts [538:566]


export function getSeriesName(
  seriesIdentifier: XYChartSeriesIdentifier,
  hasSingleSeries: boolean,
  isTooltip: boolean,
  spec?: BasicSeriesSpec,
): string {
  const customLabel =
    typeof spec?.name === 'function'
      ? spec.name(seriesIdentifier, isTooltip)
      : typeof spec?.name === 'object' // extract booleans once https://github.com/microsoft/TypeScript/issues/12184 is fixed
        ? getSeriesNameFromOptions(spec.name, seriesIdentifier, spec.name.delimiter ?? SERIES_DELIMITER)
        : null;

  if (customLabel !== null) {
    return customLabel.toString();
  }

  const multipleYAccessors = spec && spec.yAccessors.length > 1;
  const nameKeys = multipleYAccessors ? seriesIdentifier.seriesKeys : seriesIdentifier.seriesKeys.slice(0, -1);
  const nonZeroLength = nameKeys.length > 0;

  return nonZeroLength && (spec?.splitSeriesAccessors || !hasSingleSeries)
    ? nameKeys.join(typeof spec?.name === 'object' ? spec.name.delimiter ?? SERIES_DELIMITER : SERIES_DELIMITER)
    : spec === undefined
      ? ''
      : typeof spec.name === 'string'
        ? spec.name
        : spec.id;
}