Skip to content

Commit

Permalink
Add FlDotCrossPainter
Browse files Browse the repository at this point in the history
  • Loading branch information
imaN Khoshabi committed Apr 1, 2021
1 parent 634843a commit d438b2e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
56 changes: 56 additions & 0 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object?> 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
Expand Down

0 comments on commit d438b2e

Please sign in to comment.