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 bounds = _getBarBounds(
      details.domain,
      domainAxis,
      domainAxis.rangeBand.round(),
      config.maxBarWidthPx,
      details.measure,
      details.measureOffset!,
      measureAxis,
      barGroupIndex,
      previousBarGroupWeight,
      barGroupWeight,
      allBarGroupWeights,
      numBarGroups);

  NullablePoint chartPosition;

  if (renderingVertically) {
    chartPosition = NullablePoint(
        (bounds.left + (bounds.width / 2)).toDouble(), bounds.top.toDouble());
  } else {
    chartPosition = NullablePoint(
        isRtl ? bounds.left.toDouble() : bounds.right.toDouble(),
        (bounds.top + (bounds.height / 2)).toDouble());
  }

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