createA11yNodes method

  1. @override
List<A11yNode> createA11yNodes()

Returns a list of A11yNodes for this chart.

Implementation

@override
List<A11yNode> createA11yNodes() {
  final nodes = <_DomainA11yNode>[];

  // Update the selection model when the a11y node has focus.
  final selectionModel = _chart.getSelectionModel(SelectionModelType.info);

  final domainSeriesDatum = <D, List<SeriesDatum<D>>>{};

  for (final series in _seriesList) {
    for (var index = 0; index < series.data.length; index++) {
      final Object? datum = series.data[index];
      final domain = series.domainFn(index);

      domainSeriesDatum[domain] ??= <SeriesDatum<D>>[];
      domainSeriesDatum[domain]!.add(SeriesDatum<D>(series, datum));
    }
  }

  domainSeriesDatum.forEach((domain, seriesDatums) {
    final a11yDescription = _vocalizationCallback(seriesDatums);

    final firstSeries = seriesDatums.first.series;
    final domainAxis =
        firstSeries.getAttr(domainAxisKey)! as ImmutableAxis<D>;
    final location = domainAxis.getLocation(domain)!;

    /// If the step size is smaller than the minimum width, use minimum.
    final stepSize = (domainAxis.stepSize > minimumWidth)
        ? domainAxis.stepSize
        : minimumWidth;

    nodes.add(
      _DomainA11yNode(
        a11yDescription,
        location: location,
        stepSize: stepSize,
        chartDrawBounds: _chart.drawAreaBounds,
        isRtl: _chart.context.isRtl,
        renderVertically: _chart.vertical,
        onFocus: () => selectionModel.updateSelection(seriesDatums, []),
      ),
    );
  });

  // The screen reader navigates the nodes based on the order it is returned.
  // So if the chart is RTL, then the nodes should be ordered with the right
  // most domain first.
  //
  // If the chart has multiple series and one series is missing the domain
  // and it was added later, we still want the domains to be in order.
  nodes.sort();

  return nodes;
}