function updateSeriesText()

in viz-lib/src/visualizations/chart/plotly/updateData.ts [51:100]


function updateSeriesText(seriesList: any, options: any) {
  const formatNumber = createNumberFormatter(options.numberFormat);
  const formatPercent = createNumberFormatter(options.percentFormat);
  const formatText = createTextFormatter(options);

  const defaultY = options.missingValuesAsZero ? 0.0 : null;

  each(seriesList, series => {
    const seriesOptions = options.seriesOptions[series.name] || { type: options.globalSeriesType };

    series.text = [];
    series.hover = [];
    const xValues = options.globalSeriesType === "pie" ? series.labels : series.x;
    xValues.forEach((x: any) => {
      const text = {
        "@@name": series.name,
      };
      const item = series.sourceData.get(x) || { x, y: defaultY, row: { x, y: defaultY } };

      const yValueIsAny = includes(["bubble", "scatter"], seriesOptions.type);

      // for `formatValue` we have to use original value of `x` and `y`: `item.x`/`item.y` contains value
      // already processed with `normalizeValue`, and if they were `moment` instances - they are formatted
      // using default (ISO) date/time format. Here we need to use custom date/time format, so we pass original value
      // to `formatValue` which will call `normalizeValue` again, but this time with different date/time format
      // (if needed)
      // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
      text["@@x"] = formatValue(item.row.x, "x", options);
      // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
      text["@@y"] = yValueIsAny ? formatValue(item.row.y, series.yaxis, options) : formatNumber(item.y);
      if (item.yError !== undefined) {
        // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
        text["@@yError"] = formatNumber(item.yError);
      }
      if (item.size !== undefined) {
        // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
        text["@@size"] = formatNumber(item.size);
      }

      if (options.series.percentValues || options.globalSeriesType === "pie") {
        // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
        text["@@yPercent"] = formatPercent(Math.abs(item.yPercent));
      }

      extend(text, item.row.$raw);

      series.text.push(formatText(text));
    });
  });
}