getTicks method

  1. @override
List<Tick<DateTime>> getTicks({
  1. required ChartContext? context,
  2. required GraphicsFactory graphicsFactory,
  3. required covariant DateTimeScale scale,
  4. required TickFormatter<DateTime> formatter,
  5. required Map<DateTime, String> formatterValueCache,
  6. required TickDrawStrategy<DateTime> tickDrawStrategy,
  7. required AxisOrientation? orientation,
  8. bool viewportExtensionEnabled = false,
  9. TickHint<DateTime>? tickHint,
})

Generates a list of ticks for the given data which should not collide unless the range is not large enough.

Implementation

@override
List<Tick<DateTime>> getTicks({
  required ChartContext? context,
  required GraphicsFactory graphicsFactory,
  required DateTimeScale scale,
  required TickFormatter<DateTime> formatter,
  required Map<DateTime, String> formatterValueCache,
  required TickDrawStrategy<DateTime> tickDrawStrategy,
  required AxisOrientation? orientation,
  bool viewportExtensionEnabled = false,
  TickHint<DateTime>? tickHint,
}) {
  List<TimeRangeTickProvider> tickProviders;

  /// If tick hint is provided, use the closest tick provider, otherwise
  /// look through the tick providers for one that provides sufficient ticks
  /// for the viewport.
  if (tickHint != null) {
    tickProviders = [_getClosestTickProvider(tickHint)];
  } else {
    tickProviders = _potentialTickProviders;
  }

  final lastTickProvider = tickProviders.last;

  final viewport = scale.viewportDomain;
  for (final tickProvider in tickProviders) {
    final isLastProvider = tickProvider == lastTickProvider;
    if (isLastProvider ||
        tickProvider.providesSufficientTicksForRange(viewport)) {
      return tickProvider.getTicks(
        context: context,
        graphicsFactory: graphicsFactory,
        scale: scale,
        formatter: formatter,
        formatterValueCache: formatterValueCache,
        tickDrawStrategy: tickDrawStrategy,
        orientation: orientation,
      );
    }
  }

  return <Tick<DateTime>>[];
}