diff --git a/example/lib/app_utils.dart b/example/lib/app_utils.dart index 53b4f7641f..b5259fbcfb 100644 --- a/example/lib/app_utils.dart +++ b/example/lib/app_utils.dart @@ -1,7 +1,6 @@ import 'dart:math' as math; class AppUtils { - static final AppUtils _singleton = AppUtils._internal(); factory AppUtils() { diff --git a/example/lib/bar_chart/samples/bar_chart_sample4.dart b/example/lib/bar_chart/samples/bar_chart_sample4.dart index 08ba2224fc..fea9d222a1 100644 --- a/example/lib/bar_chart/samples/bar_chart_sample4.dart +++ b/example/lib/bar_chart/samples/bar_chart_sample4.dart @@ -13,7 +13,7 @@ class BarChartSample4State extends State { final Color normal = const Color(0xff64caad); final Color light = const Color(0xff73e8c9); - Widget bottomTitles(double value,TitleMeta meta) { + Widget bottomTitles(double value, TitleMeta meta) { const style = TextStyle(color: Color(0xff939393), fontSize: 10); String text; switch (value.toInt()) { diff --git a/example/lib/bar_chart/samples/bar_chart_sample5.dart b/example/lib/bar_chart/samples/bar_chart_sample5.dart index ba4c0e00e9..5efc85cd84 100644 --- a/example/lib/bar_chart/samples/bar_chart_sample5.dart +++ b/example/lib/bar_chart/samples/bar_chart_sample5.dart @@ -87,7 +87,6 @@ class BarChartSample5State extends State { break; default: return Container(); - break; } return Center(child: Text(text, style: style)); } diff --git a/example/lib/line_chart/samples/line_chart_sample6.dart b/example/lib/line_chart/samples/line_chart_sample6.dart index ad3e14996d..6dcdef351d 100644 --- a/example/lib/line_chart/samples/line_chart_sample6.dart +++ b/example/lib/line_chart/samples/line_chart_sample6.dart @@ -181,10 +181,9 @@ class LineChartSample6 extends StatelessWidget { ), rightTitles: AxisTitles( sideTitles: SideTitles( - showTitles: true, - getTitles: rightTitleWidgets, - reservedSize: 30 - ), + showTitles: true, + getTitles: rightTitleWidgets, + reservedSize: 30), ), bottomTitles: AxisTitles( sideTitles: SideTitles(showTitles: false), diff --git a/lib/src/chart/base/axis_chart/axis_chart_data.dart b/lib/src/chart/base/axis_chart/axis_chart_data.dart index d7cf6c9871..2039ce3ac7 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_data.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_data.dart @@ -6,7 +6,6 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_painter.dart'; import 'package:fl_chart/src/chart/base/base_chart/base_chart_data.dart'; import 'package:fl_chart/src/utils/lerp.dart'; -import 'package:fl_chart/src/utils/utils.dart'; import 'package:flutter/material.dart'; /// This is the base class for axis base charts data @@ -83,7 +82,6 @@ abstract class AxisChartData extends BaseChartData with EquatableMixin { /// Holds data for showing label values on axis numbers class SideTitles with EquatableMixin { - /// Determines showing or hiding this side titles final bool showTitles; @@ -156,16 +154,15 @@ class SideTitles with EquatableMixin { /// Used for equality check, see [EquatableMixin]. @override List get props => [ - showTitles, - getTitles, - reservedSize, - interval, - ]; + showTitles, + getTitles, + reservedSize, + interval, + ]; } /// Holds data for showing each side titles (left, top, right, bottom) class AxisTitles with EquatableMixin { - /// Determines the size of [axisName] final double axisNameSize; @@ -201,8 +198,7 @@ class AxisTitles with EquatableMixin { static AxisTitles lerp(AxisTitles a, AxisTitles b, double t) { return AxisTitles( axisName: b.axisName, - axisNameSize: - lerpDouble(a.axisNameSize, b.axisNameSize, t), + axisNameSize: lerpDouble(a.axisNameSize, b.axisNameSize, t), sideTitles: SideTitles.lerp(a.sideTitles, b.sideTitles, t), ); } @@ -211,12 +207,12 @@ class AxisTitles with EquatableMixin { /// and replaces provided values. AxisTitles copyWith({ Widget? axisName, - double? axisNameReservedSize, + double? axisNameSize, SideTitles? sideTitles, }) { return AxisTitles( axisName: axisName ?? this.axisName, - axisNameSize: axisNameReservedSize ?? this.axisNameSize, + axisNameSize: axisNameSize ?? this.axisNameSize, sideTitles: sideTitles ?? this.sideTitles, ); } diff --git a/lib/src/chart/base/axis_chart/axis_chart_helper.dart b/lib/src/chart/base/axis_chart/axis_chart_helper.dart index bc18383997..d242cf68c6 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_helper.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_helper.dart @@ -74,7 +74,7 @@ class AxisChartHelper { final lastPosition = initialValue + (count * interval); final lastPositionOverlapsWithMax = lastPosition == max; final end = - !maxIncluded && lastPositionOverlapsWithMax ? max - interval : max; + !maxIncluded && lastPositionOverlapsWithMax ? max - interval : max; List results = []; final epsilon = interval / 100000; diff --git a/lib/src/chart/base/axis_chart/side_titles/side_titles_flex.dart b/lib/src/chart/base/axis_chart/side_titles/side_titles_flex.dart index 90992e98d2..a1ca5ed9dd 100644 --- a/lib/src/chart/base/axis_chart/side_titles/side_titles_flex.dart +++ b/lib/src/chart/base/axis_chart/side_titles/side_titles_flex.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'dart:math' as math; +/// Inspired from [Flex] class SideTitlesFlex extends MultiChildRenderObjectWidget { SideTitlesFlex({ Key? key, @@ -86,8 +87,6 @@ class AxisSideTitlesRenderFlex extends RenderBox } } - double _overflow = 0; - @override void setupParentData(RenderBox child) { if (child.parentData is! FlexParentData) { @@ -264,7 +263,6 @@ class AxisSideTitlesRenderFlex extends RenderBox constraints: constraints, ); - final double allocatedSize = sizes.allocatedSize; double actualSize = sizes.mainSize; double crossSize = sizes.crossSize; @@ -281,18 +279,8 @@ class AxisSideTitlesRenderFlex extends RenderBox crossSize = size.width; break; } - final double actualSizeDelta = actualSize - allocatedSize; - _overflow = math.max(0.0, -actualSizeDelta); - final double remainingSpace = math.max(0.0, actualSizeDelta); - late final double leadingSpace; - late final double betweenSpace; - - // spaceBetween - leadingSpace = 0.0; - betweenSpace = childCount > 1 ? remainingSpace / (childCount - 1) : 0.0; // Position elements - double childMainPosition = leadingSpace; RenderBox? child = firstChild; int counter = 0; while (child != null) { @@ -303,8 +291,8 @@ class AxisSideTitlesRenderFlex extends RenderBox // Stretch childCrossPosition = 0.0; - final childMainPosition = metaData.axisPixelLocation - - (_getMainSize(child.size) / 2); + final childMainPosition = + metaData.axisPixelLocation - (_getMainSize(child.size) / 2); switch (_direction) { case Axis.horizontal: childParentData.offset = diff --git a/lib/src/chart/base/axis_chart/side_titles/side_titles_widget.dart b/lib/src/chart/base/axis_chart/side_titles/side_titles_widget.dart index a5598bba90..592a5320a5 100644 --- a/lib/src/chart/base/axis_chart/side_titles/side_titles_widget.dart +++ b/lib/src/chart/base/axis_chart/side_titles/side_titles_widget.dart @@ -130,7 +130,8 @@ class SideTitlesWidget extends StatelessWidget { final interval = sideTitles.interval ?? Utils().getEfficientInterval( axisViewSize, - axisMax - axisMin,); + axisMax - axisMin, + ); if (isHorizontal && axisChartData is BarChartData) { final barChartData = axisChartData as BarChartData; final xLocations = barChartData.calculateGroupsX(axisViewSize); @@ -147,7 +148,8 @@ class SideTitlesWidget extends StatelessWidget { max: axisMax, baseLine: axisBaseLine, interval: interval, - ).map((axisValue) { + ) + .map((axisValue) { var portion = (axisValue - axisMin) / (axisMax - axisMin); if (isVertical) { portion = 1 - portion; diff --git a/lib/src/chart/base/base_chart/base_chart_data.dart b/lib/src/chart/base/base_chart/base_chart_data.dart index 55ec6a2e7a..3ef05d9ae8 100644 --- a/lib/src/chart/base/base_chart/base_chart_data.dart +++ b/lib/src/chart/base/base_chart/base_chart_data.dart @@ -1,10 +1,8 @@ // coverage:ignore-file import 'dart:core'; -import 'dart:core'; import 'package:equatable/equatable.dart'; import 'package:fl_chart/fl_chart.dart'; -import 'package:fl_chart/src/utils/utils.dart'; import 'package:flutter/material.dart'; import 'base_chart_painter.dart'; @@ -25,16 +23,14 @@ abstract class BaseChartData with EquatableMixin { BaseChartData({ FlBorderData? borderData, required FlTouchData touchData, - }) - : borderData = borderData ?? FlBorderData(), + }) : borderData = borderData ?? FlBorderData(), touchData = touchData; BaseChartData lerp(BaseChartData a, BaseChartData b, double t); /// Used for equality check, see [EquatableMixin]. @override - List get props => - [ + List get props => [ borderData, touchData, ]; @@ -50,8 +46,7 @@ class FlBorderData with EquatableMixin { FlBorderData({ bool? show, Border? border, - }) - : show = show ?? true, + }) : show = show ?? true, border = border ?? Border.all( color: Colors.black, @@ -81,8 +76,7 @@ class FlBorderData with EquatableMixin { /// Used for equality check, see [EquatableMixin]. @override - List get props => - [ + List get props => [ show, border, ]; @@ -108,17 +102,17 @@ abstract class FlTouchData with EquatableMixin { final MouseCursorResolver? mouseCursorResolver; /// You can disable or enable the touch system using [enabled] flag, - FlTouchData(bool enabled, - BaseTouchCallback? touchCallback, - MouseCursorResolver? mouseCursorResolver,) - : enabled = enabled, + FlTouchData( + bool enabled, + BaseTouchCallback? touchCallback, + MouseCursorResolver? mouseCursorResolver, + ) : enabled = enabled, touchCallback = touchCallback, mouseCursorResolver = mouseCursorResolver; /// Used for equality check, see [EquatableMixin]. @override - List get props => - [ + List get props => [ enabled, touchCallback, mouseCursorResolver, @@ -186,10 +180,7 @@ class TitleMeta { final SideTitles sideTitles; final String formattedValue; - TitleMeta(this.min, - this.max, - this.appliedInterval, - this.sideTitles, + TitleMeta(this.min, this.max, this.appliedInterval, this.sideTitles, this.formattedValue); } diff --git a/lib/src/chart/scatter_chart/scatter_chart.dart b/lib/src/chart/scatter_chart/scatter_chart.dart index 42fd476b3c..cdb63e04a2 100644 --- a/lib/src/chart/scatter_chart/scatter_chart.dart +++ b/lib/src/chart/scatter_chart/scatter_chart.dart @@ -46,7 +46,8 @@ class _ScatterChartState extends AnimatedWidgetBaseState { return AxisChartScaffoldWidget( data: showingData, chart: ScatterChartLeaf( - data: _withTouchedIndicators(_scatterChartDataTween!.evaluate(animation)), + data: + _withTouchedIndicators(_scatterChartDataTween!.evaluate(animation)), targetData: _withTouchedIndicators(showingData), ), ); diff --git a/lib/src/chart/scatter_chart/scatter_chart_data.dart b/lib/src/chart/scatter_chart/scatter_chart_data.dart index 024ca1f017..5cb0c93e56 100644 --- a/lib/src/chart/scatter_chart/scatter_chart_data.dart +++ b/lib/src/chart/scatter_chart/scatter_chart_data.dart @@ -157,14 +157,11 @@ class ScatterChartData extends AxisChartData with EquatableMixin { @override List get props => [ scatterSpots, - titlesData, scatterTouchData, showingTooltipIndicators, gridData, - touchData, - borderData, - clipData, - backgroundColor, + titlesData, + rangeAnnotations, minX, maxX, baselineX, @@ -173,6 +170,10 @@ class ScatterChartData extends AxisChartData with EquatableMixin { baselineY, rangeAnnotations, scatterLabelSettings, + clipData, + backgroundColor, + borderData, + touchData, ]; } diff --git a/lib/src/extensions/bar_chart_data_extension.dart b/lib/src/extensions/bar_chart_data_extension.dart index ea158613d4..acbe2520a7 100644 --- a/lib/src/extensions/bar_chart_data_extension.dart +++ b/lib/src/extensions/bar_chart_data_extension.dart @@ -2,6 +2,7 @@ import 'package:fl_chart/src/chart/bar_chart/bar_chart_data.dart'; extension BarChartDataExtension on BarChartData { List calculateGroupsX(double viewWidth) { + assert(barGroups.isNotEmpty); final groupsX = List.filled(barGroups.length, 0.0, growable: false); switch (alignment) { case BarChartAlignment.start: @@ -23,15 +24,14 @@ extension BarChartDataExtension on BarChartData { case BarChartAlignment.center: var sumWidth = - barGroups.map((group) => group.width).reduce((a, b) => a + b); + barGroups.map((group) => group.width).reduce((a, b) => a + b); sumWidth += groupsSpace * (barGroups.length - 1); final horizontalMargin = (viewWidth - sumWidth) / 2; var tempX = 0.0; for (var i = 0; i < barGroups.length; i++) { final group = barGroups[i]; - groupsX[i] = - horizontalMargin + tempX + group.width / 2; + groupsX[i] = horizontalMargin + tempX + group.width / 2; final groupSpace = i == barGroups.length - 1 ? 0 : groupsSpace; tempX += group.width + groupSpace; @@ -40,7 +40,7 @@ extension BarChartDataExtension on BarChartData { case BarChartAlignment.spaceBetween: final sumWidth = - barGroups.map((group) => group.width).reduce((a, b) => a + b); + barGroups.map((group) => group.width).reduce((a, b) => a + b); final spaceAvailable = viewWidth - sumWidth; final eachSpace = spaceAvailable / (barGroups.length - 1); @@ -57,7 +57,7 @@ extension BarChartDataExtension on BarChartData { case BarChartAlignment.spaceAround: final sumWidth = - barGroups.map((group) => group.width).reduce((a, b) => a + b); + barGroups.map((group) => group.width).reduce((a, b) => a + b); final spaceAvailable = viewWidth - sumWidth; final eachSpace = spaceAvailable / (barGroups.length * 2); @@ -73,7 +73,7 @@ extension BarChartDataExtension on BarChartData { case BarChartAlignment.spaceEvenly: final sumWidth = - barGroups.map((group) => group.width).reduce((a, b) => a + b); + barGroups.map((group) => group.width).reduce((a, b) => a + b); final spaceAvailable = viewWidth - sumWidth; final eachSpace = spaceAvailable / (barGroups.length + 1); diff --git a/lib/src/extensions/edge_insets_extension.dart b/lib/src/extensions/edge_insets_extension.dart index 76016f7877..208838d612 100644 --- a/lib/src/extensions/edge_insets_extension.dart +++ b/lib/src/extensions/edge_insets_extension.dart @@ -2,16 +2,16 @@ import 'package:flutter/widgets.dart'; extension EdgeInsetsExtension on EdgeInsets { EdgeInsets get onlyTopBottom => EdgeInsets.only( - left: 0, - top: top, - right: 0, - bottom: bottom, - ); + left: 0, + top: top, + right: 0, + bottom: bottom, + ); EdgeInsets get onlyLeftRight => EdgeInsets.only( - left: left, - top: 0, - right: right, - bottom: 0, - ); -} \ No newline at end of file + left: left, + top: 0, + right: right, + bottom: 0, + ); +} diff --git a/lib/src/extensions/fl_titles_data_extension.dart b/lib/src/extensions/fl_titles_data_extension.dart index 54724582ce..8bf5d3b69f 100644 --- a/lib/src/extensions/fl_titles_data_extension.dart +++ b/lib/src/extensions/fl_titles_data_extension.dart @@ -5,10 +5,10 @@ import 'package:flutter/widgets.dart'; extension FlTitlesDataExtension on FlTitlesData { EdgeInsets get allSidesPadding { return EdgeInsets.only( - left: show ? leftTitles.totalReservedSize: 0.0, - top: show ? topTitles.totalReservedSize: 0.0, - right: show ? rightTitles.totalReservedSize: 0.0, - bottom: show ? bottomTitles.totalReservedSize: 0.0, + left: show ? leftTitles.totalReservedSize : 0.0, + top: show ? topTitles.totalReservedSize : 0.0, + right: show ? rightTitles.totalReservedSize : 0.0, + bottom: show ? bottomTitles.totalReservedSize : 0.0, ); } } diff --git a/lib/src/extensions/side_titles_extension.dart b/lib/src/extensions/side_titles_extension.dart index bab6d4c0be..d500f3e0b0 100644 --- a/lib/src/extensions/side_titles_extension.dart +++ b/lib/src/extensions/side_titles_extension.dart @@ -11,4 +11,4 @@ extension SideTitlesExtension on AxisTitles { } return size; } -} \ No newline at end of file +} diff --git a/test/chart/bar_chart/bar_chart_painter_test.dart b/test/chart/bar_chart/bar_chart_painter_test.dart index 4fa22b1635..6d7c2d0b9e 100644 --- a/test/chart/bar_chart/bar_chart_painter_test.dart +++ b/test/chart/bar_chart/bar_chart_painter_test.dart @@ -34,7 +34,7 @@ void main() { final BarChartPainter barChartPainter = BarChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(644, 728)); + const Size(728, 728)); }); test('test 2', () { @@ -52,7 +52,7 @@ void main() { final BarChartPainter barChartPainter = BarChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(1958, 2020)); + const Size(2020, 2020)); }); test('test 3', () { @@ -70,27 +70,28 @@ void main() { final BarChartPainter barChartPainter = BarChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(500, 1000)); + const Size(1000, 1000)); }); test('test 4', () { const viewSize = Size(800, 1000); final BarChartData data = BarChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 10, showTitles: true)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 240, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: true)), - )); + titlesData: FlTitlesData( + leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 10, showTitles: true)), + topTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 240, showTitles: true)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 322, showTitles: true)), + ), + ); final BarChartPainter barChartPainter = BarChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(790, 438)); + const Size(800, 1000)); }); test('test 5', () { @@ -111,7 +112,7 @@ void main() { final BarChartPainter barChartPainter = BarChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(600, 320)); + const Size(600, 400)); }); }); @@ -202,6 +203,7 @@ void main() { titlesData: FlTitlesData(show: false), groupsSpace: 10, alignment: BarChartAlignment.center, + barGroups: barGroups, ); final BarChartPainter barChartPainter = BarChartPainter(); @@ -251,6 +253,7 @@ void main() { final BarChartData data = BarChartData( titlesData: FlTitlesData(show: false), groupsSpace: 10, + barGroups: barGroups, ); final BarChartPainter barChartPainter = BarChartPainter(); @@ -354,9 +357,9 @@ void main() { final BarChartData data = BarChartData( titlesData: FlTitlesData(show: false), + axisTitleData: FlAxisTitleData(show: false), groupsSpace: 10, barGroups: barGroups, - alignment: BarChartAlignment.center, ); final BarChartPainter barChartPainter = BarChartPainter(); @@ -366,7 +369,8 @@ void main() { when(_mockCanvasWrapper.size).thenAnswer((realInvocation) => viewSize); when(_mockCanvasWrapper.canvas).thenReturn(MockCanvas()); - final groupsX = data.calculateGroupsX(viewSize.width); + final groupsX = barChartPainter.calculateGroupsX( + viewSize, barGroups, BarChartAlignment.center, holder); final barGroupsPosition = barChartPainter.calculateGroupAndBarsPosition( viewSize, groupsX, barGroups); @@ -1042,7 +1046,7 @@ void main() { expect(rrect.width, 112); expect(rrect.height, 90); expect(rrect.left, -22.5); - expect(rrect.top, 104); + expect(rrect.top, 116); final bgTooltipPaint = result1.captured[1] as Paint; expect(bgTooltipPaint.color, const Color(0xf33f33f3)); @@ -1065,7 +1069,7 @@ void main() { const TextSpan(text: 'helllo3')); final drawOffset = result2.captured[1] as Offset; - expect(drawOffset, const Offset(-6.5, 112.0)); + expect(drawOffset, const Offset(-6.5, 124.0)); }); test('test 3', () { diff --git a/test/chart/bar_chart/bar_chart_renderer_test.dart b/test/chart/bar_chart/bar_chart_renderer_test.dart index 7633fc2f07..41a498e0bb 100644 --- a/test/chart/bar_chart/bar_chart_renderer_test.dart +++ b/test/chart/bar_chart/bar_chart_renderer_test.dart @@ -15,16 +15,20 @@ void main() { group('BarChartRenderer', () { final BarChartData data = BarChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 20, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 64, showTitles: true)), + leftTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 20, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 64, showTitles: true)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), )); final BarChartData targetData = BarChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 8, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 20, showTitles: true)), + leftTitles: + AxisTitles(sideTitles: SideTitles(reservedSize: 8, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 20, showTitles: true)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), )); diff --git a/test/chart/data_pool.dart b/test/chart/data_pool.dart index 49fca43f6a..2c7c13059f 100644 --- a/test/chart/data_pool.dart +++ b/test/chart/data_pool.dart @@ -355,28 +355,34 @@ class MockData { interval: 22, ); + static const widget1 = Text('axis1'); + static const widget2 = Text('axis2'); + static const widget3 = Text('axis3'); + static const widget4 = Text('axis4'); + static const widget5 = Text('axis5'); + static final axisTitles1 = AxisTitles( - axisName: const Text('axis1'), + axisName: widget1, sideTitles: sideTitles1, ); static final axisTitles1Clone = AxisTitles( - axisName: const Text('axis1'), + axisName: widget1, sideTitles: sideTitles1Clone, ); static final axisTitles2 = AxisTitles( - axisName: const Text('axis2'), + axisName: widget2, sideTitles: sideTitles2, ); static final axisTitles3 = AxisTitles( - axisName: const Text('axis3'), + axisName: widget3, sideTitles: sideTitles3, ); static final axisTitles4 = AxisTitles( - axisName: const Text('axis4'), + axisName: widget4, sideTitles: sideTitles4, ); static final axisTitles5 = AxisTitles( - axisName: const Text('axis4'), + axisName: widget5, axisNameSize: 889, sideTitles: sideTitles4, ); @@ -2380,22 +2386,96 @@ final ScatterChartData scatterChartData1Clone = ScatterChartData( show: true, leftTitles: AxisTitles( axisNameSize: 33, - axisName: const Text('title 1'), + axisName: MockData.widget1, sideTitles: SideTitles(showTitles: false), ), rightTitles: AxisTitles( axisNameSize: 1326, - axisName: const Text('title 3'), + axisName: MockData.widget3, sideTitles: SideTitles(reservedSize: 500, showTitles: true), ), topTitles: AxisTitles( axisNameSize: 34, - axisName: const Text('title 4'), + axisName: MockData.widget4, sideTitles: SideTitles(showTitles: false), ), bottomTitles: AxisTitles( axisNameSize: 22, - axisName: const Text('title 2'), + axisName: MockData.widget2, + sideTitles: SideTitles(showTitles: false), + ), + ), + scatterLabelSettings: ScatterLabelSettings( + showLabel: true, + getLabelTextStyleFunction: getLabelTextStyle, + getLabelFunction: getLabel, + ), +); +final ScatterChartData scatterChartData1Clone = ScatterChartData( + minY: 0, + maxY: 12, + maxX: 22, + minX: 11, + gridData: FlGridData( + show: false, + getDrawingHorizontalLine: gridGetDrawingLine, + getDrawingVerticalLine: gridGetDrawingLine, + checkToShowHorizontalLine: gridCheckToShowLine, + checkToShowVerticalLine: gridCheckToShowLine, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 33, + verticalInterval: 1, + ), + backgroundColor: Colors.black, + clipData: FlClipData.none(), + borderData: FlBorderData( + show: true, + border: Border.all( + color: Colors.white, + ), + ), + scatterSpots: [ + ScatterSpot(0, 0, show: false, radius: 33, color: Colors.yellow), + ScatterSpot(2, 2, show: false, radius: 11, color: Colors.purple), + ScatterSpot(1, 2, show: false, radius: 11, color: Colors.white), + ], + scatterTouchData: ScatterTouchData( + enabled: true, + touchTooltipData: ScatterTouchTooltipData( + getTooltipItems: scatterChartGetTooltipItems, + fitInsideHorizontally: true, + fitInsideVertically: false, + maxContentWidth: 33, + tooltipBgColor: Colors.white, + tooltipPadding: const EdgeInsets.all(23), + tooltipRoundedRadius: 534, + ), + handleBuiltInTouches: false, + touchCallback: scatterTouchCallback, + touchSpotThreshold: 12, + ), + showingTooltipIndicators: [0, 1, 2], + titlesData: FlTitlesData( + show: true, + leftTitles: AxisTitles( + axisNameSize: 33, + axisName: MockData.widget1, + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + axisNameSize: 1326, + axisName: MockData.widget3, + sideTitles: SideTitles(reservedSize: 500, showTitles: true), + ), + topTitles: AxisTitles( + axisNameSize: 34, + axisName: MockData.widget4, + sideTitles: SideTitles(showTitles: false), + ), + bottomTitles: AxisTitles( + axisNameSize: 22, + axisName: MockData.widget2, sideTitles: SideTitles(showTitles: false), ), ), @@ -2405,6 +2485,7 @@ final ScatterChartData scatterChartData1Clone = ScatterChartData( getLabelFunction: getLabel, ), ); +final ScatterChartData scatterChartData1Clone = scatterChartData1.copyWith(); final BarChartRodStackItem barChartRodStackItem1 = BarChartRodStackItem( 1, 2, diff --git a/test/chart/line_chart/line_chart_painter_test.dart b/test/chart/line_chart/line_chart_painter_test.dart index a01debb18c..5ddc5e1bad 100644 --- a/test/chart/line_chart/line_chart_painter_test.dart +++ b/test/chart/line_chart/line_chart_painter_test.dart @@ -22,8 +22,10 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 20, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 64, showTitles: true)), + leftTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 20, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 64, showTitles: true)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), )); @@ -31,7 +33,7 @@ void main() { final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(644, 728)); + const Size(728, 728)); }); test('test 2', () { @@ -39,7 +41,8 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 62, showTitles: true)), + leftTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 62, showTitles: true)), rightTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), @@ -48,7 +51,7 @@ void main() { final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(1958, 2020)); + const Size(2020, 2020)); }); test('test 3', () { @@ -57,8 +60,8 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: - AxisTitles(sideTitles: SideTitles(reservedSize: 500, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 500, showTitles: true)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), )); @@ -66,7 +69,7 @@ void main() { final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(500, 1000)); + const Size(1000, 1000)); }); test('test 4', () { @@ -75,16 +78,18 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 10, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 240, showTitles: true)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(reservedSize: 322, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 10, showTitles: true)), + topTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 240, showTitles: true)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 322, showTitles: true)), )); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(790, 438)); + const Size(800, 1000)); }); test('test 5', () { @@ -92,18 +97,20 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 0, showTitles: true)), - rightTitles: - AxisTitles(sideTitles: SideTitles(reservedSize: 342134133, showTitles: false)), - topTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 80, showTitles: true)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(reservedSize: 322, showTitles: false)), + leftTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 0, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 342134133, showTitles: false)), + topTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 80, showTitles: true)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 322, showTitles: false)), )); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(600, 320)); + const Size(600, 400)); }); test('test 6', () { @@ -159,12 +166,14 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 20)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 30)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 40)), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 20)), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 30)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 40)), ), borderData: FlBorderData(show: true, border: Border.all(width: 8)), clipData: FlClipData( @@ -188,9 +197,9 @@ void main() { final verifyResult = verify(_mockCanvasWrapper.clipRect(captureAny)); final Rect rect = verifyResult.captured.single; verifyResult.called(1); - expect(rect.left, 14); + expect(rect.left, 4); expect(rect.top, 0); - expect(rect.right, 366); + expect(rect.right, 396); expect(rect.bottom, 400); }); @@ -200,12 +209,17 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 40,)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 30)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 40)), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + topTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + reservedSize: 40, + )), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 30)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 40)), ), borderData: FlBorderData(show: true, border: Border.all(width: 8)), clipData: FlClipData( @@ -229,10 +243,10 @@ void main() { final verifyResult = verify(_mockCanvasWrapper.clipRect(captureAny)); final Rect rect = verifyResult.captured.single; verifyResult.called(1); - expect(rect.left, 14); - expect(rect.top, 44); - expect(rect.right, 366); - expect(rect.bottom, 356); + expect(rect.left, 4); + expect(rect.top, 4); + expect(rect.right, 396); + expect(rect.bottom, 396); }); }); @@ -1988,31 +2002,33 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false, reservedSize: 10)), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false, reservedSize: 10)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getExtraNeededHorizontalSpace(holder); - expect(result, 10); + expect(result, 0); }); test('test 3', () { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getExtraNeededHorizontalSpace(holder); - expect(result, 24); + expect(result, 0); }); }); @@ -2032,32 +2048,34 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false, reservedSize: 10)), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false, reservedSize: 10)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getExtraNeededVerticalSpace(holder); - expect(result, 10); + expect(result, 0); }); test('test 3', () { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getExtraNeededVerticalSpace(holder); - expect(result, 24); + expect(result, 0); }); }); @@ -2077,32 +2095,34 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false, reservedSize: 10)), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false, reservedSize: 10)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getLeftOffsetDrawSize(holder); - expect(result, 10); + expect(result, 0); }); test('test 3', () { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getLeftOffsetDrawSize(holder); - expect(result, 12); + expect(result, 0); }); }); @@ -2122,32 +2142,34 @@ void main() { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false, reservedSize: 10)), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 10)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false, reservedSize: 10)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getTopOffsetDrawSize(holder); - expect(result, 10); + expect(result, 0); }); test('test 3', () { final LineChartData data = LineChartData( titlesData: FlTitlesData( show: true, - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - bottomTitles: - AxisTitles(sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: true, reservedSize: 12)), ), ); final LineChartPainter lineChartPainter = LineChartPainter(); final holder = PaintHolder(data, data, 1.0); final result = lineChartPainter.getTopOffsetDrawSize(holder); - expect(result, 12); + expect(result, 0); }); }); diff --git a/test/chart/line_chart/line_chart_renderer_test.dart b/test/chart/line_chart/line_chart_renderer_test.dart index ca136116c7..021ef92d45 100644 --- a/test/chart/line_chart/line_chart_renderer_test.dart +++ b/test/chart/line_chart/line_chart_renderer_test.dart @@ -15,16 +15,20 @@ void main() { group('LineChartRenderer', () { final LineChartData data = LineChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 20, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 464, showTitles: true)), + leftTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 20, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 464, showTitles: true)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), )); final LineChartData targetData = LineChartData( titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 8, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(reservedSize: 20, showTitles: true)), + leftTitles: + AxisTitles(sideTitles: SideTitles(reservedSize: 8, showTitles: true)), + rightTitles: AxisTitles( + sideTitles: SideTitles(reservedSize: 20, showTitles: true)), topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), )); diff --git a/test/chart/scatter_chart/scatter_chart_data_test.dart b/test/chart/scatter_chart/scatter_chart_data_test.dart index d8bbf8a290..7e8762f378 100644 --- a/test/chart/scatter_chart/scatter_chart_data_test.dart +++ b/test/chart/scatter_chart/scatter_chart_data_test.dart @@ -104,22 +104,22 @@ void main() { show: true, leftTitles: AxisTitles( axisNameSize: 33, - axisName: const Text('title 1'), + axisName: MockData.widget1, sideTitles: SideTitles(showTitles: false), ), rightTitles: AxisTitles( axisNameSize: 1326, - axisName: const Text('title 3'), + axisName: MockData.widget3, sideTitles: SideTitles(reservedSize: 500, showTitles: true), ), topTitles: AxisTitles( axisNameSize: 34, - axisName: const Text('title 4'), + axisName: MockData.widget4, sideTitles: SideTitles(showTitles: false), ), bottomTitles: AxisTitles( axisNameSize: 22, - axisName: const Text('title 2'), + axisName: MockData.widget2, sideTitles: SideTitles(showTitles: false), ), ), @@ -212,29 +212,29 @@ void main() { expect( scatterChartData1 == scatterChartData1Clone.copyWith( - titlesData: FlTitlesData( - show: true, - leftTitles: AxisTitles( - axisNameSize: 33, - axisName: const Text('title 1'), - sideTitles: SideTitles(showTitles: false), - ), - rightTitles: AxisTitles( - axisNameSize: 13262, - axisName: const Text('title 3'), - sideTitles: SideTitles(reservedSize: 500, showTitles: true), - ), - topTitles: AxisTitles( - axisNameSize: 34, - axisName: const Text('title 4'), - sideTitles: SideTitles(showTitles: false), - ), - bottomTitles: AxisTitles( - axisNameSize: 22, - axisName: const Text('title 2'), - sideTitles: SideTitles(showTitles: false), - ), + titlesData: FlTitlesData( + show: true, + leftTitles: AxisTitles( + axisNameSize: 33, + axisName: const Text('title 1'), + sideTitles: SideTitles(showTitles: false), ), + rightTitles: AxisTitles( + axisNameSize: 13262, + axisName: const Text('title 3'), + sideTitles: SideTitles(reservedSize: 500, showTitles: true), + ), + topTitles: AxisTitles( + axisNameSize: 34, + axisName: const Text('title 4'), + sideTitles: SideTitles(showTitles: false), + ), + bottomTitles: AxisTitles( + axisNameSize: 22, + axisName: const Text('title 2'), + sideTitles: SideTitles(showTitles: false), + ), + ), ), false); diff --git a/test/chart/scatter_chart/scatter_chart_painter_test.dart b/test/chart/scatter_chart/scatter_chart_painter_test.dart index 78341fb108..82d8500555 100644 --- a/test/chart/scatter_chart/scatter_chart_painter_test.dart +++ b/test/chart/scatter_chart/scatter_chart_painter_test.dart @@ -32,7 +32,7 @@ void main() { final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(644, 728)); + const Size(728, 728)); }); test('test 2', () { @@ -50,7 +50,7 @@ void main() { final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(1958, 2020)); + const Size(2020, 2020)); }); test('test 3', () { @@ -68,7 +68,7 @@ void main() { final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(500, 1000)); + const Size(1000, 1000)); }); test('test 4', () { @@ -88,7 +88,7 @@ void main() { final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(790, 438)); + const Size(800, 1000)); }); test('test 5', () { @@ -109,7 +109,7 @@ void main() { final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); final holder = PaintHolder(data, data, 1.0); expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(600, 320)); + const Size(600, 400)); }); }); @@ -608,7 +608,7 @@ void main() { }); test('test 2', () { - const viewSize = Size(128, 112); + const viewSize = Size(100, 100); final spots = [ ScatterSpot(1, 1), ScatterSpot(2, 4), @@ -655,33 +655,31 @@ void main() { scatterSpots: spots, ); - const leftExtra = 14; - const topExtra = 6; final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); final holder = PaintHolder(data, data, 1.0); ScatterTouchedSpot? touchedSpot = scatterChartPainter.handleTouch( - const Offset(leftExtra + 10, topExtra + 90), + const Offset(10, 90), viewSize, holder, ); expect(touchedSpot!.spot, spots[0]); ScatterTouchedSpot? touchedSpot2 = scatterChartPainter.handleTouch( - const Offset(leftExtra + 50, topExtra + 80), + const Offset(50, 80), viewSize, holder, ); expect(touchedSpot2!.spot, spots[2]); ScatterTouchedSpot? touchedSpot3 = scatterChartPainter.handleTouch( - const Offset(leftExtra + 50.49, topExtra + 80), + const Offset(50.49, 80), viewSize, holder, ); expect(touchedSpot3!.spot, spots[2]); ScatterTouchedSpot? touchedSpot4 = scatterChartPainter.handleTouch( - const Offset(leftExtra + 50.5, topExtra + 80), + const Offset(50.5, 80), viewSize, holder, ); @@ -690,8 +688,8 @@ void main() { final radius = spots[2].radius; ScatterTouchedSpot? touchedSpot5 = scatterChartPainter.handleTouch( Offset( - leftExtra + 50 + (math.cos(math.pi / 4) * radius) - 0.01, - topExtra + 80 + (math.sin(math.pi / 4) * radius) - 0.01, + 50 + (math.cos(math.pi / 4) * radius) - 0.01, + 80 + (math.sin(math.pi / 4) * radius) - 0.01, ), viewSize, holder, @@ -700,8 +698,8 @@ void main() { ScatterTouchedSpot? touchedSpot6 = scatterChartPainter.handleTouch( Offset( - leftExtra + 50 + (math.cos(math.pi / 4) * radius), - topExtra + 80 + (math.sin(math.pi / 4) * radius), + 50 + (math.cos(math.pi / 4) * radius), + 80 + (math.sin(math.pi / 4) * radius), ), viewSize, holder,