paint method

  1. @override
void paint(
  1. ChartCanvas canvas,
  2. Rectangle<num> bounds, {
  3. List<int>? dashPattern,
  4. Color? fillColor,
  5. FillPatternType? fillPattern,
  6. Color? strokeColor,
  7. double? strokeWidthPx,
})
override

Implementation

@override
void paint(
  ChartCanvas canvas,
  Rectangle<num> bounds, {
  List<int>? dashPattern,
  Color? fillColor,
  FillPatternType? fillPattern,
  Color? strokeColor,
  double? strokeWidthPx,
}) {
  final centerHeight = (bounds.bottom - bounds.top) / 2;

  // If we have a dash pattern, do not round the end caps, and set
  // strokeWidthPx to a smaller value. Using round end caps makes smaller
  // patterns blurry.
  final localDashPattern = dashPattern ?? _dashPattern;
  final roundEndCaps = localDashPattern == null;

  // If we have a dash pattern, the normal stroke width makes them look
  // strangely tall.
  final localStrokeWidthPx = localDashPattern == null
      ? getSolidStrokeWidthPx(strokeWidthPx ?? strokeWidth)
      : strokeWidthForNonRoundedEndCaps;

  // Adjust the length so the total width includes the rounded pixels.
  // Otherwise the cap is drawn past the bounds and appears to be cut off.
  // If bounds is not long enough to accommodate the line, do not adjust.
  var left = bounds.left;
  var right = bounds.right;

  if (roundEndCaps && bounds.width >= minLengthToRoundCaps) {
    left += roundEndCapsPixels;
    right -= roundEndCapsPixels;
  }

  // TODO: Pass in strokeWidth, roundEndCaps, and dashPattern from
  // line renderer config.
  canvas.drawLine(
    points: [Point(left, centerHeight), Point(right, centerHeight)],
    dashPattern: localDashPattern,
    fill: getSolidFillColor(fillColor),
    roundEndCaps: roundEndCaps,
    stroke: strokeColor,
    strokeWidthPx: localStrokeWidthPx,
  );
}