updateTickWidth method

  1. @override
void updateTickWidth(
  1. List<Tick<D>> ticks,
  2. int maxWidth,
  3. int maxHeight,
  4. AxisOrientation orientation, {
  5. bool collision = false,
})
override

Updates max tick width to match fit max size.

Implementation

@override
void updateTickWidth(List<Tick<D>> ticks, int maxWidth, int maxHeight,
    AxisOrientation orientation,
    {bool collision = false}) {
  final isVertical =
      orientation != null && orientation == AxisOrientation.right ||
          orientation == AxisOrientation.left;
  final rotationRelativeToAxis =
      labelRotation(collision: collision).toDouble();
  final rotationRads =
      _degToRad(rotationRelativeToAxis - (isVertical ? 90 : 0)).abs();
  final availableSpace = (isVertical ? maxWidth : maxHeight) -
      labelOffsetFromAxisPx(collision: collision);
  final maxTextWidth = sin(rotationRads) == 0
      ? null
      : (availableSpace / sin(rotationRads)).floor();

  for (final tick in ticks) {
    if (maxTextWidth != null) {
      tick.textElement!.maxWidth = maxTextWidth;
      tick.textElement!.maxWidthStrategy = MaxWidthStrategy.ellipsize;
    } else {
      tick.textElement!.maxWidth = null;
      tick.textElement!.maxWidthStrategy = null;
    }
  }
}