Add edgeStyle to AnimatedCircularChart and CircularChart

This commit is contained in:
Victor Choueiri 2018-05-09 21:24:40 +03:00 committed by Victor Choueiri
parent c98ed04297
commit de9f37138a
2 changed files with 27 additions and 4 deletions

View File

@ -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<AnimatedCircularChart>
percentageValues: widget.percentageValues,
holeRadius: widget.holeRadius,
startAngle: widget.startAngle,
edgeStyle: widget.edgeStyle,
),
);
_animation.forward();
@ -231,6 +246,7 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
percentageValues: widget.percentageValues,
holeRadius: widget.holeRadius,
startAngle: widget.startAngle,
edgeStyle: widget.edgeStyle,
),
);
_animation.forward(from: 0.0);

View File

@ -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<CircularChartStack> stacks;
final CircularChartType chartType;
final SegmentEdgeStyle edgeStyle;
factory CircularChart.empty({@required CircularChartType chartType}) {
return new CircularChart(<CircularChartStack>[], chartType);
@ -27,6 +32,7 @@ class CircularChart {
Map<String, int> stackRanks,
Map<String, int> 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> {
CircularChart lerp(double t) => new CircularChart(
_stacksTween.lerp(t),
begin.chartType,
edgeStyle: end.edgeStyle,
);
}