getCoordinates method

List<GeoCoordinate2D> getCoordinates({
  1. required Size size,
})

generate coordinate for polar chart based on rectangular region. An ellipse is used to distort the polar chart to resemble the shape of the region. For a more circular look, the size width and height should be the same.

Implementation

List<GeoCoordinate2D> getCoordinates({required Size size}) {
  GeoAngle samplingAngle =
      GeoAngle(radian: (polarEndAngle - polarBeginAngle) / sampling);
  GeoEllipse ellipse = GeoEllipse(size.width / 2, size.height / 2);
  List<GeoCoordinate2D> coords = <GeoCoordinate2D>[];
  GeoAngle polarAngle = GeoAngle(radian: polarBeginAngle);
  double currentAngle = clockwise ? startAngle.radian : -startAngle.radian;

  bool hasBoxFit = (boxFit != BoxFit.none);
  GeoCoordinate2D? center = GeoCoordinate2D(size.width / 2, size.height / 2);
  for (int i = 0; i < sampling; i++) {
    coords.add(ellipse.coordinateByRadian(
        currentAngle, center, formula(polarAngle)));
    currentAngle += clockwise ? samplingAngle.radian : -samplingAngle.radian;
    polarAngle += samplingAngle;
  }
  if (hasBoxFit) {
    GeoUtility.scaleToFit(size, boxFit, coords, true, true);
    GeoUtility.recenter(
        GeoCoordinate2D(size.width / 2, size.height / 2), coords, true);
  }
  return coords;
}