diff --git a/README.md b/README.md index 96eff50..4cf3df8 100644 --- a/README.md +++ b/README.md @@ -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 _chartKey = new GlobalKey(); +final GlobalKey _chartKey = GlobalKey(); ``` Create chart data entry objects: ```dart List data = [ - new CircularStackEntry( + CircularStackEntry( [ - 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 nextData = [ - new CircularStackEntry( + CircularStackEntry( [ - 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: [ - new CircularStackEntry( + CircularStackEntry( [ - 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: [ - new CircularStackEntry( + CircularStackEntry( [ - new CircularSegmentEntry( + CircularSegmentEntry( 33.33, Colors.blue[400], rankKey: 'completed', ), - new CircularSegmentEntry( + CircularSegmentEntry( 66.67, Colors.blueGrey[600], rankKey: 'remaining', diff --git a/example/animated_pie_chart_example.dart b/example/animated_pie_chart_example.dart index 8d09159..a780596 100644 --- a/example/animated_pie_chart_example.dart +++ b/example/animated_pie_chart_example.dart @@ -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> _quarterlyProfitPieData = [ [ - new CircularStackEntry( + CircularStackEntry( [ - 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', ), ], [ - new CircularStackEntry( + CircularStackEntry( [ - 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', ), ], [ - new CircularStackEntry( + CircularStackEntry( [ - 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> _quarterlyProfitPieData = [ class AnimatedPieChartExample extends StatefulWidget { @override - _AnimatedPieChartExampleState createState() => - new _AnimatedPieChartExampleState(); + _AnimatedPieChartExampleState createState() => _AnimatedPieChartExampleState(); } class _AnimatedPieChartExampleState extends State { - final GlobalKey _chartKey = - new GlobalKey(); + final GlobalKey _chartKey = GlobalKey(); final _chartSize = const Size(300.0, 300.0); int sampleIndex = 0; @@ -65,20 +63,20 @@ class _AnimatedPieChartExampleState extends State { @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, ), ); diff --git a/example/animated_radial_chart_example.dart b/example/animated_radial_chart_example.dart index 560c9ff..495e4d7 100644 --- a/example/animated_radial_chart_example.dart +++ b/example/animated_radial_chart_example.dart @@ -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 { - final GlobalKey _chartKey = - new GlobalKey(); +class _AnimatedRadialChartExampleState extends State { + final GlobalKey _chartKey = GlobalKey(); final _chartSize = const Size(200.0, 200.0); double value = 50.0; @@ -48,9 +45,9 @@ class _AnimatedRadialChartExampleState labelColor = dialColor; List data = [ - new CircularStackEntry( + CircularStackEntry( [ - 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( [ - 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: [ - 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: [ - 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(), diff --git a/example/animated_random_radial_chart_example.dart b/example/animated_random_radial_chart_example.dart index f883661..eecb2a4 100644 --- a/example/animated_random_radial_chart_example.dart +++ b/example/animated_random_radial_chart_example.dart @@ -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 { - final GlobalKey _chartKey = - new GlobalKey(); +class _RandomizedRadialChartExampleState extends State { + final GlobalKey _chartKey = GlobalKey(); final _chartSize = const Size(300.0, 300.0); - final Math.Random random = new Math.Random(); + final Math.Random random = Math.Random(); List data; @override @@ -41,13 +38,13 @@ class _RandomizedRadialChartExampleState List _generateRandomData() { int stackCount = random.nextInt(10); - List data = new List.generate(stackCount, (i) { + List data = List.generate(stackCount, (i) { int segCount = random.nextInt(10); - List segments = new List.generate(segCount, (j) { + List 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), ), diff --git a/example/color_palette.dart b/example/color_palette.dart index e759fec..cd6884c 100644 --- a/example/color_palette.dart +++ b/example/color_palette.dart @@ -3,7 +3,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; class ColorPalette { - static final ColorPalette primary = new ColorPalette([ + static final ColorPalette primary = ColorPalette([ Colors.blue[400], Colors.blue[200], Colors.red[400], diff --git a/lib/src/animated_circular_chart.dart b/lib/src/animated_circular_chart.dart index 17e0af0..16475f7 100644 --- a/lib/src/animated_circular_chart.dart +++ b/lib/src/animated_circular_chart.dart @@ -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()); + final AnimatedCircularChartState result = + context.findAncestorStateOfType(); 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 chartKey = new GlobalKey(); +/// GlobalKey chartKey = GlobalKey(); /// ... -/// new AnimatedCircularChart(key: chartKey, ...); +/// AnimatedCircularChart(key: chartKey, ...); /// ... /// chartKey.currentState.updateData(newData); /// ``` @@ -156,21 +155,21 @@ class AnimatedCircularChartState extends State AnimationController _animation; final Map _stackRanks = {}; final Map _entryRanks = {}; - 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 @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 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 _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 @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, ), diff --git a/lib/src/circular_chart.dart b/lib/src/circular_chart.dart index 772190b..5383a37 100644 --- a/lib/src/circular_chart.dart +++ b/lib/src/circular_chart.dart @@ -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([], chartType); + return CircularChart([], 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 stacks = new List.generate( + List stacks = List.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 { CircularChartTween(CircularChart begin, CircularChart end) - : _stacksTween = - new MergeTween(begin.stacks, end.stacks), + : _stacksTween = MergeTween(begin.stacks, end.stacks), super(begin: begin, end: end); final MergeTween _stacksTween; @override - CircularChart lerp(double t) => new CircularChart( + CircularChart lerp(double t) => CircularChart( _stacksTween.lerp(t), begin.chartType, edgeStyle: end.edgeStyle, diff --git a/lib/src/painter.dart b/lib/src/painter.dart index 83efd39..b4ee61a 100644 --- a/lib/src/painter.dart +++ b/lib/src/painter.dart @@ -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 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, diff --git a/lib/src/segment.dart b/lib/src/segment.dart index c6486e2..24ff8cc 100644 --- a/lib/src/segment.dart +++ b/lib/src/segment.dart @@ -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(this.rank, this.sweepAngle, this.color); @@ -11,20 +11,19 @@ class CircularChartSegment extends MergeTweenable { 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 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 { } class CircularChartSegmentTween extends Tween { - 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); } diff --git a/lib/src/stack.dart b/lib/src/stack.dart index 70b6757..bfdcd07 100644 --- a/lib/src/stack.dart +++ b/lib/src/stack.dart @@ -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 { ); double previousSweepAngle = 0.0; - List segments = - new List.generate(entries.length, (i) { - double sweepAngle = - (entries[i].value / valueSum * _kMaxAngle) + previousSweepAngle; + List segments = List.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 { } @override - CircularChartStack get empty => new CircularChartStack( - rank, radius, 0.0, startAngle, []); + CircularChartStack get empty => + CircularChartStack(rank, radius, 0.0, startAngle, []); @override bool operator <(CircularChartStack other) => rank < other.rank; @override Tween tweenTo(CircularChartStack other) => - new CircularChartStackTween(this, other); + CircularChartStackTween(this, other); } class CircularChartStackTween extends Tween { CircularChartStackTween(CircularChartStack begin, CircularChartStack end) - : _circularSegmentsTween = - new MergeTween(begin.segments, end.segments), + : _circularSegmentsTween = MergeTween(begin.segments, end.segments), super(begin: begin, end: end) { assert(begin.rank == end.rank); } @@ -80,7 +77,7 @@ class CircularChartStackTween extends Tween { final MergeTween _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), diff --git a/lib/src/tween.dart b/lib/src/tween.dart index 9debe26..13ed45c 100644 --- a/lib/src/tween.dart +++ b/lib/src/tween.dart @@ -32,7 +32,7 @@ class MergeTween> extends Tween> { final _tweens = >[]; @override - List lerp(double t) => new List.generate( + List lerp(double t) => List.generate( _tweens.length, (i) => _tweens[i].lerp(t), ); diff --git a/pubspec.yaml b/pubspec.yaml index 858b281..4107e0e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/flutter_circular_chart_test.dart b/test/flutter_circular_chart_test.dart deleted file mode 100644 index 49ffe1b..0000000 --- a/test/flutter_circular_chart_test.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:test/test.dart'; - -import 'package:flutter_circular_chart/flutter_circular_chart.dart'; - -void main() { - -}