diff --git a/packages/pie_chart/CHANGELOG.md b/packages/edited_pie_chart/CHANGELOG.md similarity index 100% rename from packages/pie_chart/CHANGELOG.md rename to packages/edited_pie_chart/CHANGELOG.md diff --git a/packages/pie_chart/lib/pie_chart.dart b/packages/edited_pie_chart/lib/pie_chart.dart similarity index 100% rename from packages/pie_chart/lib/pie_chart.dart rename to packages/edited_pie_chart/lib/pie_chart.dart diff --git a/packages/pie_chart/lib/src/chart_painter.dart b/packages/edited_pie_chart/lib/src/chart_painter.dart similarity index 82% rename from packages/pie_chart/lib/src/chart_painter.dart rename to packages/edited_pie_chart/lib/src/chart_painter.dart index a382433d..0b422c4f 100644 --- a/packages/pie_chart/lib/src/chart_painter.dart +++ b/packages/edited_pie_chart/lib/src/chart_painter.dart @@ -63,23 +63,15 @@ class PieChartPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { final side = size.width < size.height ? size.width : size.height; - _prevAngle = this.initialAngle * math.pi / 180; + _prevAngle = initialAngle * math.pi / 180; for (int i = 0; i < _subParts.length; i++) { canvas.drawArc( - new Rect.fromLTWH(0.0, 0.0, side, size.height), + Rect.fromLTWH(0.0, 0.0, side, size.height), _prevAngle, (((_totalAngle) / _total) * _subParts[i]), chartType == ChartType.disc ? true : false, _paintList[i], ); - if (selected) - canvas.drawArc( - new Rect.fromLTWH(-8, -8, side + 16, size.height + 16), - _prevAngle, - (((_totalAngle) / _total) * _subParts[i]), - chartType == ChartType.disc ? true : false, - _paintList[i]..color = _paintList[i].color.withOpacity(0.4), - ); final radius = showChartValuesOutside ? (side / 2) + 16 : side / 3; final x = (radius) * math.cos(_prevAngle + ((((_totalAngle) / _total) * _subParts[i]) / 2)); final y = (radius) * math.sin(_prevAngle + ((((_totalAngle) / _total) * _subParts[i]) / 2)); @@ -94,9 +86,18 @@ class PieChartPainter extends CustomPainter { // final name = showValuesInPercentage ? (((_subParts.elementAt(i) / _total) * 100).toStringAsFixed(this.decimalPlaces) + '%') : _subTitles.elementAt(i); if (showChartValues) { - final name = _subTitles[i] + " " + (showValuesInPercentage ? (((_subParts.elementAt(i) / _total) * 100).toStringAsFixed(this.decimalPlaces) + '%') : value); - if (selected) _drawLabel(canvas, name, x, y - 30, side, true, statusColor: getColor(colorList, i)); - _drawLabel(canvas, _subTitles[i], (y > 0 ? x - y : x * 1.7) - 32, y, side + 8, false); + final name = "${_subTitles[i]} " + (showValuesInPercentage ? (((_subParts.elementAt(i) / _total) * 100).toStringAsFixed(this.decimalPlaces) + '%') : value); + var yLabel = y > 0 ? y + 40 : y - 20; + var xLabel = (y > 0 ? x - y : x * 1.6) - 20; + var yPopup = y; + if (_subParts[i] <= (_total / _subParts.length)) { + yLabel = y; + xLabel *= 1.1; + yPopup *= 1.25; + } + + if (selected) _drawLabel(canvas, name, x, yPopup, side, true, statusColor: getColor(colorList, i)); + _drawLabel(canvas, _subTitles[i], xLabel, yLabel, side + 8, false); } } _prevAngle = _prevAngle + (((_totalAngle) / _total) * _subParts[i]); @@ -123,15 +124,15 @@ class PieChartPainter extends CustomPainter { height: tp.height + 16, ); final rect2 = Rect.fromCenter( - center: new Offset( + center: Offset( (side / 2 + x) - ((tp.width - 16) / 2), (side / 2 + y) - ((tp.height - 16) / 2), ), width: 12, height: 12, ); - final rRect = RRect.fromRectAndRadius(rect, Radius.circular(8)); - final rRect2 = RRect.fromRectAndRadius(rect2, Radius.circular(1)); + final rRect = RRect.fromRectAndRadius(rect, const Radius.circular(8)); + final rRect2 = RRect.fromRectAndRadius(rect2, const Radius.circular(1)); final paint = Paint() ..color = chartValueBackgroundColor ?? Colors.grey[200] ..style = PaintingStyle.fill; @@ -141,7 +142,7 @@ class PieChartPainter extends CustomPainter { //Finally paint the text above box tp.paint( canvas, - new Offset( + Offset( (side / 2 + x) - ((tp.width - 50) / 2), (side / 2 + y) - ((tp.height) / 2), ), @@ -149,5 +150,5 @@ class PieChartPainter extends CustomPainter { } @override - bool shouldRepaint(PieChartPainter oldDelegate) => oldDelegate._totalAngle != _totalAngle || selected != oldDelegate.selected; + bool shouldRepaint(PieChartPainter oldDelegate) => selected != oldDelegate.selected; } diff --git a/packages/pie_chart/lib/src/chart_values_options.dart b/packages/edited_pie_chart/lib/src/chart_values_options.dart similarity index 100% rename from packages/pie_chart/lib/src/chart_values_options.dart rename to packages/edited_pie_chart/lib/src/chart_values_options.dart diff --git a/packages/pie_chart/lib/src/legend.dart b/packages/edited_pie_chart/lib/src/legend.dart similarity index 100% rename from packages/pie_chart/lib/src/legend.dart rename to packages/edited_pie_chart/lib/src/legend.dart diff --git a/packages/pie_chart/lib/src/legend_options.dart b/packages/edited_pie_chart/lib/src/legend_options.dart similarity index 100% rename from packages/pie_chart/lib/src/legend_options.dart rename to packages/edited_pie_chart/lib/src/legend_options.dart diff --git a/packages/pie_chart/lib/src/pie_chart.dart b/packages/edited_pie_chart/lib/src/pie_chart.dart similarity index 56% rename from packages/pie_chart/lib/src/pie_chart.dart rename to packages/edited_pie_chart/lib/src/pie_chart.dart index e4c9a472..71810bdf 100644 --- a/packages/pie_chart/lib/src/pie_chart.dart +++ b/packages/edited_pie_chart/lib/src/pie_chart.dart @@ -10,7 +10,7 @@ enum LegendPosition { top, bottom, left, right } enum ChartType { disc, ring } class PieChart extends StatefulWidget { - PieChart({ + const PieChart({ @required this.dataMap, this.chartType = ChartType.disc, this.chartRadius, @@ -55,11 +55,11 @@ class _PieChartState extends State with SingleTickerProviderStateMixin List legendValues; void initLegends() { - this.legendTitles = widget.dataMap.keys.toList(growable: false); + legendTitles = widget.dataMap.keys.toList(growable: false); } void initValues() { - this.legendValues = widget.dataMap.values.toList(growable: false); + legendValues = widget.dataMap.values.toList(growable: false); } void initData() { @@ -76,7 +76,7 @@ class _PieChartState extends State with SingleTickerProviderStateMixin super.initState(); initData(); controller = AnimationController( - duration: widget.animationDuration ?? Duration(milliseconds: 800), + duration: widget.animationDuration ?? const Duration(milliseconds: 800), vsync: this, ); final Animation curve = CurvedAnimation( @@ -85,9 +85,8 @@ class _PieChartState extends State with SingleTickerProviderStateMixin ); animation = Tween(begin: 0, end: 1).animate(curve) ..addListener(() { - setState(() { - _animFraction = animation.value; - }); + _animFraction = animation.value; + setState(() {}); }); controller.forward(); } @@ -98,39 +97,64 @@ class _PieChartState extends State with SingleTickerProviderStateMixin alignment: Alignment.center, children: [ LayoutBuilder( - builder: (_, c) => Container( + builder: (_, c) => SizedBox( height: widget.chartRadius != null ? c.maxWidth < widget.chartRadius ? c.maxWidth : widget.chartRadius : null, - child: InkWell( - onTap: () { - setState(() { - _selected = !_selected; - }); + child: GestureDetector( + onTapDown: (details) { + _selected = !_selected; + setState(() {}); }, - child: CustomPaint( - painter: PieChartPainter( - _animFraction, - widget.chartValuesOptions.showChartValues, - widget.chartValuesOptions.showChartValuesOutside, - widget.colorList, - chartValueStyle: widget.chartValuesOptions.chartValueStyle, - chartValueBackgroundColor: widget.chartValuesOptions.chartValueBackgroundColor, - values: legendValues, - titles: legendTitles, - initialAngle: widget.initialAngleInDegree, - showValuesInPercentage: widget.chartValuesOptions.showChartValuesInPercentage, - decimalPlaces: widget.chartValuesOptions.decimalPlaces, - showChartValueLabel: widget.chartValuesOptions.showChartValueBackground, - chartType: widget.chartType, - formatChartValues: widget.formatChartValues, - strokeWidth: widget.ringStrokeWidth, - selected: _selected, - sideTextStyle: widget.sideTextStyle, - ), - child: AspectRatio(aspectRatio: 1), + child: Stack( + children: [ + if (_selected) + CustomPaint( + painter: PieChartPainter( + _animFraction, + widget.chartValuesOptions.showChartValues, + widget.chartValuesOptions.showChartValuesOutside, + widget.colorList.map((e) => e.withOpacity(0.4)).toList(), + chartValueStyle: widget.chartValuesOptions.chartValueStyle, + chartValueBackgroundColor: widget.chartValuesOptions.chartValueBackgroundColor, + values: legendValues, + titles: legendTitles, + initialAngle: widget.initialAngleInDegree, + showValuesInPercentage: widget.chartValuesOptions.showChartValuesInPercentage, + decimalPlaces: widget.chartValuesOptions.decimalPlaces, + showChartValueLabel: widget.chartValuesOptions.showChartValueBackground, + chartType: widget.chartType, + formatChartValues: widget.formatChartValues, + strokeWidth: widget.ringStrokeWidth + 10, + sideTextStyle: widget.sideTextStyle, + ), + child: const AspectRatio(aspectRatio: 1), + ), + CustomPaint( + painter: PieChartPainter( + _animFraction, + widget.chartValuesOptions.showChartValues, + widget.chartValuesOptions.showChartValuesOutside, + widget.colorList, + chartValueStyle: widget.chartValuesOptions.chartValueStyle, + chartValueBackgroundColor: widget.chartValuesOptions.chartValueBackgroundColor, + values: legendValues, + titles: legendTitles, + initialAngle: widget.initialAngleInDegree, + showValuesInPercentage: widget.chartValuesOptions.showChartValuesInPercentage, + decimalPlaces: widget.chartValuesOptions.decimalPlaces, + showChartValueLabel: widget.chartValuesOptions.showChartValueBackground, + chartType: widget.chartType, + formatChartValues: widget.formatChartValues, + strokeWidth: widget.ringStrokeWidth, + selected: _selected, + sideTextStyle: widget.sideTextStyle, + ), + child: const AspectRatio(aspectRatio: 1), + ), + ], ), ), ), @@ -147,11 +171,7 @@ class _PieChartState extends State with SingleTickerProviderStateMixin return Column( mainAxisSize: MainAxisSize.min, children: [ - _getLegend( - padding: EdgeInsets.only( - bottom: widget.chartLegendSpacing, - ), - ), + _getLegend(padding: EdgeInsets.only(bottom: widget.chartLegendSpacing)), _getChart(), ], ); @@ -161,22 +181,14 @@ class _PieChartState extends State with SingleTickerProviderStateMixin mainAxisSize: MainAxisSize.min, children: [ _getChart(), - _getLegend( - padding: EdgeInsets.only( - top: widget.chartLegendSpacing, - ), - ), + _getLegend(padding: EdgeInsets.only(top: widget.chartLegendSpacing)), ], ); case LegendPosition.left: return Row( mainAxisSize: MainAxisSize.min, children: [ - _getLegend( - padding: EdgeInsets.only( - right: widget.chartLegendSpacing, - ), - ), + _getLegend(padding: EdgeInsets.only(right: widget.chartLegendSpacing)), _getChart(), ], ); @@ -185,11 +197,7 @@ class _PieChartState extends State with SingleTickerProviderStateMixin mainAxisSize: MainAxisSize.min, children: [ _getChart(), - _getLegend( - padding: EdgeInsets.only( - left: widget.chartLegendSpacing, - ), - ), + _getLegend(padding: EdgeInsets.only(left: widget.chartLegendSpacing)), ], ); default: @@ -230,18 +238,16 @@ class _PieChartState extends State with SingleTickerProviderStateMixin .toList(), ), ); - } else - return SizedBox( - height: 0, - width: 0, - ); + } else { + return const SizedBox(height: 0, width: 0); + } } @override Widget build(BuildContext context) { return Container( alignment: Alignment.center, - padding: EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), child: _getPieChart(), ); } diff --git a/packages/pie_chart/lib/src/utils.dart b/packages/edited_pie_chart/lib/src/utils.dart similarity index 100% rename from packages/pie_chart/lib/src/utils.dart rename to packages/edited_pie_chart/lib/src/utils.dart diff --git a/packages/pie_chart/pubspec.lock b/packages/edited_pie_chart/pubspec.lock similarity index 100% rename from packages/pie_chart/pubspec.lock rename to packages/edited_pie_chart/pubspec.lock diff --git a/packages/pie_chart/pubspec.yaml b/packages/edited_pie_chart/pubspec.yaml similarity index 100% rename from packages/pie_chart/pubspec.yaml rename to packages/edited_pie_chart/pubspec.yaml diff --git a/packages/pie_chart/res/Screenshot1.png b/packages/edited_pie_chart/res/Screenshot1.png similarity index 100% rename from packages/pie_chart/res/Screenshot1.png rename to packages/edited_pie_chart/res/Screenshot1.png diff --git a/packages/pie_chart/res/app.gif b/packages/edited_pie_chart/res/app.gif similarity index 100% rename from packages/pie_chart/res/app.gif rename to packages/edited_pie_chart/res/app.gif diff --git a/packages/pie_chart/res/pub_logo.svg b/packages/edited_pie_chart/res/pub_logo.svg similarity index 100% rename from packages/pie_chart/res/pub_logo.svg rename to packages/edited_pie_chart/res/pub_logo.svg diff --git a/packages/pie_chart/res/s10.png b/packages/edited_pie_chart/res/s10.png similarity index 100% rename from packages/pie_chart/res/s10.png rename to packages/edited_pie_chart/res/s10.png diff --git a/packages/pie_chart/res/s2.png b/packages/edited_pie_chart/res/s2.png similarity index 100% rename from packages/pie_chart/res/s2.png rename to packages/edited_pie_chart/res/s2.png diff --git a/packages/pie_chart/res/s4.png b/packages/edited_pie_chart/res/s4.png similarity index 100% rename from packages/pie_chart/res/s4.png rename to packages/edited_pie_chart/res/s4.png diff --git a/packages/pie_chart/res/s5.png b/packages/edited_pie_chart/res/s5.png similarity index 100% rename from packages/pie_chart/res/s5.png rename to packages/edited_pie_chart/res/s5.png diff --git a/packages/pie_chart/res/s6.png b/packages/edited_pie_chart/res/s6.png similarity index 100% rename from packages/pie_chart/res/s6.png rename to packages/edited_pie_chart/res/s6.png diff --git a/packages/pie_chart/res/s7.png b/packages/edited_pie_chart/res/s7.png similarity index 100% rename from packages/pie_chart/res/s7.png rename to packages/edited_pie_chart/res/s7.png diff --git a/packages/pie_chart/res/s8.png b/packages/edited_pie_chart/res/s8.png similarity index 100% rename from packages/pie_chart/res/s8.png rename to packages/edited_pie_chart/res/s8.png diff --git a/packages/pie_chart/res/s9.png b/packages/edited_pie_chart/res/s9.png similarity index 100% rename from packages/pie_chart/res/s9.png rename to packages/edited_pie_chart/res/s9.png diff --git a/pubspec.lock b/pubspec.lock index 82dbb6b7..d4e45631 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -904,7 +904,7 @@ packages: pie_chart: dependency: "direct main" description: - path: "packages/pie_chart" + path: "packages/edited_pie_chart" relative: true source: path version: "4.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index eb9ca3e7..c965ebe3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -73,7 +73,7 @@ dependencies: shimmer: ^2.0.0 flutter_advanced_switch: ^3.0.1 pie_chart: - path: packages/pie_chart + path: packages/edited_pie_chart table_calendar: ^3.0.8 image_cropper: ^3.0.3 touchable: ^0.2.1