updateSegmentGradient method

  1. @nonVirtual
void updateSegmentGradient(
  1. ChartSegment segment
)

Implementation

@nonVirtual
void updateSegmentGradient(ChartSegment segment) {
  if (!segment.isEmpty) {
    if (pointShaderMapper != null) {
      final Shader shader = pointShaderMapper!(
          dataSource![segment.currentSegmentIndex],
          segment.currentSegmentIndex,
          palette[segment.currentSegmentIndex % palette.length],
          Rect.fromCircle(center: center, radius: currentRadius));
      segment.fillPaint.shader = shader;
    } else if (onCreateShader != null) {
      final ChartShaderDetails details = createShaderDetails();
      segment.fillPaint.shader = onCreateShader!(details);
    } else if (pointRenderMode == PointRenderMode.gradient) {
      final List<Color> colors = List<Color>.generate(
          segments.length, (int i) => palette[i % palette.length]);
      final List<double> stops = <double>[];
      num initialStops = 0;
      for (int i = 0; i < segments.length; i++) {
        final double segmentRatio = circularYValues[i] / sumOfY;
        if (stops.isEmpty) {
          initialStops = segmentRatio / 4;
          stops.add(segmentRatio - initialStops);
        } else {
          if (stops.length == 1) {
            stops.add((segmentRatio + stops.last) + initialStops / 1.5);
          } else {
            stops.add(segmentRatio + stops.last);
          }
        }
      }
      final SweepGradient sweep = SweepGradient(
          startAngle: degreeToRadian(startAngle),
          endAngle: degreeToRadian(endAngle),
          colors: colors,
          stops: stops,
          transform: GradientRotation(degreeToRadian(-90)));
      segment.fillPaint.shader = sweep.createShader(
          createShaderDetails().outerRect,
          textDirection: TextDirection.ltr);
    }
  }
}