drawSegment method

void drawSegment(
  1. CanvasRenderingContext2D ctx,
  2. int idx,
  3. PieChartItem item,
  4. double start,
)

Implementation

void drawSegment(CanvasRenderingContext2D ctx, int idx, PieChartItem item, double start) {
  ctx.save();

  var radius = (min(width, height) / 2) * (item.isActive ? 0.88 : 0.82);
  var startingAngle = degreesToRadians((start / totalWeight) * 360 - 90.0) - (item.isActive ? 0.03 : 0);
  var arcSize = degreesToRadians((item.weight / totalWeight) * 360) + (item.isActive ? 0.06 : 0);
  var endingAngle = startingAngle + arcSize;

  ctx.beginPath();
  ctx.moveTo(centerX, centerY);
  ctx.arc(centerX, centerY, radius, startingAngle, endingAngle, false);
  ctx.closePath();

  ctx.fillStyle = (item.color ?? '').toJS;
  ctx.fill();
  ctx.restore();

  drawSegmentLabel(ctx, idx, item, start);
}