createPathFromChartPoints function

Path? createPathFromChartPoints(
  1. Size size,
  2. BoundingBox bounds,
  3. List<Point> points, {
  4. bool closePath = false,
  5. double? smoothness,
})

Implementation

Path? createPathFromChartPoints(
  Size size,
  BoundingBox bounds,
  List<Point> points, {
  bool closePath = false,
  double? smoothness,
}) {
  if (points.length < 2) {
    return null;
  }

  final path = Path();
  final zeroFraction = bounds.getFractionY(0);
  final scaledPoints =
      points.map((point) => _getScaledPoint(bounds, point, size)).toList();

  if (closePath) {
    path
      ..moveTo(scaledPoints.first.x, size.height * zeroFraction.clamp(0, 1))
      ..lineTo(scaledPoints.first.x, scaledPoints.first.y);
  } else {
    path.moveTo(scaledPoints.first.x, scaledPoints.first.y);
  }

  if (smoothness == null) {
    _createSimplePath(path, scaledPoints);
  } else {
    _createSmoothPath(path, scaledPoints, smoothness);
  }

  if (closePath) {
    path.lineTo(scaledPoints.last.x, size.height * zeroFraction.clamp(0, 1));
  }

  return path;
}