initPath method

void initPath(
  1. Size size
)

计算Path

Implementation

void initPath(Size size) {
  if (path == null) {
    if ((chartBeans?.isNotEmpty ?? false) && maxMin[0] > 0) {
      path = Path();
      double preX, preY, currentX, currentY;
      int length = chartBeans!.length > 7 ? 7 : chartBeans!.length;
      double W = _fixedWidth / (length - 1); //两个点之间的x方向距离
      for (int i = 0; i < length; i++) {
        if (i == 0) {
          var key = startX;
          var value = (startY - chartBeans![i].y / maxMin[0] * _fixedHeight);
          path!.moveTo(key, value);
          _points[key] = Offset(key, value);
          continue;
        }
        currentX = startX + W * i;
        preX = startX + W * (i - 1);

        preY = (startY - chartBeans![i - 1].y / maxMin[0] * _fixedHeight);
        currentY = (startY - chartBeans![i].y / maxMin[0] * _fixedHeight);
        _points[currentX] = Offset(currentX, currentY);

        if (isCurve) {
          path!.cubicTo(
            (preX + currentX) / 2,
            preY,
            (preX + currentX) / 2,
            currentY,
            currentX,
            currentY,
          );
        } else {
          path!.lineTo(currentX, currentY);
        }
      }
    }
  }
}