addPositionToDetailsForSeriesDatum method

  1. @override
DatumDetails<D> addPositionToDetailsForSeriesDatum(
  1. DatumDetails<D> details,
  2. SeriesDatum<D> seriesDatum
)
override

Adds chart position data to details.

This is a helper function intended to be called from getDetailsForSeriesDatum. Every concrete SeriesRenderer needs to implement custom logic for setting location data.

Implementation

@override
DatumDetails<D> addPositionToDetailsForSeriesDatum(
  DatumDetails<D> details,
  SeriesDatum<D> seriesDatum,
) {
  final series = details.series!;

  final domainAxis = series.getAttr(domainAxisKey)! as ImmutableAxis<D>;
  final measureAxis = series.getAttr(measureAxisKey)! as ImmutableAxis<num>;

  final barGroupIndex = series.getAttr(barGroupIndexKey)!;
  final previousBarGroupWeight = series.getAttr(previousBarGroupWeightKey);
  final barGroupWeight = series.getAttr(barGroupWeightKey);
  final allBarGroupWeights = series.getAttr(allBarGroupWeightsKey);
  final numBarGroups = series.getAttr(barGroupCountKey)!;

  final points = _getTargetLinePoints(
    details.domain,
    domainAxis,
    domainAxis.rangeBand.round(),
    config.maxBarWidthPx,
    details.measure,
    details.measureOffset!,
    measureAxis,
    barGroupIndex,
    previousBarGroupWeight,
    barGroupWeight,
    allBarGroupWeights,
    numBarGroups,
  );

  NullablePoint chartPosition;

  if (renderingVertically) {
    chartPosition = NullablePoint(
      points[0].x + (points[1].x - points[0].x) / 2,
      points[0].y.toDouble(),
    );
  } else {
    chartPosition = NullablePoint(
      points[0].x.toDouble(),
      points[0].y + (points[1].y - points[0].y) / 2,
    );
  }

  return DatumDetails.from(details, chartPosition: chartPosition);
}