detectOutsideLabelCollision method

  1. @protected
bool detectOutsideLabelCollision(
  1. num labelY,
  2. bool labelLeftOfChart,
  3. num? previousOutsideLabelY,
  4. bool? previousLabelLeftOfChart,
)

Detects whether the current outside label collides with the previous label.

Implementation

@protected
bool detectOutsideLabelCollision(
  num labelY,
  bool labelLeftOfChart,
  num? previousOutsideLabelY,
  bool? previousLabelLeftOfChart,
) {
  var collides = false;

  // Given that labels are vertically centered, we can assume they will
  // collide if the current label's Y coordinate +/- the font size
  // crosses past the Y coordinate of the previous label drawn on the
  // same side of the chart.
  if (previousOutsideLabelY != null &&
      labelLeftOfChart == previousLabelLeftOfChart) {
    if (labelY > previousOutsideLabelY) {
      if (labelY - outsideLabelStyleSpec.fontSize! <= previousOutsideLabelY) {
        collides = true;
      }
    } else {
      if (labelY + outsideLabelStyleSpec.fontSize! >= previousOutsideLabelY) {
        collides = true;
      }
    }
  }

  return collides;
}