export function renderLine()

in packages/charts/src/chart_types/xy_chart/rendering/line.ts [27:91]


export function renderLine(
  shift: number,
  dataSeries: DataSeries,
  xScale: ScaleBand | ScaleContinuous,
  yScale: ScaleContinuous,
  panel: Dimensions,
  color: Color,
  curve: CurveType,
  hasY0Accessors: boolean,
  xScaleOffset: number,
  style: LineSeriesStyle,
  markSizeOptions: MarkSizeOptions,
  hasFit: boolean,
  pointStyleAccessor?: PointStyleAccessor,
): {
  lineGeometry: LineGeometry;
  indexedGeometryMap: IndexedGeometryMap;
} {
  const y1Fn = getY1ScaledValueFn(yScale);
  const definedFn = isYValueDefinedFn(yScale, xScale);
  const y1Accessor = getYDatumValueFn();

  const pathGenerator = line<DataSeriesDatum>()
    .x(({ x }) => xScale.scale(x) - xScaleOffset)
    .y(y1Fn)
    .defined((datum) => definedFn(datum, y1Accessor))
    .curve(getCurveFactory(curve));

  const { pointGeometries, indexedGeometryMap, minDistanceBetweenPoints } = renderPoints(
    shift - xScaleOffset,
    dataSeries,
    xScale,
    yScale,
    panel,
    color,
    style.point,
    style.isolatedPoint,
    style.line.strokeWidth,
    hasY0Accessors,
    markSizeOptions,
    false,
    style.isolatedPoint.enabled,
    pointStyleAccessor,
  );

  // TODO we can probably avoid computing the clipped ranges if no fit function is applied.
  const clippedRanges = getClippedRanges(dataSeries.data, xScale, xScaleOffset);

  const lineGeometry: LineGeometry = {
    line: pathGenerator(dataSeries.data) || '',
    points: pointGeometries,
    color,
    transform: {
      x: shift,
      y: 0,
    },
    seriesIdentifier: getSeriesIdentifierFromDataSeries(dataSeries),
    style,
    clippedRanges,
    shouldClip: hasFit,
    hasFit,
    minPointDistance: minDistanceBetweenPoints,
  };
  return { lineGeometry, indexedGeometryMap };
}