Skip to content

Commit

Permalink
Simplify the error indicator painter
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Jan 9, 2025
1 parent c135ce7 commit addafb8
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions lib/src/chart/base/axis_chart/axis_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1732,19 +1732,13 @@ abstract class FlSpotErrorRangePainter with EquatableMixin {
FlSpot origin,
Rect errorRelativeRect,
);

Size getSize(FlSpot spot);

Color get mainColor;

FlSpotErrorRangePainter lerp(
FlSpotErrorRangePainter a, FlSpotErrorRangePainter b, double t);
}

class FlSimpleErrorPainter extends FlSpotErrorRangePainter with EquatableMixin {
FlSimpleErrorPainter({
this.lineColor = Colors.white,
this.lineWidth = 1.0,
this.lineWidth = 2.0,
this.capLength = 8.0,
}) {
_linePaint = Paint()
..color = lineColor
Expand All @@ -1754,6 +1748,7 @@ class FlSimpleErrorPainter extends FlSpotErrorRangePainter with EquatableMixin {

final Color lineColor;
final double lineWidth;
final double capLength;

late final Paint _linePaint;

Expand Down Expand Up @@ -1792,59 +1787,43 @@ class FlSimpleErrorPainter extends FlSpotErrorRangePainter with EquatableMixin {
);

// Draw edge lines
const edgeLength = 8.0;
if (from.dx == to.dx) {
// Line is vertical
canvas
// draw top edge
// draw top cap
..drawLine(
Offset(from.dx - (edgeLength / 2), from.dy),
Offset(from.dx + (edgeLength / 2), from.dy),
Offset(from.dx - (capLength / 2), from.dy),
Offset(from.dx + (capLength / 2), from.dy),
_linePaint,
)
// draw bottom edge
// draw bottom cap
..drawLine(
Offset(to.dx - (edgeLength / 2), to.dy),
Offset(to.dx + (edgeLength / 2), to.dy),
Offset(to.dx - (capLength / 2), to.dy),
Offset(to.dx + (capLength / 2), to.dy),
_linePaint,
);
} else {
// // Line is horizontal
canvas
// draw left edge
// draw left cap
..drawLine(
Offset(from.dx, from.dy - (edgeLength / 2)),
Offset(from.dx, from.dy + (edgeLength / 2)),
Offset(from.dx, from.dy - (capLength / 2)),
Offset(from.dx, from.dy + (capLength / 2)),
_linePaint,
)
// draw right edge
// draw right cap
..drawLine(
Offset(to.dx, to.dy - (edgeLength / 2)),
Offset(to.dx, to.dy + (edgeLength / 2)),
Offset(to.dx, to.dy - (capLength / 2)),
Offset(to.dx, to.dy + (capLength / 2)),
_linePaint,
);
}
}

@override
Size getSize(FlSpot spot) {
return const Size(10, 10);
}

@override
FlSpotErrorRangePainter lerp(
FlSpotErrorRangePainter a,
FlSpotErrorRangePainter b,
double t,
) {
return this;
}

@override
Color get mainColor => Colors.black;

@override
List<Object?> get props => [
mainColor,
lineColor,
lineWidth,
capLength,
];
}

0 comments on commit addafb8

Please sign in to comment.