getTicks method
List<Tick<DateTime> >
getTicks({
- required ChartContext? context,
- required GraphicsFactory graphicsFactory,
- required covariant DateTimeScale scale,
- required TickFormatter<
DateTime> formatter, - required Map<
DateTime, String> formatterValueCache, - required TickDrawStrategy<
DateTime> tickDrawStrategy, - required AxisOrientation? orientation,
- bool viewportExtensionEnabled = false,
- TickHint<
DateTime> ? tickHint,
Returns a list of ticks in value order that should be displayed.
If no ticks are desired an empty list should be returned.
graphicsFactory
The graphics factory used for text measurement.
scale
The scale of the data.
formatter
The formatter to use for generating tick labels.
orientation
Orientation of this axis ticks.
tickDrawStrategy
Draw strategy for ticks.
viewportExtensionEnabled
allow extending the viewport for 'niced' ticks.
tickHint
tick values for provider to calculate a desired tick range.
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,
}) {
late List<Tick<DateTime>> currentTicks;
final tickValues = <DateTime>[];
final timeStepIt = timeStepper.getSteps(scale.viewportDomain).iterator;
// Try different tickIncrements and choose the first that has no collisions.
// If none exist use the last one which should have the fewest ticks and
// hope that the renderer will resolve collisions.
//
// If a tick hint was provided, use the tick hint to search for the closest
// increment and use that.
List<int> allowedTickIncrements;
if (tickHint != null) {
final stepSize = tickHint.end.difference(tickHint.start).inMilliseconds;
allowedTickIncrements = [_getClosestIncrementFromStepSize(stepSize)];
} else {
allowedTickIncrements = timeStepper.allowedTickIncrements;
}
assert(allowedTickIncrements.isNotEmpty);
for (final tickIncrement in allowedTickIncrements) {
// Create tick values with a specified increment.
tickValues.clear();
timeStepIt.reset(tickIncrement);
while (timeStepIt.moveNext()) {
tickValues.add(timeStepIt.current);
}
// Create ticks
currentTicks = createTicks(tickValues,
context: context,
graphicsFactory: graphicsFactory,
scale: scale,
formatter: formatter,
formatterValueCache: formatterValueCache,
tickDrawStrategy: tickDrawStrategy,
stepSize: timeStepper.typicalStepSizeMs * tickIncrement);
// Request collision check from draw strategy.
final collisionReport =
tickDrawStrategy.collides(currentTicks, orientation);
if (!collisionReport.ticksCollide) {
// Return the first non colliding ticks.
return currentTicks;
}
}
// If all ticks collide, return the last generated ticks.
return currentTicks;
}