draw method
Implementation
@override
void draw(Canvas canvas, ChartsState state) {
_ChartCircularCoordinateState layout = state.layout as _ChartCircularCoordinateState;
Offset center = layout.center;
double radius = layout.radius;
int index = 0;
num? lastXvs;
double startAngle = this.startAngle;
double fullSweepAngle = math.pi;
//
if (layout.arcPosition == ArcPosition.none) {
fullSweepAngle = math.pi * 2;
} else if (layout.arcPosition == ArcPosition.up) {
fullSweepAngle = math.pi;
} else if (layout.arcPosition == ArcPosition.down) {
startAngle = 0;
}
for (T item in data) {
num po = position.call(item);
if (lastXvs != null) {
assert(lastXvs > po, '数据必须降序,否则会被挡住');
}
double sweepAngle = fullSweepAngle * po * layout.controlValue;
Path path = Path()
..addArc(
Rect.fromCenter(center: center, width: radius * 2, height: radius * 2),
startAngle,
sweepAngle,
);
canvas.drawPath(path, _paint..color = colors[index]);
if (_endPaint != null && sweepAngle > 0) {
double endAngle = startAngle + sweepAngle;
var startX = math.cos(endAngle) * radius + center.dx;
var startY = math.sin(endAngle) * radius + center.dy;
canvas.drawCircle(Offset(startX, startY), strokeWidth / 2 - 2, _endPaint!);
}
index++;
lastXvs = po;
}
}