general update

This commit is contained in:
Gustavo Rodrigues 2021-03-08 12:37:23 -05:00
parent 6755e96f06
commit 43a1d9b47d
13 changed files with 158 additions and 191 deletions

View File

@ -31,25 +31,25 @@ Install the latest version [from pub](https://pub.dartlang.org/packages/flutter_
Import the package:
```dart
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
import 'package:flutter_circular_chart_two/flutter_circular_chart.dart';
```
Create a [GlobalKey](https://docs.flutter.io/flutter/widgets/GlobalKey-class.html) to be able to access the chart and update its data:
```dart
final GlobalKey<AnimatedCircularChartState> _chartKey = new GlobalKey<AnimatedCircularChartState>();
final GlobalKey<AnimatedCircularChartState> _chartKey = GlobalKey<AnimatedCircularChartState>();
```
Create chart data entry objects:
```dart
List<CircularStackEntry> data = <CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(500.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(1000.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
CircularSegmentEntry(500.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(1000.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
@ -61,7 +61,7 @@ Create an `AnimatedCircularChart`, passing it the `_chartKey` and initial `data`
```dart
@override
Widget build(BuildContext context) {
return new AnimatedCircularChart(
return AnimatedCircularChart(
key: _chartKey,
size: const Size(300.0, 300.0),
initialChartData: data,
@ -75,12 +75,12 @@ Call `updateData` to animate the chart:
```dart
void _cycleSamples() {
List<CircularStackEntry> nextData = <CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(1500.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(750.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
CircularSegmentEntry(1500.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(750.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
@ -103,18 +103,18 @@ void _cycleSamples() {
Example:
```dart
new AnimatedCircularChart(
AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: <CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(
CircularSegmentEntry(
33.33,
Colors.blue[400],
rankKey: 'completed',
),
new CircularSegmentEntry(
CircularSegmentEntry(
66.67,
Colors.blueGrey[600],
rankKey: 'remaining',
@ -126,7 +126,7 @@ new AnimatedCircularChart(
chartType: CircularChartType.Radial,
percentageValues: true,
holeLabel: '1/3',
labelStyle: new TextStyle(
labelStyle: TextStyle(
color: Colors.blueGrey[600],
fontWeight: FontWeight.bold,
fontSize: 24.0,
@ -152,18 +152,18 @@ new AnimatedCircularChart(
Example:
```dart
new AnimatedCircularChart(
AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: <CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(
CircularSegmentEntry(
33.33,
Colors.blue[400],
rankKey: 'completed',
),
new CircularSegmentEntry(
CircularSegmentEntry(
66.67,
Colors.blueGrey[600],
rankKey: 'remaining',

View File

@ -1,42 +1,42 @@
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
import 'package:flutter_circular_chart_two/flutter_circular_chart.dart';
void main() {
runApp(new MaterialApp(
home: new AnimatedPieChartExample(),
runApp(MaterialApp(
home: AnimatedPieChartExample(),
));
}
final List<List<CircularStackEntry>> _quarterlyProfitPieData = [
<CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(500.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(1000.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
CircularSegmentEntry(500.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(1000.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
],
<CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(1500.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(750.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
CircularSegmentEntry(1500.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(750.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(2000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(1000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
],
<CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(1800.0, Colors.red[200], rankKey: 'Q1'),
new CircularSegmentEntry(2900.0, Colors.green[200], rankKey: 'Q2'),
new CircularSegmentEntry(4000.0, Colors.blue[200], rankKey: 'Q3'),
new CircularSegmentEntry(7000.0, Colors.yellow[200], rankKey: 'Q4'),
CircularSegmentEntry(1800.0, Colors.red[200], rankKey: 'Q1'),
CircularSegmentEntry(2900.0, Colors.green[200], rankKey: 'Q2'),
CircularSegmentEntry(4000.0, Colors.blue[200], rankKey: 'Q3'),
CircularSegmentEntry(7000.0, Colors.yellow[200], rankKey: 'Q4'),
],
rankKey: 'Quarterly Profits',
),
@ -45,13 +45,11 @@ final List<List<CircularStackEntry>> _quarterlyProfitPieData = [
class AnimatedPieChartExample extends StatefulWidget {
@override
_AnimatedPieChartExampleState createState() =>
new _AnimatedPieChartExampleState();
_AnimatedPieChartExampleState createState() => _AnimatedPieChartExampleState();
}
class _AnimatedPieChartExampleState extends State<AnimatedPieChartExample> {
final GlobalKey<AnimatedCircularChartState> _chartKey =
new GlobalKey<AnimatedCircularChartState>();
final GlobalKey<AnimatedCircularChartState> _chartKey = GlobalKey<AnimatedCircularChartState>();
final _chartSize = const Size(300.0, 300.0);
int sampleIndex = 0;
@ -65,20 +63,20 @@ class _AnimatedPieChartExampleState extends State<AnimatedPieChartExample> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
return Scaffold(
appBar: AppBar(
title: const Text('Quarterly Profit'),
),
body: new Center(
child: new AnimatedCircularChart(
body: Center(
child: AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: _quarterlyProfitPieData[0],
chartType: CircularChartType.Pie,
),
),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.refresh),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.refresh),
onPressed: _cycleSamples,
),
);

View File

@ -1,22 +1,19 @@
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
import 'package:flutter_circular_chart_two/flutter_circular_chart.dart';
void main() {
runApp(new MaterialApp(
home: new AnimatedRadialChartExample(),
runApp(MaterialApp(
home: AnimatedRadialChartExample(),
));
}
class AnimatedRadialChartExample extends StatefulWidget {
@override
_AnimatedRadialChartExampleState createState() =>
new _AnimatedRadialChartExampleState();
_AnimatedRadialChartExampleState createState() => _AnimatedRadialChartExampleState();
}
class _AnimatedRadialChartExampleState
extends State<AnimatedRadialChartExample> {
final GlobalKey<AnimatedCircularChartState> _chartKey =
new GlobalKey<AnimatedCircularChartState>();
class _AnimatedRadialChartExampleState extends State<AnimatedRadialChartExample> {
final GlobalKey<AnimatedCircularChartState> _chartKey = GlobalKey<AnimatedCircularChartState>();
final _chartSize = const Size(200.0, 200.0);
double value = 50.0;
@ -48,9 +45,9 @@ class _AnimatedRadialChartExampleState
labelColor = dialColor;
List<CircularStackEntry> data = <CircularStackEntry>[
new CircularStackEntry(
CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(
CircularSegmentEntry(
value,
dialColor,
rankKey: 'percentage',
@ -63,9 +60,9 @@ class _AnimatedRadialChartExampleState
if (value > 100) {
labelColor = Colors.green[200];
data.add(new CircularStackEntry(
data.add(CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(
CircularSegmentEntry(
value - 100,
Colors.green[200],
rankKey: 'percentage',
@ -80,20 +77,17 @@ class _AnimatedRadialChartExampleState
@override
Widget build(BuildContext context) {
TextStyle _labelStyle = Theme
.of(context)
.textTheme
.title
.merge(new TextStyle(color: labelColor));
TextStyle _labelStyle =
Theme.of(context).textTheme.headline6.merge(TextStyle(color: labelColor));
return new Scaffold(
appBar: new AppBar(
return Scaffold(
appBar: AppBar(
title: const Text('Percentage Dial'),
),
body: new Column(
body: Column(
children: <Widget>[
new Container(
child: new AnimatedCircularChart(
Container(
child: AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: _generateChartData(value),
@ -104,17 +98,17 @@ class _AnimatedRadialChartExampleState
labelStyle: _labelStyle,
),
),
new Row(
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
new RaisedButton(
RaisedButton(
onPressed: _decrement,
child: const Icon(Icons.remove),
shape: const CircleBorder(),
color: Colors.red[200],
textColor: Colors.white,
),
new RaisedButton(
RaisedButton(
onPressed: _increment,
child: const Icon(Icons.add),
shape: const CircleBorder(),

View File

@ -1,27 +1,24 @@
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
import 'package:flutter_circular_chart_two/flutter_circular_chart.dart';
import 'dart:math' as Math;
import 'color_palette.dart';
void main() {
runApp(new MaterialApp(
home: new RandomizedRadialChartExample(),
runApp(MaterialApp(
home: RandomizedRadialChartExample(),
));
}
class RandomizedRadialChartExample extends StatefulWidget {
@override
_RandomizedRadialChartExampleState createState() =>
new _RandomizedRadialChartExampleState();
_RandomizedRadialChartExampleState createState() => _RandomizedRadialChartExampleState();
}
class _RandomizedRadialChartExampleState
extends State<RandomizedRadialChartExample> {
final GlobalKey<AnimatedCircularChartState> _chartKey =
new GlobalKey<AnimatedCircularChartState>();
class _RandomizedRadialChartExampleState extends State<RandomizedRadialChartExample> {
final GlobalKey<AnimatedCircularChartState> _chartKey = GlobalKey<AnimatedCircularChartState>();
final _chartSize = const Size(300.0, 300.0);
final Math.Random random = new Math.Random();
final Math.Random random = Math.Random();
List<CircularStackEntry> data;
@override
@ -41,13 +38,13 @@ class _RandomizedRadialChartExampleState
List<CircularStackEntry> _generateRandomData() {
int stackCount = random.nextInt(10);
List<CircularStackEntry> data = new List.generate(stackCount, (i) {
List<CircularStackEntry> data = List.generate(stackCount, (i) {
int segCount = random.nextInt(10);
List<CircularSegmentEntry> segments = new List.generate(segCount, (j) {
List<CircularSegmentEntry> segments = List.generate(segCount, (j) {
Color randomColor = ColorPalette.primary.random(random);
return new CircularSegmentEntry(random.nextDouble(), randomColor);
return CircularSegmentEntry(random.nextDouble(), randomColor);
});
return new CircularStackEntry(segments);
return CircularStackEntry(segments);
});
return data;
@ -55,19 +52,19 @@ class _RandomizedRadialChartExampleState
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
return Scaffold(
appBar: AppBar(
title: const Text('Randomized radial data'),
),
body: new Center(
child: new AnimatedCircularChart(
body: Center(
child: AnimatedCircularChart(
key: _chartKey,
size: _chartSize,
initialChartData: data,
chartType: CircularChartType.Radial,
),
),
floatingActionButton: new FloatingActionButton(
floatingActionButton: FloatingActionButton(
onPressed: _randomize,
child: const Icon(Icons.refresh),
),

View File

@ -3,7 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart';
class ColorPalette {
static final ColorPalette primary = new ColorPalette(<Color>[
static final ColorPalette primary = ColorPalette(<Color>[
Colors.blue[400],
Colors.blue[200],
Colors.red[400],

View File

@ -1,8 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/src/circular_chart.dart';
import 'package:flutter_circular_chart/src/entry.dart';
import 'package:flutter_circular_chart/src/painter.dart';
import 'package:flutter_circular_chart_two/src/circular_chart.dart';
import 'package:flutter_circular_chart_two/src/entry.dart';
import 'package:flutter_circular_chart_two/src/painter.dart';
// The default chart tween animation duration.
const Duration _kDuration = const Duration(milliseconds: 300);
@ -113,17 +113,16 @@ class AnimatedCircularChart extends StatefulWidget {
/// ```dart
/// AnimatedCircularChartState animatedCircularChart = AnimatedCircularChart.of(context);
/// ```
static AnimatedCircularChartState of(BuildContext context,
{bool nullOk: false}) {
static AnimatedCircularChartState of(BuildContext context, {bool nullOk: false}) {
assert(context != null);
assert(nullOk != null);
final AnimatedCircularChartState result = context
.ancestorStateOfType(const TypeMatcher<AnimatedCircularChartState>());
final AnimatedCircularChartState result =
context.findAncestorStateOfType<AnimatedCircularChartState>();
if (nullOk || result != null) return result;
throw new FlutterError(
throw FlutterError(
'AnimatedCircularChart.of() called with a context that does not contain a AnimatedCircularChart.\n'
'No AnimatedCircularChart ancestor could be found starting from the context that was passed to AnimatedCircularChart.of(). '
'This can happen when the context provided is from the same StatefulWidget that '
@ -133,7 +132,7 @@ class AnimatedCircularChart extends StatefulWidget {
}
@override
AnimatedCircularChartState createState() => new AnimatedCircularChartState();
AnimatedCircularChartState createState() => AnimatedCircularChartState();
}
/// The state for a circular chart that animates when its data is updated.
@ -144,9 +143,9 @@ class AnimatedCircularChart extends StatefulWidget {
/// can refer to the [AnimatedCircularChart]'s state with a global key:
///
/// ```dart
/// GlobalKey<AnimatedCircularChartState> chartKey = new GlobalKey<AnimatedCircularChartState>();
/// GlobalKey<AnimatedCircularChartState> chartKey = GlobalKey<AnimatedCircularChartState>();
/// ...
/// new AnimatedCircularChart(key: chartKey, ...);
/// AnimatedCircularChart(key: chartKey, ...);
/// ...
/// chartKey.currentState.updateData(newData);
/// ```
@ -156,21 +155,21 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
AnimationController _animation;
final Map<String, int> _stackRanks = <String, int>{};
final Map<String, int> _entryRanks = <String, int>{};
final TextPainter _labelPainter = new TextPainter();
final TextPainter _labelPainter = TextPainter();
@override
void initState() {
super.initState();
_animation = new AnimationController(
_animation = AnimationController(
duration: widget.duration,
vsync: this,
);
_assignRanks(widget.initialChartData);
_tween = new CircularChartTween(
new CircularChart.empty(chartType: widget.chartType),
new CircularChart.fromData(
_tween = CircularChartTween(
CircularChart.empty(chartType: widget.chartType),
CircularChart.fromData(
size: widget.size,
data: widget.initialChartData,
chartType: widget.chartType,
@ -188,8 +187,7 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
@override
void didUpdateWidget(AnimatedCircularChart oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.holeLabel != widget.holeLabel ||
oldWidget.labelStyle != widget.labelStyle) {
if (oldWidget.holeLabel != widget.holeLabel || oldWidget.labelStyle != widget.labelStyle) {
_updateLabelPainter();
}
}
@ -217,10 +215,9 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
void _updateLabelPainter() {
if (widget.holeLabel != null) {
TextStyle _labelStyle =
widget.labelStyle ?? Theme.of(context).textTheme.body2;
TextStyle _labelStyle = widget.labelStyle ?? Theme.of(context).textTheme.bodyText1;
_labelPainter
..text = new TextSpan(style: _labelStyle, text: widget.holeLabel)
..text = TextSpan(style: _labelStyle, text: widget.holeLabel)
..textDirection = Directionality.of(context)
..textScaleFactor = MediaQuery.of(context).textScaleFactor
..layout();
@ -235,9 +232,9 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
_assignRanks(data);
setState(() {
_tween = new CircularChartTween(
_tween = CircularChartTween(
_tween.evaluate(_animation),
new CircularChart.fromData(
CircularChart.fromData(
size: widget.size,
data: data,
chartType: widget.chartType,
@ -255,9 +252,9 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
@override
Widget build(BuildContext context) {
return new CustomPaint(
return CustomPaint(
size: widget.size,
painter: new AnimatedCircularChartPainter(
painter: AnimatedCircularChartPainter(
_tween.animate(_animation),
widget.holeLabel != null ? _labelPainter : null,
),

View File

@ -1,10 +1,10 @@
import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/src/animated_circular_chart.dart';
import 'package:flutter_circular_chart/src/entry.dart';
import 'package:flutter_circular_chart/src/stack.dart';
import 'package:flutter_circular_chart/src/tween.dart';
import 'package:flutter_circular_chart_two/src/animated_circular_chart.dart';
import 'package:flutter_circular_chart_two/src/entry.dart';
import 'package:flutter_circular_chart_two/src/stack.dart';
import 'package:flutter_circular_chart_two/src/tween.dart';
class CircularChart {
static const double _kStackWidthFraction = 0.75;
@ -20,7 +20,7 @@ class CircularChart {
final SegmentEdgeStyle edgeStyle;
factory CircularChart.empty({@required CircularChartType chartType}) {
return new CircularChart(<CircularChartStack>[], chartType);
return CircularChart(<CircularChartStack>[], chartType);
}
factory CircularChart.fromData({
@ -35,38 +35,36 @@ class CircularChart {
SegmentEdgeStyle edgeStyle,
}) {
final double _holeRadius = holeRadius ?? size.width / (2 + data.length);
final double stackDistance =
(size.width / 2 - _holeRadius) / (2 + data.length);
final double stackDistance = (size.width / 2 - _holeRadius) / (2 + data.length);
final double stackWidth = stackDistance * _kStackWidthFraction;
final double startRadius = stackDistance + _holeRadius;
List<CircularChartStack> stacks = new List<CircularChartStack>.generate(
List<CircularChartStack> stacks = List<CircularChartStack>.generate(
data.length,
(i) => new CircularChartStack.fromData(
stackRanks[data[i].rankKey] ?? i,
data[i].entries,
entryRanks,
percentageValues,
startRadius + i * stackDistance,
stackWidth,
startAngle,
),
(i) => CircularChartStack.fromData(
stackRanks[data[i].rankKey] ?? i,
data[i].entries,
entryRanks,
percentageValues,
startRadius + i * stackDistance,
stackWidth,
startAngle,
),
);
return new CircularChart(stacks, chartType, edgeStyle: edgeStyle);
return CircularChart(stacks, chartType, edgeStyle: edgeStyle);
}
}
class CircularChartTween extends Tween<CircularChart> {
CircularChartTween(CircularChart begin, CircularChart end)
: _stacksTween =
new MergeTween<CircularChartStack>(begin.stacks, end.stacks),
: _stacksTween = MergeTween<CircularChartStack>(begin.stacks, end.stacks),
super(begin: begin, end: end);
final MergeTween<CircularChartStack> _stacksTween;
@override
CircularChart lerp(double t) => new CircularChart(
CircularChart lerp(double t) => CircularChart(
_stacksTween.lerp(t),
begin.chartType,
edgeStyle: end.edgeStyle,

View File

@ -1,13 +1,12 @@
import 'dart:math' as Math;
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/src/animated_circular_chart.dart';
import 'package:flutter_circular_chart/src/circular_chart.dart';
import 'package:flutter_circular_chart/src/stack.dart';
import 'package:flutter_circular_chart_two/src/animated_circular_chart.dart';
import 'package:flutter_circular_chart_two/src/circular_chart.dart';
import 'package:flutter_circular_chart_two/src/stack.dart';
class AnimatedCircularChartPainter extends CustomPainter {
AnimatedCircularChartPainter(this.animation, this.labelPainter)
: super(repaint: animation);
AnimatedCircularChartPainter(this.animation, this.labelPainter) : super(repaint: animation);
final Animation<CircularChart> animation;
final TextPainter labelPainter;
@ -44,7 +43,7 @@ void _paintLabel(Canvas canvas, Size size, TextPainter labelPainter) {
if (labelPainter != null) {
labelPainter.paint(
canvas,
new Offset(
Offset(
size.width / 2 - labelPainter.width / 2,
size.height / 2 - labelPainter.height / 2,
),
@ -53,13 +52,10 @@ void _paintLabel(Canvas canvas, Size size, TextPainter labelPainter) {
}
void _paintChart(Canvas canvas, Size size, CircularChart chart) {
final Paint segmentPaint = new Paint()
..style = chart.chartType == CircularChartType.Radial
? PaintingStyle.stroke
: PaintingStyle.fill
..strokeCap = chart.edgeStyle == SegmentEdgeStyle.round
? StrokeCap.round
: StrokeCap.butt;
final Paint segmentPaint = Paint()
..style =
chart.chartType == CircularChartType.Radial ? PaintingStyle.stroke : PaintingStyle.fill
..strokeCap = chart.edgeStyle == SegmentEdgeStyle.round ? StrokeCap.round : StrokeCap.butt;
for (final CircularChartStack stack in chart.stacks) {
for (final segment in stack.segments) {
@ -67,8 +63,8 @@ void _paintChart(Canvas canvas, Size size, CircularChart chart) {
segmentPaint.strokeWidth = stack.width;
canvas.drawArc(
new Rect.fromCircle(
center: new Offset(size.width / 2, size.height / 2),
Rect.fromCircle(
center: Offset(size.width / 2, size.height / 2),
radius: stack.radius,
),
stack.startAngle * _kRadiansPerDegree,

View File

@ -1,7 +1,7 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/src/tween.dart';
import 'package:flutter_circular_chart_two/src/tween.dart';
class CircularChartSegment extends MergeTweenable<CircularChartSegment> {
CircularChartSegment(this.rank, this.sweepAngle, this.color);
@ -11,20 +11,19 @@ class CircularChartSegment extends MergeTweenable<CircularChartSegment> {
final Color color;
@override
CircularChartSegment get empty => new CircularChartSegment(rank, 0.0, color);
CircularChartSegment get empty => CircularChartSegment(rank, 0.0, color);
@override
bool operator <(CircularChartSegment other) => rank < other.rank;
@override
Tween<CircularChartSegment> tweenTo(CircularChartSegment other) =>
new CircularChartSegmentTween(this, other);
CircularChartSegmentTween(this, other);
static CircularChartSegment lerp(
CircularChartSegment begin, CircularChartSegment end, double t) {
static CircularChartSegment lerp(CircularChartSegment begin, CircularChartSegment end, double t) {
assert(begin.rank == end.rank);
return new CircularChartSegment(
return CircularChartSegment(
begin.rank,
lerpDouble(begin.sweepAngle, end.sweepAngle, t),
Color.lerp(begin.color, end.color, t),
@ -33,13 +32,11 @@ class CircularChartSegment extends MergeTweenable<CircularChartSegment> {
}
class CircularChartSegmentTween extends Tween<CircularChartSegment> {
CircularChartSegmentTween(
CircularChartSegment begin, CircularChartSegment end)
CircularChartSegmentTween(CircularChartSegment begin, CircularChartSegment end)
: super(begin: begin, end: end) {
assert(begin.rank == end.rank);
}
@override
CircularChartSegment lerp(double t) =>
CircularChartSegment.lerp(begin, end, t);
CircularChartSegment lerp(double t) => CircularChartSegment.lerp(begin, end, t);
}

View File

@ -1,9 +1,9 @@
import 'dart:ui' show lerpDouble;
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/src/entry.dart';
import 'package:flutter_circular_chart/src/segment.dart';
import 'package:flutter_circular_chart/src/tween.dart';
import 'package:flutter_circular_chart_two/src/entry.dart';
import 'package:flutter_circular_chart_two/src/segment.dart';
import 'package:flutter_circular_chart_two/src/tween.dart';
const double _kMaxAngle = 360.0;
@ -39,16 +39,14 @@ class CircularChartStack implements MergeTweenable<CircularChartStack> {
);
double previousSweepAngle = 0.0;
List<CircularChartSegment> segments =
new List<CircularChartSegment>.generate(entries.length, (i) {
double sweepAngle =
(entries[i].value / valueSum * _kMaxAngle) + previousSweepAngle;
List<CircularChartSegment> segments = List<CircularChartSegment>.generate(entries.length, (i) {
double sweepAngle = (entries[i].value / valueSum * _kMaxAngle) + previousSweepAngle;
previousSweepAngle = sweepAngle;
int rank = entryRanks[entries[i].rankKey] ?? i;
return new CircularChartSegment(rank, sweepAngle, entries[i].color);
return CircularChartSegment(rank, sweepAngle, entries[i].color);
});
return new CircularChartStack(
return CircularChartStack(
stackRank,
startRadius,
stackWidth,
@ -58,21 +56,20 @@ class CircularChartStack implements MergeTweenable<CircularChartStack> {
}
@override
CircularChartStack get empty => new CircularChartStack(
rank, radius, 0.0, startAngle, <CircularChartSegment>[]);
CircularChartStack get empty =>
CircularChartStack(rank, radius, 0.0, startAngle, <CircularChartSegment>[]);
@override
bool operator <(CircularChartStack other) => rank < other.rank;
@override
Tween<CircularChartStack> tweenTo(CircularChartStack other) =>
new CircularChartStackTween(this, other);
CircularChartStackTween(this, other);
}
class CircularChartStackTween extends Tween<CircularChartStack> {
CircularChartStackTween(CircularChartStack begin, CircularChartStack end)
: _circularSegmentsTween =
new MergeTween<CircularChartSegment>(begin.segments, end.segments),
: _circularSegmentsTween = MergeTween<CircularChartSegment>(begin.segments, end.segments),
super(begin: begin, end: end) {
assert(begin.rank == end.rank);
}
@ -80,7 +77,7 @@ class CircularChartStackTween extends Tween<CircularChartStack> {
final MergeTween<CircularChartSegment> _circularSegmentsTween;
@override
CircularChartStack lerp(double t) => new CircularChartStack(
CircularChartStack lerp(double t) => CircularChartStack(
begin.rank,
lerpDouble(begin.radius, end.radius, t),
lerpDouble(begin.width, end.width, t),

View File

@ -32,7 +32,7 @@ class MergeTween<T extends MergeTweenable<T>> extends Tween<List<T>> {
final _tweens = <Tween<T>>[];
@override
List<T> lerp(double t) => new List.generate(
List<T> lerp(double t) => List.generate(
_tweens.length,
(i) => _tweens[i].lerp(t),
);

View File

@ -1,4 +1,4 @@
name: circular_chart
name: flutter_circular_chart_two
description: Animated radial and pie charts for Flutter. Forked from https://github.com/xqwzts/flutter_circular_chart
version: 0.1.0
author: Gustavo Bonifacio Rodrigues <omykronbr@gmail.com>

View File

@ -1,7 +0,0 @@
import 'package:test/test.dart';
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
void main() {
}