getRealRect method

Rect? getRealRect()

偏移/放大操作后,计算其真实位置

Implementation

Rect? getRealRect() {
  ChartCoordinateState? layout = this.layout;
  if (layout == null) {
    return originRect;
  }
  if (this is ChartLineLayoutState) {
    final double left = layout.left;
    final double top = layout.top;
    final double bottom = layout.bottom;
    final ChartLineLayoutState p = this as ChartLineLayoutState;
    final double dotRadius = originRect!.width / 2;
    double xPos = xValue! * p.xAxis.density + left;
    xPos = layout.transform.withXScroll(xPos);
    if (yValue != null) {
      double yPos = bottom - p.yAxis[p.yAxisPosition].getHeight(yValue!);
      Offset currentPoint = Offset(xPos, yPos);
      return Rect.fromCenter(center: currentPoint, width: dotRadius, height: dotRadius);
    } else {
      return Rect.fromLTRB(xPos - dotRadius, top, xPos + dotRadius, bottom);
    }
  }
  return originRect;
}