diff --git a/lib/src/animated_circular_chart.dart b/lib/src/animated_circular_chart.dart index 47cef1f..265e09f 100644 --- a/lib/src/animated_circular_chart.dart +++ b/lib/src/animated_circular_chart.dart @@ -14,6 +14,15 @@ enum CircularChartType { Radial, } +/// Determines how the ends of a chart's segments should be drawn. +enum SegmentEdgeStyle { + /// Segments begin and end with a flat edge. + Flat, + + /// Segments begin and end with a semi-circle. + Round, +} + class AnimatedCircularChart extends StatefulWidget { AnimatedCircularChart({ Key key, @@ -26,8 +35,8 @@ class AnimatedCircularChart extends StatefulWidget { this.startAngle = _kStartAngle, this.holeLabel, this.labelStyle, - }) - : assert(size != null), + this.edgeStyle = SegmentEdgeStyle.Flat, + }) : assert(size != null), super(key: key); /// The size of the bounding box this chart will be constrained to. @@ -91,6 +100,11 @@ class AnimatedCircularChart extends StatefulWidget { /// [ThemeData.textTheme.body2] text style. final TextStyle labelStyle; + /// The type of segment edges to be drawn. + /// + /// Defaults to [SegmentEdgeStyle.Flat]. + final SegmentEdgeStyle edgeStyle; + /// The state from the closest instance of this class that encloses the given context. /// /// This method is typically used by [AnimatedCircularChart] item widgets that insert or @@ -165,6 +179,7 @@ class AnimatedCircularChartState extends State percentageValues: widget.percentageValues, holeRadius: widget.holeRadius, startAngle: widget.startAngle, + edgeStyle: widget.edgeStyle, ), ); _animation.forward(); @@ -231,6 +246,7 @@ class AnimatedCircularChartState extends State percentageValues: widget.percentageValues, holeRadius: widget.holeRadius, startAngle: widget.startAngle, + edgeStyle: widget.edgeStyle, ), ); _animation.forward(from: 0.0); diff --git a/lib/src/circular_chart.dart b/lib/src/circular_chart.dart index a340112..c6ae25c 100644 --- a/lib/src/circular_chart.dart +++ b/lib/src/circular_chart.dart @@ -9,10 +9,15 @@ import 'package:flutter_circular_chart/src/tween.dart'; class CircularChart { static const double _kStackWidthFraction = 0.75; - CircularChart(this.stacks, this.chartType); + CircularChart( + this.stacks, + this.chartType, { + this.edgeStyle = SegmentEdgeStyle.Flat, + }); final List stacks; final CircularChartType chartType; + final SegmentEdgeStyle edgeStyle; factory CircularChart.empty({@required CircularChartType chartType}) { return new CircularChart([], chartType); @@ -27,6 +32,7 @@ class CircularChart { Map stackRanks, Map entryRanks, double holeRadius, + SegmentEdgeStyle edgeStyle, }) { final double _holeRadius = holeRadius ?? size.width / (2 + data.length); final double stackDistance = @@ -47,7 +53,7 @@ class CircularChart { ), ); - return new CircularChart(stacks, chartType); + return new CircularChart(stacks, chartType, edgeStyle: edgeStyle); } } @@ -63,5 +69,6 @@ class CircularChartTween extends Tween { CircularChart lerp(double t) => new CircularChart( _stacksTween.lerp(t), begin.chartType, + edgeStyle: end.edgeStyle, ); }