diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6491a0e..198944148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * [IMPROVEMENT] Added `getTouchLineStart` and `getTouchLineEnd` in [LineTouchData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#linetouchdata-read-about-touch-handling) to give more customizability over showing the touch lines. see [SampleLineChart9](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#sample-8-source-code). * [IMPROVEMENT] Enabled `sectionsSpace` in PieChart for the web. * [IMPROVEMENT] Added [Makefile](https://makefiletutorial.com) commands which makes it comfortable for verifying your code before push (It is related to contributors, red more about it in [CONTRIBUTING.md](https://github.com/imaNNeoFighT/fl_chart/blob/master/CONTRIBUTING.md)). +* [IMPROVEMENT] Added `FlDotCrossPainter` which extends `FlDotPainter` to paint X marks on line chart spots. * [BUGFIX] Fixed some bugs on drawing PieChart (for example when we have only one section), #582, * [BREAKING] Border of pieChart now is hide by default (you can show it using `borderData: FlBorderData(show: true)`. * [BREAKING] You cannot set `0` value on [PieChartSectionData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/pie_chart.md#piechartsectiondata).value anymore, instead remove it from list. diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index bf5e79fdc..4011840a2 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -923,6 +923,62 @@ class FlDotSquarePainter extends FlDotPainter { ]; } +/// This class is an implementation of a [FlDotPainter] that draws +/// a cross (X mark) shape +class FlDotCrossPainter extends FlDotPainter { + /// The fill color to use for the X mark + Color color; + + /// Determines size (width and height) of shape. + double size; + + /// Determines thickness of X mark. + double width; + + /// The [color] and [width] properties determines the color and thickness of the cross shape, + /// [size] determines the width and height of the shape. + FlDotCrossPainter({ + Color? color, + double? size, + double? width, + }) : color = color ?? Colors.green, + size = size ?? 8.0, + width = width ?? 2.0; + + /// Implementation of the parent class to draw the cross + @override + void draw(Canvas canvas, FlSpot spot, Offset offsetInCanvas) { + final path = Path() + ..moveTo(offsetInCanvas.dx, offsetInCanvas.dy) + ..relativeMoveTo(-size / 2, -size / 2) + ..relativeLineTo(size, size) + ..moveTo(offsetInCanvas.dx, offsetInCanvas.dy) + ..relativeMoveTo(size / 2, -size / 2) + ..relativeLineTo(-size, size); + + final paint = Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = width + ..color = color; + + canvas.drawPath(path, paint); + } + + /// Implementation of the parent class to get the size of the circle + @override + Size getSize(FlSpot spot) { + return Size(size, size); + } + + /// Used for equality check, see [EquatableMixin]. + @override + List get props => [ + color, + size, + width, + ]; +} + /// It determines showing or hiding [FlDotData] on the spots. /// /// It gives you the checking [FlSpot] and you should decide to