From 10673fafe89b3a7e8b885601536ce8c3b8e73907 Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 18:09:34 +0200 Subject: [PATCH 01/10] Add draggable logic for LineChart --- .../base/axis_chart/axis_chart_painter.dart | 19 ++++++++++ lib/src/chart/line_chart/line_chart.dart | 38 ++++++++++++++++++- lib/src/chart/line_chart/line_chart_data.dart | 8 ++++ .../chart/line_chart/line_chart_painter.dart | 8 ++++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/lib/src/chart/base/axis_chart/axis_chart_painter.dart b/lib/src/chart/base/axis_chart/axis_chart_painter.dart index 610e0dac5..46967ccf8 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_painter.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_painter.dart @@ -410,6 +410,25 @@ abstract class AxisChartPainter return viewSize.height - (((spotY - data.minY) / deltaY) * viewSize.height); } + /// Function converts pixelX and pixelY to the [FlSpot], + /// reversed logic of [getPixelY] and [getPixelX] + FlSpot getTouchedCoordinates( + double pixelX, + double pixelY, + Size viewSize, + PaintHolder holder, + ) { + final data = holder.data; + final deltaY = data.maxY - data.minY; + final deltaX = data.maxX - data.minX; + + final x = ((pixelX * deltaX) / viewSize.width) + data.minX; + final y = + ((viewSize.height - pixelY) * deltaY) / viewSize.height + data.minY; + + return FlSpot(x, y); + } + /// With this function we can get horizontal /// position for the tooltip. double getTooltipLeft( diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index cee6c9d60..3c6c3bdcb 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -44,6 +44,22 @@ class _LineChartState extends AnimatedWidgetBaseState { final Map> _showingTouchedIndicators = {}; + List _lineBarsData = []; + + @override + void initState() { + _lineBarsData = widget.data.lineBarsData; + super.initState(); + } + + @override + void didUpdateWidget(covariant LineChart oldWidget) { + if (widget.data.lineBarsData != _lineBarsData) { + _lineBarsData = widget.data.lineBarsData; + } + super.didUpdateWidget(oldWidget); + } + @override Widget build(BuildContext context) { final showingData = _getData(); @@ -80,11 +96,13 @@ class _LineChartState extends AnimatedWidgetBaseState { if (lineTouchData.enabled && lineTouchData.handleBuiltInTouches) { _providedTouchCallback = lineTouchData.touchCallback; return widget.data.copyWith( + lineBarsData: _lineBarsData, lineTouchData: widget.data.lineTouchData .copyWith(touchCallback: _handleBuiltInTouch), ); } - return widget.data; + + return widget.data.copyWith(lineBarsData: _lineBarsData); } void _handleBuiltInTouch( @@ -94,8 +112,8 @@ class _LineChartState extends AnimatedWidgetBaseState { if (!mounted) { return; } - _providedTouchCallback?.call(event, touchResponse); + _providedTouchCallback?.call(event, touchResponse); if (!event.isInterestedForInteractions || touchResponse?.lineBarSpots == null || touchResponse!.lineBarSpots!.isEmpty) { @@ -121,6 +139,22 @@ class _LineChartState extends AnimatedWidgetBaseState { ..clear() ..add(ShowingTooltipIndicators(sortedLineSpots)); }); + + if (event is FlPanStartEvent || event is FlPanUpdateEvent) { + final barIndex = touchResponse.lineBarSpots?.first.barIndex; + final spotIndex = touchResponse.lineBarSpots?.first.spotIndex; + final newDataSpot = touchResponse.lineBarSpots?.first.touchedAxesPoint; + + if (spotIndex != null && newDataSpot != null && barIndex != null) { + final isDraggable = widget.data.lineBarsData[barIndex].isDraggable; + + if (isDraggable) { + setState(() { + _lineBarsData[barIndex].spots[spotIndex] = newDataSpot; + }); + } + } + } } @override diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index 6c2b7d18f..2b0a4a7fa 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -246,6 +246,7 @@ class LineChartBarData with EquatableMixin { this.shadow = const Shadow(color: Colors.transparent), this.isStepLineChart = false, this.lineChartStepData = const LineChartStepData(), + this.isDraggable = false, }) : color = color ?? ((color == null && gradient == null) ? Colors.cyan : null), belowBarData = belowBarData ?? BarAreaData(), @@ -311,6 +312,9 @@ class LineChartBarData with EquatableMixin { /// Determines to show or hide the line. final bool show; + /// Determines if spots are draggable + final bool isDraggable; + /// If provided, this [LineChartBarData] draws with this [color] /// Otherwise we use [gradient] to draw the background. /// It throws an exception if you provide both [color] and [gradient] @@ -1376,10 +1380,14 @@ class TouchLineBarSpot extends LineBarSpot { super.barIndex, super.spot, this.distance, + this.touchedAxesPoint, ); /// Distance in pixels from where the user taped final double distance; + + /// Position in spots' values converted from local position + final FlSpot touchedAxesPoint; } /// Holds data of showing each row item in the tooltip popup. diff --git a/lib/src/chart/line_chart/line_chart_painter.dart b/lib/src/chart/line_chart/line_chart_painter.dart index 3cc5a6060..c6acdaf07 100644 --- a/lib/src/chart/line_chart/line_chart_painter.dart +++ b/lib/src/chart/line_chart/line_chart_painter.dart @@ -1233,6 +1233,13 @@ class LineChartPainter extends AxisChartPainter { return null; } + final axesPoint = getTouchedCoordinates( + touchedPoint.dx, + touchedPoint.dy, + viewSize, + holder, + ); + /// Find the nearest spot (based on distanceCalculator) final sortedSpots = []; double? smallestDistance; @@ -1264,6 +1271,7 @@ class LineChartPainter extends AxisChartPainter { barDataPosition, sortedSpots.first, smallestDistance!, + axesPoint, ); } else { return null; From b0d0cedb329f5fce827c894caaca2b1276198e8d Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 20:41:27 +0200 Subject: [PATCH 02/10] Remake logic of updating spot's position and adjust tests --- lib/src/chart/line_chart/line_chart.dart | 39 ++- lib/src/chart/line_chart/line_chart_data.dart | 29 +- .../chart/line_chart/line_chart_painter.dart | 23 +- .../chart/line_chart/line_chart_renderer.dart | 4 +- .../bar_chart_painter_test.mocks.dart | 2 +- .../bar_chart_renderer_test.mocks.dart | 150 ++++++---- test/chart/data_pool.dart | 20 +- .../line_chart/line_chart_painter_test.dart | 32 ++- .../line_chart_painter_test.mocks.dart | 258 ++++++++++------- .../line_chart/line_chart_renderer_test.dart | 2 +- .../line_chart_renderer_test.mocks.dart | 266 +++++++++++------- .../pie_chart_painter_test.mocks.dart | 2 +- .../pie_chart_renderer_test.mocks.dart | 2 +- .../radar_chart_painter_test.mocks.dart | 2 +- .../radar_chart_renderer_test.mocks.dart | 2 +- .../scatter_chart_painter_test.mocks.dart | 2 +- .../scatter_chart_renderer_test.mocks.dart | 134 +++++---- test/utils/canvas_wrapper_test.mocks.dart | 2 +- test/utils/utils_test.mocks.dart | 2 +- 19 files changed, 616 insertions(+), 357 deletions(-) diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 3c6c3bdcb..82a601469 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -46,16 +46,22 @@ class _LineChartState extends AnimatedWidgetBaseState { List _lineBarsData = []; + /// Keeps index of bar and spot that currently is being dragging + (int barIndex, int spotIndex)? _draggingSpotIndexes; + + bool get _isAnyDraggable => + _lineBarsData.indexWhere((lineBarData) => lineBarData.isDraggable) != -1; + @override void initState() { - _lineBarsData = widget.data.lineBarsData; + _lineBarsData = List.from(widget.data.lineBarsData); super.initState(); } @override void didUpdateWidget(covariant LineChart oldWidget) { if (widget.data.lineBarsData != _lineBarsData) { - _lineBarsData = widget.data.lineBarsData; + _lineBarsData = List.from(widget.data.lineBarsData); } super.didUpdateWidget(oldWidget); } @@ -97,12 +103,14 @@ class _LineChartState extends AnimatedWidgetBaseState { _providedTouchCallback = lineTouchData.touchCallback; return widget.data.copyWith( lineBarsData: _lineBarsData, - lineTouchData: widget.data.lineTouchData - .copyWith(touchCallback: _handleBuiltInTouch), + lineTouchData: widget.data.lineTouchData.copyWith( + touchCallback: _handleBuiltInTouch, + distanceCalculator: _isAnyDraggable ? vectorDistanceCalculator : null, + ), ); } - return widget.data.copyWith(lineBarsData: _lineBarsData); + return widget.data; } void _handleBuiltInTouch( @@ -113,6 +121,20 @@ class _LineChartState extends AnimatedWidgetBaseState { return; } + if (event is FlPanEndEvent || event is FlLongPressEnd) { + setState(() { + _draggingSpotIndexes = null; + }); + } + + if (_draggingSpotIndexes != null) { + setState(() { + final (barIndex, spotIndex) = _draggingSpotIndexes!; + _lineBarsData[barIndex].spots[spotIndex] = + touchResponse!.touchedAxesPoint!; + }); + } + _providedTouchCallback?.call(event, touchResponse); if (!event.isInterestedForInteractions || touchResponse?.lineBarSpots == null || @@ -140,17 +162,16 @@ class _LineChartState extends AnimatedWidgetBaseState { ..add(ShowingTooltipIndicators(sortedLineSpots)); }); - if (event is FlPanStartEvent || event is FlPanUpdateEvent) { + if (event is FlPanStartEvent || event is FlLongPressStart) { final barIndex = touchResponse.lineBarSpots?.first.barIndex; final spotIndex = touchResponse.lineBarSpots?.first.spotIndex; - final newDataSpot = touchResponse.lineBarSpots?.first.touchedAxesPoint; - if (spotIndex != null && newDataSpot != null && barIndex != null) { + if (spotIndex != null && barIndex != null) { final isDraggable = widget.data.lineBarsData[barIndex].isDraggable; if (isDraggable) { setState(() { - _lineBarsData[barIndex].spots[spotIndex] = newDataSpot; + _draggingSpotIndexes = (barIndex, spotIndex); }); } } diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index 2b0a4a7fa..f4c9ce1ec 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -1,4 +1,5 @@ // coverage:ignore-file +import 'dart:math'; import 'dart:ui'; import 'package:equatable/equatable.dart'; @@ -227,7 +228,7 @@ class LineChartBarData with EquatableMixin { /// If you want to have a Step Line Chart style, just set [isStepLineChart] true, /// also you can tweak the [LineChartBarData.lineChartStepData]. LineChartBarData({ - this.spots = const [], + List spots = const [], this.show = true, Color? color, this.gradient, @@ -257,6 +258,7 @@ class LineChartBarData with EquatableMixin { FlSpot? mostBottom; FlSpot? firstValidSpot; + this.spots = List.from(spots); try { firstValidSpot = spots.firstWhere((element) => element != FlSpot.nullSpot); @@ -295,7 +297,7 @@ class LineChartBarData with EquatableMixin { /// /// You can have multiple lines by splitting them, /// put a [FlSpot.nullSpot] between each section. - final List spots; + late final List spots; /// We keep the most left spot to prevent redundant calculations late final FlSpot mostLeftSpot; @@ -385,6 +387,7 @@ class LineChartBarData with EquatableMixin { aboveBarData: BarAreaData.lerp(a.aboveBarData, b.aboveBarData, t), curveSmoothness: b.curveSmoothness, isCurved: b.isCurved, + isDraggable: b.isDraggable, isStrokeCapRound: b.isStrokeCapRound, isStrokeJoinRound: b.isStrokeJoinRound, preventCurveOverShooting: b.preventCurveOverShooting, @@ -1187,6 +1190,17 @@ double _xDistance(Offset touchPoint, Offset spotPixelCoordinates) { return (touchPoint.dx - spotPixelCoordinates.dx).abs(); } +/// distance calculator that calculates distance using vectors' math +double vectorDistanceCalculator( + Offset touchPoint, + Offset spotPixelCoordinates, +) { + return sqrt( + pow(touchPoint.dx - spotPixelCoordinates.dx, 2) + + pow(touchPoint.dy - spotPixelCoordinates.dy, 2), + ); +} + /// Default presentation of touched indicators. List defaultTouchedIndicators( LineChartBarData barData, @@ -1380,14 +1394,10 @@ class TouchLineBarSpot extends LineBarSpot { super.barIndex, super.spot, this.distance, - this.touchedAxesPoint, ); /// Distance in pixels from where the user taped final double distance; - - /// Position in spots' values converted from local position - final FlSpot touchedAxesPoint; } /// Holds data of showing each row item in the tooltip popup. @@ -1478,19 +1488,24 @@ class LineTouchResponse extends BaseTouchResponse { /// If touch happens, [LineChart] processes it internally and /// passes out a list of [lineBarSpots] it gives you information about the touched spot. /// They are sorted based on their distance to the touch event - const LineTouchResponse(this.lineBarSpots); + const LineTouchResponse(this.lineBarSpots, this.touchedAxesPoint); /// touch happened on these spots /// (if a single line provided on the chart, [lineBarSpots]'s length will be 1 always) final List? lineBarSpots; + /// Position in spots' values converted from local position + final FlSpot? touchedAxesPoint; + /// Copies current [LineTouchResponse] to a new [LineTouchResponse], /// and replaces provided values. LineTouchResponse copyWith({ List? lineBarSpots, + FlSpot? touchedAxesPoint, }) { return LineTouchResponse( lineBarSpots ?? this.lineBarSpots, + touchedAxesPoint ?? this.touchedAxesPoint, ); } } diff --git a/lib/src/chart/line_chart/line_chart_painter.dart b/lib/src/chart/line_chart/line_chart_painter.dart index c6acdaf07..e0a31a265 100644 --- a/lib/src/chart/line_chart/line_chart_painter.dart +++ b/lib/src/chart/line_chart/line_chart_painter.dart @@ -1191,7 +1191,7 @@ class LineChartPainter extends AxisChartPainter { /// Processes [localPosition] and checks /// the elements of the chart that are near the offset, /// then makes a [LineTouchResponse] from the elements that has been touched. - List? handleTouch( + LineTouchResponse handleTouch( Offset localPosition, Size size, PaintHolder holder, @@ -1214,9 +1214,20 @@ class LineChartPainter extends AxisChartPainter { } } + final axesPoint = getTouchedCoordinates( + localPosition.dx, + localPosition.dy, + size, + holder, + ); + touchedSpots.sort((a, b) => a.distance.compareTo(b.distance)); + final response = LineTouchResponse( + touchedSpots.isEmpty ? null : touchedSpots, + axesPoint, + ); - return touchedSpots.isEmpty ? null : touchedSpots; + return response; } /// find the nearest spot base on the touched offset @@ -1233,13 +1244,6 @@ class LineChartPainter extends AxisChartPainter { return null; } - final axesPoint = getTouchedCoordinates( - touchedPoint.dx, - touchedPoint.dy, - viewSize, - holder, - ); - /// Find the nearest spot (based on distanceCalculator) final sortedSpots = []; double? smallestDistance; @@ -1271,7 +1275,6 @@ class LineChartPainter extends AxisChartPainter { barDataPosition, sortedSpots.first, smallestDistance!, - axesPoint, ); } else { return null; diff --git a/lib/src/chart/line_chart/line_chart_renderer.dart b/lib/src/chart/line_chart/line_chart_renderer.dart index dfae057dd..59165d1fd 100644 --- a/lib/src/chart/line_chart/line_chart_renderer.dart +++ b/lib/src/chart/line_chart/line_chart_renderer.dart @@ -104,11 +104,11 @@ class RenderLineChart extends RenderBaseChart { @override LineTouchResponse getResponseAtLocation(Offset localPosition) { - final touchedSpots = painter.handleTouch( + final touchedSpotsResponse = painter.handleTouch( localPosition, mockTestSize ?? size, paintHolder, ); - return LineTouchResponse(touchedSpots); + return touchedSpotsResponse; } } diff --git a/test/chart/bar_chart/bar_chart_painter_test.mocks.dart b/test/chart/bar_chart/bar_chart_painter_test.mocks.dart index 7e4833f7e..6efe33bca 100644 --- a/test/chart/bar_chart/bar_chart_painter_test.mocks.dart +++ b/test/chart/bar_chart/bar_chart_painter_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/bar_chart/bar_chart_painter_test.dart. // Do not manually edit this file. diff --git a/test/chart/bar_chart/bar_chart_renderer_test.mocks.dart b/test/chart/bar_chart/bar_chart_renderer_test.mocks.dart index 48490ff23..9c980a59d 100644 --- a/test/chart/bar_chart/bar_chart_renderer_test.mocks.dart +++ b/test/chart/bar_chart/bar_chart_renderer_test.mocks.dart @@ -1,22 +1,22 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/bar_chart/bar_chart_renderer_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:typed_data' as _i7; +import 'dart:typed_data' as _i8; import 'dart:ui' as _i2; -import 'package:fl_chart/fl_chart.dart' as _i13; -import 'package:fl_chart/src/chart/bar_chart/bar_chart_painter.dart' as _i10; +import 'package:fl_chart/fl_chart.dart' as _i7; +import 'package:fl_chart/src/chart/bar_chart/bar_chart_painter.dart' as _i11; import 'package:fl_chart/src/chart/base/base_chart/base_chart_painter.dart' - as _i12; -import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i11; + as _i13; +import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i12; import 'package:flutter/foundation.dart' as _i5; -import 'package:flutter/gestures.dart' as _i8; +import 'package:flutter/gestures.dart' as _i9; import 'package:flutter/material.dart' as _i6; import 'package:flutter/rendering.dart' as _i3; import 'package:flutter/src/rendering/layer.dart' as _i4; -import 'package:flutter/src/widgets/notification_listener.dart' as _i9; +import 'package:flutter/src/widgets/notification_listener.dart' as _i10; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -137,6 +137,16 @@ class _FakeDiagnosticsNode_7 extends _i1.SmartFake super.toString(); } +class _FakeFlSpot_8 extends _i1.SmartFake implements _i7.FlSpot { + _FakeFlSpot_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [Canvas]. /// /// See the documentation for Mockito's code generation for more information. @@ -246,7 +256,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - void transform(_i7.Float64List? matrix4) => super.noSuchMethod( + void transform(_i8.Float64List? matrix4) => super.noSuchMethod( Invocation.method( #transform, [matrix4], @@ -254,13 +264,13 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - _i7.Float64List getTransform() => (super.noSuchMethod( + _i8.Float64List getTransform() => (super.noSuchMethod( Invocation.method( #getTransform, [], ), - returnValue: _i7.Float64List(0), - ) as _i7.Float64List); + returnValue: _i8.Float64List(0), + ) as _i8.Float64List); @override void clipRect( _i2.Rect? rect, { @@ -585,7 +595,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawPoints( _i2.PointMode? pointMode, - _i7.Float32List? points, + _i8.Float32List? points, _i2.Paint? paint, ) => super.noSuchMethod( @@ -644,9 +654,9 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawAtlas( _i2.Image? atlas, - _i7.Float32List? rstTransforms, - _i7.Float32List? rects, - _i7.Int32List? colors, + _i8.Float32List? rstTransforms, + _i8.Float32List? rects, + _i8.Int32List? colors, _i2.BlendMode? blendMode, _i2.Rect? cullRect, _i2.Paint? paint, @@ -922,7 +932,7 @@ class MockPaintingContext extends _i1.Mock implements _i3.PaintingContext { _i4.TransformLayer? pushTransform( bool? needsCompositing, _i2.Offset? offset, - _i8.Matrix4? transform, + _i9.Matrix4? transform, _i3.PaintingContextCallback? painter, { _i4.TransformLayer? oldLayer, }) => @@ -1089,7 +1099,7 @@ class MockBuildContext extends _i1.Mock implements _i6.BuildContext { returnValueForMissingStub: null, ); @override - void dispatchNotification(_i9.Notification? notification) => + void dispatchNotification(_i10.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, @@ -1168,7 +1178,7 @@ class MockBuildContext extends _i1.Mock implements _i6.BuildContext { /// A class which mocks [BarChartPainter]. /// /// See the documentation for Mockito's code generation for more information. -class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { +class MockBarChartPainter extends _i1.Mock implements _i11.BarChartPainter { MockBarChartPainter() { _i1.throwOnMissingStub(this); } @@ -1176,8 +1186,8 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { @override void paint( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1191,10 +1201,10 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { returnValueForMissingStub: null, ); @override - List<_i10.GroupBarsPosition> calculateGroupAndBarsPosition( + List<_i11.GroupBarsPosition> calculateGroupAndBarsPosition( _i2.Size? viewSize, List? groupsX, - List<_i13.BarChartGroupData>? barGroups, + List<_i7.BarChartGroupData>? barGroups, ) => (super.noSuchMethod( Invocation.method( @@ -1205,13 +1215,13 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { barGroups, ], ), - returnValue: <_i10.GroupBarsPosition>[], - ) as List<_i10.GroupBarsPosition>); + returnValue: <_i11.GroupBarsPosition>[], + ) as List<_i11.GroupBarsPosition>); @override void drawBars( - _i11.CanvasWrapper? canvasWrapper, - List<_i10.GroupBarsPosition>? groupBarsPosition, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + List<_i11.GroupBarsPosition>? groupBarsPosition, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1227,14 +1237,14 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { @override void drawTouchTooltip( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - List<_i10.GroupBarsPosition>? groupPositions, - _i13.BarTouchTooltipData? tooltipData, - _i13.BarChartGroupData? showOnBarGroup, + _i12.CanvasWrapper? canvasWrapper, + List<_i11.GroupBarsPosition>? groupPositions, + _i7.BarTouchTooltipData? tooltipData, + _i7.BarChartGroupData? showOnBarGroup, int? barGroupIndex, - _i13.BarChartRodData? showOnRodData, + _i7.BarChartRodData? showOnRodData, int? barRodIndex, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1255,14 +1265,14 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { ); @override void drawStackItemBorderStroke( - _i11.CanvasWrapper? canvasWrapper, - _i13.BarChartRodStackItem? stackItem, + _i12.CanvasWrapper? canvasWrapper, + _i7.BarChartRodStackItem? stackItem, int? index, int? rodStacksSize, double? barThickSize, _i2.RRect? barRRect, _i2.Size? drawSize, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1281,10 +1291,10 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { returnValueForMissingStub: null, ); @override - _i13.BarTouchedSpot? handleTouch( + _i7.BarTouchedSpot? handleTouch( _i2.Offset? localPosition, _i2.Size? viewSize, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => (super.noSuchMethod(Invocation.method( #handleTouch, @@ -1293,11 +1303,11 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { viewSize, holder, ], - )) as _i13.BarTouchedSpot?); + )) as _i7.BarTouchedSpot?); @override void drawGrid( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1311,8 +1321,8 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { ); @override void drawBackground( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1326,8 +1336,8 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { ); @override void drawRangeAnnotation( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1342,8 +1352,8 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { @override void drawExtraLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1359,8 +1369,8 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { @override void drawHorizontalLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1378,8 +1388,8 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { @override void drawVerticalLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.BarChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1398,7 +1408,7 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { double getPixelX( double? spotX, _i2.Size? viewSize, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1415,7 +1425,7 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { double getPixelY( double? spotY, _i2.Size? viewSize, - _i12.PaintHolder<_i13.BarChartData>? holder, + _i13.PaintHolder<_i7.BarChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1429,10 +1439,40 @@ class MockBarChartPainter extends _i1.Mock implements _i10.BarChartPainter { returnValue: 0.0, ) as double); @override + _i7.FlSpot getTouchedCoordinates( + double? pixelX, + double? pixelY, + _i2.Size? viewSize, + _i13.PaintHolder<_i7.BarChartData>? holder, + ) => + (super.noSuchMethod( + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + returnValue: _FakeFlSpot_8( + this, + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + ), + ) as _i7.FlSpot); + @override double getTooltipLeft( double? dx, double? tooltipWidth, - _i13.FLHorizontalAlignment? tooltipHorizontalAlignment, + _i7.FLHorizontalAlignment? tooltipHorizontalAlignment, double? tooltipHorizontalOffset, ) => (super.noSuchMethod( diff --git a/test/chart/data_pool.dart b/test/chart/data_pool.dart index 2bb1f1315..f046668ff 100644 --- a/test/chart/data_pool.dart +++ b/test/chart/data_pool.dart @@ -305,7 +305,7 @@ class MockData { ); static final lineTouchResponse1 = - LineTouchResponse([lineBarSpot1, lineBarSpot2]); + LineTouchResponse([lineBarSpot1, lineBarSpot2], const FlSpot(1, 1)); static final barChartRodData1 = BarChartRodData(toY: 11); static final barChartRodData2 = BarChartRodData(toY: 22); @@ -1020,8 +1020,12 @@ final TouchLineBarSpot lineBarSpot1Clone = TouchLineBarSpot( 0, ); -final TouchLineBarSpot lineBarSpot2 = - TouchLineBarSpot(lineChartBarData1, 2, flSpot1, 2); +final TouchLineBarSpot lineBarSpot2 = TouchLineBarSpot( + lineChartBarData1, + 2, + flSpot1, + 2, +); final TouchLineBarSpot lineBarSpot3 = TouchLineBarSpot( lineChartBarData1, @@ -1035,12 +1039,14 @@ final LineTouchResponse lineTouchResponse1 = LineTouchResponse( lineBarSpot1, lineBarSpot2, ], + const FlSpot(1, 1), ); final LineTouchResponse lineTouchResponse1Clone = LineTouchResponse( [ lineBarSpot1Clone, lineBarSpot2, ], + const FlSpot(1, 1), ); final LineTouchResponse lineTouchResponse2 = LineTouchResponse( @@ -1048,17 +1054,18 @@ final LineTouchResponse lineTouchResponse2 = LineTouchResponse( lineBarSpot2, lineBarSpot1, ], + const FlSpot(1, 1), ); -const LineTouchResponse lineTouchResponse3 = LineTouchResponse( - [], -); +const LineTouchResponse lineTouchResponse3 = + LineTouchResponse([], FlSpot(1, 1)); final LineTouchResponse lineTouchResponse4 = LineTouchResponse( [ lineBarSpot1, lineBarSpot2, ], + const FlSpot(1, 1), ); final LineTouchResponse lineTouchResponse5 = LineTouchResponse( @@ -1066,6 +1073,7 @@ final LineTouchResponse lineTouchResponse5 = LineTouchResponse( lineBarSpot1, lineBarSpot2, ], + const FlSpot(1, 1), ); const TouchedSpotIndicatorData touchedSpotIndicatorData1 = diff --git a/test/chart/line_chart/line_chart_painter_test.dart b/test/chart/line_chart/line_chart_painter_test.dart index c702c6431..510a8a955 100644 --- a/test/chart/line_chart/line_chart_painter_test.dart +++ b/test/chart/line_chart/line_chart_painter_test.dart @@ -2663,7 +2663,7 @@ void main() { final holder = PaintHolder(data, data, 1); final touchResponse = lineChartPainter.handleTouch(const Offset(35, 0), viewSize, holder); - expect(touchResponse, null); + expect(touchResponse.lineBarSpots, null); }); test('test 2', () { @@ -2720,21 +2720,25 @@ void main() { final holder = PaintHolder(data, data, 1); expect( lineChartPainter - .handleTouch(const Offset(30, 0), viewSize, holder)! + .handleTouch(const Offset(30, 0), viewSize, holder) + .lineBarSpots! .length, 1, ); expect( - lineChartPainter.handleTouch( - const Offset(29.99, 0), - viewSize, - holder, - ), + lineChartPainter + .handleTouch( + const Offset(29.99, 0), + viewSize, + holder, + ) + .lineBarSpots, null, ); expect( lineChartPainter - .handleTouch(const Offset(10, 0), viewSize, holder)! + .handleTouch(const Offset(10, 0), viewSize, holder) + .lineBarSpots! .length, 2, ); @@ -2794,14 +2798,14 @@ void main() { final holder = PaintHolder(data, data, 1); final result1 = - lineChartPainter.handleTouch(const Offset(11, 0), viewSize, holder)!; - expect(result1[0].barIndex, 0); - expect(result1[1].barIndex, 1); + lineChartPainter.handleTouch(const Offset(11, 0), viewSize, holder); + expect(result1.lineBarSpots![0].barIndex, 0); + expect(result1.lineBarSpots![1].barIndex, 1); final result2 = - lineChartPainter.handleTouch(const Offset(12, 0), viewSize, holder)!; - expect(result2[0].barIndex, 1); - expect(result2[1].barIndex, 0); + lineChartPainter.handleTouch(const Offset(12, 0), viewSize, holder); + expect(result2.lineBarSpots![0].barIndex, 1); + expect(result2.lineBarSpots![1].barIndex, 0); }); }); diff --git a/test/chart/line_chart/line_chart_painter_test.mocks.dart b/test/chart/line_chart/line_chart_painter_test.mocks.dart index 36127099e..be5479b46 100644 --- a/test/chart/line_chart/line_chart_painter_test.mocks.dart +++ b/test/chart/line_chart/line_chart_painter_test.mocks.dart @@ -1,16 +1,16 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/line_chart/line_chart_painter_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:typed_data' as _i5; +import 'dart:typed_data' as _i6; import 'dart:ui' as _i2; -import 'package:fl_chart/fl_chart.dart' as _i7; +import 'package:fl_chart/fl_chart.dart' as _i5; import 'package:fl_chart/src/chart/base/base_chart/base_chart_painter.dart' as _i10; import 'package:fl_chart/src/chart/line_chart/line_chart_painter.dart' as _i9; -import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i6; +import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i7; import 'package:fl_chart/src/utils/utils.dart' as _i8; import 'package:flutter/cupertino.dart' as _i3; import 'package:flutter/foundation.dart' as _i4; @@ -152,6 +152,27 @@ class _FakePath_9 extends _i1.SmartFake implements _i2.Path { ); } +class _FakeLineTouchResponse_10 extends _i1.SmartFake + implements _i5.LineTouchResponse { + _FakeLineTouchResponse_10( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFlSpot_11 extends _i1.SmartFake implements _i5.FlSpot { + _FakeFlSpot_11( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [Canvas]. /// /// See the documentation for Mockito's code generation for more information. @@ -261,7 +282,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - void transform(_i5.Float64List? matrix4) => super.noSuchMethod( + void transform(_i6.Float64List? matrix4) => super.noSuchMethod( Invocation.method( #transform, [matrix4], @@ -269,13 +290,13 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - _i5.Float64List getTransform() => (super.noSuchMethod( + _i6.Float64List getTransform() => (super.noSuchMethod( Invocation.method( #getTransform, [], ), - returnValue: _i5.Float64List(0), - ) as _i5.Float64List); + returnValue: _i6.Float64List(0), + ) as _i6.Float64List); @override void clipRect( _i2.Rect? rect, { @@ -600,7 +621,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawPoints( _i2.PointMode? pointMode, - _i5.Float32List? points, + _i6.Float32List? points, _i2.Paint? paint, ) => super.noSuchMethod( @@ -659,9 +680,9 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawAtlas( _i2.Image? atlas, - _i5.Float32List? rstTransforms, - _i5.Float32List? rects, - _i5.Int32List? colors, + _i6.Float32List? rstTransforms, + _i6.Float32List? rects, + _i6.Int32List? colors, _i2.BlendMode? blendMode, _i2.Rect? cullRect, _i2.Paint? paint, @@ -705,7 +726,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { /// A class which mocks [CanvasWrapper]. /// /// See the documentation for Mockito's code generation for more information. -class MockCanvasWrapper extends _i1.Mock implements _i6.CanvasWrapper { +class MockCanvasWrapper extends _i1.Mock implements _i7.CanvasWrapper { MockCanvasWrapper() { _i1.throwOnMissingStub(this); } @@ -954,8 +975,8 @@ class MockCanvasWrapper extends _i1.Mock implements _i6.CanvasWrapper { ); @override void drawDot( - _i7.FlDotPainter? painter, - _i7.FlSpot? spot, + _i5.FlDotPainter? painter, + _i5.FlSpot? spot, _i2.Offset? offset, ) => super.noSuchMethod( @@ -975,7 +996,7 @@ class MockCanvasWrapper extends _i1.Mock implements _i6.CanvasWrapper { _i2.Offset? rotationOffset = _i2.Offset.zero, _i2.Offset? drawOffset = _i2.Offset.zero, required double? angle, - required _i6.DrawCallback? drawCallback, + required _i7.DrawCallback? drawCallback, }) => super.noSuchMethod( Invocation.method( @@ -1362,8 +1383,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override void paint( _i3.BuildContext? context, - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1378,8 +1399,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void clipToBorder( - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1393,9 +1414,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawBarLine( - _i6.CanvasWrapper? canvasWrapper, - _i7.LineChartBarData? barData, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i5.LineChartBarData? barData, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1410,10 +1431,10 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawBetweenBarsArea( - _i6.CanvasWrapper? canvasWrapper, - _i7.LineChartData? data, - _i7.BetweenBarsData? betweenBarsData, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i5.LineChartData? data, + _i5.BetweenBarsData? betweenBarsData, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1429,9 +1450,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawDots( - _i6.CanvasWrapper? canvasWrapper, - _i7.LineChartBarData? barData, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i5.LineChartBarData? barData, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1446,9 +1467,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawTouchedSpotsIndicator( - _i6.CanvasWrapper? canvasWrapper, + _i7.CanvasWrapper? canvasWrapper, List<_i9.LineIndexDrawingInfo>? lineIndexDrawingInfo, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1464,9 +1485,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override _i2.Path generateBarPath( _i2.Size? viewSize, - _i7.LineChartBarData? barData, - List<_i7.FlSpot>? barSpots, - _i10.PaintHolder<_i7.LineChartData>? holder, { + _i5.LineChartBarData? barData, + List<_i5.FlSpot>? barSpots, + _i10.PaintHolder<_i5.LineChartData>? holder, { _i2.Path? appendToPath, }) => (super.noSuchMethod( @@ -1497,9 +1518,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override _i2.Path generateNormalBarPath( _i2.Size? viewSize, - _i7.LineChartBarData? barData, - List<_i7.FlSpot>? barSpots, - _i10.PaintHolder<_i7.LineChartData>? holder, { + _i5.LineChartBarData? barData, + List<_i5.FlSpot>? barSpots, + _i10.PaintHolder<_i5.LineChartData>? holder, { _i2.Path? appendToPath, }) => (super.noSuchMethod( @@ -1530,9 +1551,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override _i2.Path generateStepBarPath( _i2.Size? viewSize, - _i7.LineChartBarData? barData, - List<_i7.FlSpot>? barSpots, - _i10.PaintHolder<_i7.LineChartData>? holder, { + _i5.LineChartBarData? barData, + List<_i5.FlSpot>? barSpots, + _i10.PaintHolder<_i5.LineChartData>? holder, { _i2.Path? appendToPath, }) => (super.noSuchMethod( @@ -1563,10 +1584,10 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override _i2.Path generateBelowBarPath( _i2.Size? viewSize, - _i7.LineChartBarData? barData, + _i5.LineChartBarData? barData, _i2.Path? barPath, - List<_i7.FlSpot>? barSpots, - _i10.PaintHolder<_i7.LineChartData>? holder, { + List<_i5.FlSpot>? barSpots, + _i10.PaintHolder<_i5.LineChartData>? holder, { bool? fillCompletely = false, }) => (super.noSuchMethod( @@ -1599,10 +1620,10 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override _i2.Path generateAboveBarPath( _i2.Size? viewSize, - _i7.LineChartBarData? barData, + _i5.LineChartBarData? barData, _i2.Path? barPath, - List<_i7.FlSpot>? barSpots, - _i10.PaintHolder<_i7.LineChartData>? holder, { + List<_i5.FlSpot>? barSpots, + _i10.PaintHolder<_i5.LineChartData>? holder, { bool? fillCompletely = false, }) => (super.noSuchMethod( @@ -1634,11 +1655,11 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ) as _i2.Path); @override void drawBelowBar( - _i6.CanvasWrapper? canvasWrapper, + _i7.CanvasWrapper? canvasWrapper, _i2.Path? belowBarPath, _i2.Path? filledAboveBarPath, - _i10.PaintHolder<_i7.LineChartData>? holder, - _i7.LineChartBarData? barData, + _i10.PaintHolder<_i5.LineChartData>? holder, + _i5.LineChartBarData? barData, ) => super.noSuchMethod( Invocation.method( @@ -1655,11 +1676,11 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawAboveBar( - _i6.CanvasWrapper? canvasWrapper, + _i7.CanvasWrapper? canvasWrapper, _i2.Path? aboveBarPath, _i2.Path? filledBelowBarPath, - _i10.PaintHolder<_i7.LineChartData>? holder, - _i7.LineChartBarData? barData, + _i10.PaintHolder<_i5.LineChartData>? holder, + _i5.LineChartBarData? barData, ) => super.noSuchMethod( Invocation.method( @@ -1676,11 +1697,11 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawBetweenBar( - _i6.CanvasWrapper? canvasWrapper, + _i7.CanvasWrapper? canvasWrapper, _i2.Path? barPath, - _i7.BetweenBarsData? betweenBarsData, + _i5.BetweenBarsData? betweenBarsData, _i2.Rect? aroundRect, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1697,9 +1718,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawBarShadow( - _i6.CanvasWrapper? canvasWrapper, + _i7.CanvasWrapper? canvasWrapper, _i2.Path? barPath, - _i7.LineChartBarData? barData, + _i5.LineChartBarData? barData, ) => super.noSuchMethod( Invocation.method( @@ -1714,10 +1735,10 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawBar( - _i6.CanvasWrapper? canvasWrapper, + _i7.CanvasWrapper? canvasWrapper, _i2.Path? barPath, - _i7.LineChartBarData? barData, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i5.LineChartBarData? barData, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1734,11 +1755,11 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override void drawTouchTooltip( _i3.BuildContext? context, - _i6.CanvasWrapper? canvasWrapper, - _i7.LineTouchTooltipData? tooltipData, - _i7.FlSpot? showOnSpot, - _i7.ShowingTooltipIndicators? showingTooltipSpots, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i5.LineTouchTooltipData? tooltipData, + _i5.FlSpot? showOnSpot, + _i5.ShowingTooltipIndicators? showingTooltipSpots, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1756,9 +1777,9 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override double getBarLineXLength( - _i7.LineChartBarData? barData, + _i5.LineChartBarData? barData, _i2.Size? chartUsableSize, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1772,26 +1793,39 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { returnValue: 0.0, ) as double); @override - List<_i7.TouchLineBarSpot>? handleTouch( + _i5.LineTouchResponse handleTouch( _i2.Offset? localPosition, _i2.Size? size, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => - (super.noSuchMethod(Invocation.method( - #handleTouch, - [ - localPosition, - size, - holder, - ], - )) as List<_i7.TouchLineBarSpot>?); + (super.noSuchMethod( + Invocation.method( + #handleTouch, + [ + localPosition, + size, + holder, + ], + ), + returnValue: _FakeLineTouchResponse_10( + this, + Invocation.method( + #handleTouch, + [ + localPosition, + size, + holder, + ], + ), + ), + ) as _i5.LineTouchResponse); @override - _i7.TouchLineBarSpot? getNearestTouchedSpot( + _i5.TouchLineBarSpot? getNearestTouchedSpot( _i2.Size? viewSize, _i2.Offset? touchedPoint, - _i7.LineChartBarData? barData, + _i5.LineChartBarData? barData, int? barDataPosition, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => (super.noSuchMethod(Invocation.method( #getNearestTouchedSpot, @@ -1802,11 +1836,11 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { barDataPosition, holder, ], - )) as _i7.TouchLineBarSpot?); + )) as _i5.TouchLineBarSpot?); @override void drawGrid( - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1820,8 +1854,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawBackground( - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1835,8 +1869,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { ); @override void drawRangeAnnotation( - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1851,8 +1885,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override void drawExtraLines( _i3.BuildContext? context, - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1868,8 +1902,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override void drawHorizontalLines( _i3.BuildContext? context, - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1887,8 +1921,8 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { @override void drawVerticalLines( _i3.BuildContext? context, - _i6.CanvasWrapper? canvasWrapper, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i7.CanvasWrapper? canvasWrapper, + _i10.PaintHolder<_i5.LineChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1907,7 +1941,7 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { double getPixelX( double? spotX, _i2.Size? viewSize, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1924,7 +1958,7 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { double getPixelY( double? spotY, _i2.Size? viewSize, - _i10.PaintHolder<_i7.LineChartData>? holder, + _i10.PaintHolder<_i5.LineChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1938,10 +1972,40 @@ class MockLineChartPainter extends _i1.Mock implements _i9.LineChartPainter { returnValue: 0.0, ) as double); @override + _i5.FlSpot getTouchedCoordinates( + double? pixelX, + double? pixelY, + _i2.Size? viewSize, + _i10.PaintHolder<_i5.LineChartData>? holder, + ) => + (super.noSuchMethod( + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + returnValue: _FakeFlSpot_11( + this, + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + ), + ) as _i5.FlSpot); + @override double getTooltipLeft( double? dx, double? tooltipWidth, - _i7.FLHorizontalAlignment? tooltipHorizontalAlignment, + _i5.FLHorizontalAlignment? tooltipHorizontalAlignment, double? tooltipHorizontalOffset, ) => (super.noSuchMethod( diff --git a/test/chart/line_chart/line_chart_renderer_test.dart b/test/chart/line_chart/line_chart_renderer_test.dart index 10463b558..2322af395 100644 --- a/test/chart/line_chart/line_chart_renderer_test.dart +++ b/test/chart/line_chart/line_chart_renderer_test.dart @@ -97,7 +97,7 @@ void main() { 'size': inv.positionalArguments[1] as Size, 'paint_holder': inv.positionalArguments[2] as PaintHolder, }); - return MockData.lineTouchResponse1.lineBarSpots; + return MockData.lineTouchResponse1; }); final touchResponse = renderLineChart.getResponseAtLocation(MockData.offset1); diff --git a/test/chart/line_chart/line_chart_renderer_test.mocks.dart b/test/chart/line_chart/line_chart_renderer_test.mocks.dart index 97a29906e..8a177381f 100644 --- a/test/chart/line_chart/line_chart_renderer_test.mocks.dart +++ b/test/chart/line_chart/line_chart_renderer_test.mocks.dart @@ -1,22 +1,22 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/line_chart/line_chart_renderer_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:typed_data' as _i7; +import 'dart:typed_data' as _i8; import 'dart:ui' as _i2; -import 'package:fl_chart/fl_chart.dart' as _i13; +import 'package:fl_chart/fl_chart.dart' as _i7; import 'package:fl_chart/src/chart/base/base_chart/base_chart_painter.dart' - as _i12; -import 'package:fl_chart/src/chart/line_chart/line_chart_painter.dart' as _i10; -import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i11; + as _i13; +import 'package:fl_chart/src/chart/line_chart/line_chart_painter.dart' as _i11; +import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i12; import 'package:flutter/foundation.dart' as _i5; -import 'package:flutter/gestures.dart' as _i8; +import 'package:flutter/gestures.dart' as _i9; import 'package:flutter/material.dart' as _i6; import 'package:flutter/rendering.dart' as _i3; import 'package:flutter/src/rendering/layer.dart' as _i4; -import 'package:flutter/src/widgets/notification_listener.dart' as _i9; +import 'package:flutter/src/widgets/notification_listener.dart' as _i10; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -147,6 +147,27 @@ class _FakePath_8 extends _i1.SmartFake implements _i2.Path { ); } +class _FakeLineTouchResponse_9 extends _i1.SmartFake + implements _i7.LineTouchResponse { + _FakeLineTouchResponse_9( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFlSpot_10 extends _i1.SmartFake implements _i7.FlSpot { + _FakeFlSpot_10( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [Canvas]. /// /// See the documentation for Mockito's code generation for more information. @@ -256,7 +277,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - void transform(_i7.Float64List? matrix4) => super.noSuchMethod( + void transform(_i8.Float64List? matrix4) => super.noSuchMethod( Invocation.method( #transform, [matrix4], @@ -264,13 +285,13 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - _i7.Float64List getTransform() => (super.noSuchMethod( + _i8.Float64List getTransform() => (super.noSuchMethod( Invocation.method( #getTransform, [], ), - returnValue: _i7.Float64List(0), - ) as _i7.Float64List); + returnValue: _i8.Float64List(0), + ) as _i8.Float64List); @override void clipRect( _i2.Rect? rect, { @@ -595,7 +616,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawPoints( _i2.PointMode? pointMode, - _i7.Float32List? points, + _i8.Float32List? points, _i2.Paint? paint, ) => super.noSuchMethod( @@ -654,9 +675,9 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawAtlas( _i2.Image? atlas, - _i7.Float32List? rstTransforms, - _i7.Float32List? rects, - _i7.Int32List? colors, + _i8.Float32List? rstTransforms, + _i8.Float32List? rects, + _i8.Int32List? colors, _i2.BlendMode? blendMode, _i2.Rect? cullRect, _i2.Paint? paint, @@ -932,7 +953,7 @@ class MockPaintingContext extends _i1.Mock implements _i3.PaintingContext { _i4.TransformLayer? pushTransform( bool? needsCompositing, _i2.Offset? offset, - _i8.Matrix4? transform, + _i9.Matrix4? transform, _i3.PaintingContextCallback? painter, { _i4.TransformLayer? oldLayer, }) => @@ -1099,7 +1120,7 @@ class MockBuildContext extends _i1.Mock implements _i6.BuildContext { returnValueForMissingStub: null, ); @override - void dispatchNotification(_i9.Notification? notification) => + void dispatchNotification(_i10.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, @@ -1178,7 +1199,7 @@ class MockBuildContext extends _i1.Mock implements _i6.BuildContext { /// A class which mocks [LineChartPainter]. /// /// See the documentation for Mockito's code generation for more information. -class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { +class MockLineChartPainter extends _i1.Mock implements _i11.LineChartPainter { MockLineChartPainter() { _i1.throwOnMissingStub(this); } @@ -1186,8 +1207,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override void paint( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1202,8 +1223,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void clipToBorder( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1217,9 +1238,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawBarLine( - _i11.CanvasWrapper? canvasWrapper, - _i13.LineChartBarData? barData, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i7.LineChartBarData? barData, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1234,10 +1255,10 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawBetweenBarsArea( - _i11.CanvasWrapper? canvasWrapper, - _i13.LineChartData? data, - _i13.BetweenBarsData? betweenBarsData, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i7.LineChartData? data, + _i7.BetweenBarsData? betweenBarsData, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1253,9 +1274,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawDots( - _i11.CanvasWrapper? canvasWrapper, - _i13.LineChartBarData? barData, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i7.LineChartBarData? barData, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1270,9 +1291,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawTouchedSpotsIndicator( - _i11.CanvasWrapper? canvasWrapper, - List<_i10.LineIndexDrawingInfo>? lineIndexDrawingInfo, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + List<_i11.LineIndexDrawingInfo>? lineIndexDrawingInfo, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1288,9 +1309,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override _i2.Path generateBarPath( _i2.Size? viewSize, - _i13.LineChartBarData? barData, - List<_i13.FlSpot>? barSpots, - _i12.PaintHolder<_i13.LineChartData>? holder, { + _i7.LineChartBarData? barData, + List<_i7.FlSpot>? barSpots, + _i13.PaintHolder<_i7.LineChartData>? holder, { _i2.Path? appendToPath, }) => (super.noSuchMethod( @@ -1321,9 +1342,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override _i2.Path generateNormalBarPath( _i2.Size? viewSize, - _i13.LineChartBarData? barData, - List<_i13.FlSpot>? barSpots, - _i12.PaintHolder<_i13.LineChartData>? holder, { + _i7.LineChartBarData? barData, + List<_i7.FlSpot>? barSpots, + _i13.PaintHolder<_i7.LineChartData>? holder, { _i2.Path? appendToPath, }) => (super.noSuchMethod( @@ -1354,9 +1375,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override _i2.Path generateStepBarPath( _i2.Size? viewSize, - _i13.LineChartBarData? barData, - List<_i13.FlSpot>? barSpots, - _i12.PaintHolder<_i13.LineChartData>? holder, { + _i7.LineChartBarData? barData, + List<_i7.FlSpot>? barSpots, + _i13.PaintHolder<_i7.LineChartData>? holder, { _i2.Path? appendToPath, }) => (super.noSuchMethod( @@ -1387,10 +1408,10 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override _i2.Path generateBelowBarPath( _i2.Size? viewSize, - _i13.LineChartBarData? barData, + _i7.LineChartBarData? barData, _i2.Path? barPath, - List<_i13.FlSpot>? barSpots, - _i12.PaintHolder<_i13.LineChartData>? holder, { + List<_i7.FlSpot>? barSpots, + _i13.PaintHolder<_i7.LineChartData>? holder, { bool? fillCompletely = false, }) => (super.noSuchMethod( @@ -1423,10 +1444,10 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override _i2.Path generateAboveBarPath( _i2.Size? viewSize, - _i13.LineChartBarData? barData, + _i7.LineChartBarData? barData, _i2.Path? barPath, - List<_i13.FlSpot>? barSpots, - _i12.PaintHolder<_i13.LineChartData>? holder, { + List<_i7.FlSpot>? barSpots, + _i13.PaintHolder<_i7.LineChartData>? holder, { bool? fillCompletely = false, }) => (super.noSuchMethod( @@ -1458,11 +1479,11 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ) as _i2.Path); @override void drawBelowBar( - _i11.CanvasWrapper? canvasWrapper, + _i12.CanvasWrapper? canvasWrapper, _i2.Path? belowBarPath, _i2.Path? filledAboveBarPath, - _i12.PaintHolder<_i13.LineChartData>? holder, - _i13.LineChartBarData? barData, + _i13.PaintHolder<_i7.LineChartData>? holder, + _i7.LineChartBarData? barData, ) => super.noSuchMethod( Invocation.method( @@ -1479,11 +1500,11 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawAboveBar( - _i11.CanvasWrapper? canvasWrapper, + _i12.CanvasWrapper? canvasWrapper, _i2.Path? aboveBarPath, _i2.Path? filledBelowBarPath, - _i12.PaintHolder<_i13.LineChartData>? holder, - _i13.LineChartBarData? barData, + _i13.PaintHolder<_i7.LineChartData>? holder, + _i7.LineChartBarData? barData, ) => super.noSuchMethod( Invocation.method( @@ -1500,11 +1521,11 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawBetweenBar( - _i11.CanvasWrapper? canvasWrapper, + _i12.CanvasWrapper? canvasWrapper, _i2.Path? barPath, - _i13.BetweenBarsData? betweenBarsData, + _i7.BetweenBarsData? betweenBarsData, _i2.Rect? aroundRect, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1521,9 +1542,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawBarShadow( - _i11.CanvasWrapper? canvasWrapper, + _i12.CanvasWrapper? canvasWrapper, _i2.Path? barPath, - _i13.LineChartBarData? barData, + _i7.LineChartBarData? barData, ) => super.noSuchMethod( Invocation.method( @@ -1538,10 +1559,10 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawBar( - _i11.CanvasWrapper? canvasWrapper, + _i12.CanvasWrapper? canvasWrapper, _i2.Path? barPath, - _i13.LineChartBarData? barData, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i7.LineChartBarData? barData, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1558,11 +1579,11 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override void drawTouchTooltip( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i13.LineTouchTooltipData? tooltipData, - _i13.FlSpot? showOnSpot, - _i13.ShowingTooltipIndicators? showingTooltipSpots, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i7.LineTouchTooltipData? tooltipData, + _i7.FlSpot? showOnSpot, + _i7.ShowingTooltipIndicators? showingTooltipSpots, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1580,9 +1601,9 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override double getBarLineXLength( - _i13.LineChartBarData? barData, + _i7.LineChartBarData? barData, _i2.Size? chartUsableSize, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1596,26 +1617,39 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { returnValue: 0.0, ) as double); @override - List<_i13.TouchLineBarSpot>? handleTouch( + _i7.LineTouchResponse handleTouch( _i2.Offset? localPosition, _i2.Size? size, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => - (super.noSuchMethod(Invocation.method( - #handleTouch, - [ - localPosition, - size, - holder, - ], - )) as List<_i13.TouchLineBarSpot>?); + (super.noSuchMethod( + Invocation.method( + #handleTouch, + [ + localPosition, + size, + holder, + ], + ), + returnValue: _FakeLineTouchResponse_9( + this, + Invocation.method( + #handleTouch, + [ + localPosition, + size, + holder, + ], + ), + ), + ) as _i7.LineTouchResponse); @override - _i13.TouchLineBarSpot? getNearestTouchedSpot( + _i7.TouchLineBarSpot? getNearestTouchedSpot( _i2.Size? viewSize, _i2.Offset? touchedPoint, - _i13.LineChartBarData? barData, + _i7.LineChartBarData? barData, int? barDataPosition, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => (super.noSuchMethod(Invocation.method( #getNearestTouchedSpot, @@ -1626,11 +1660,11 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { barDataPosition, holder, ], - )) as _i13.TouchLineBarSpot?); + )) as _i7.TouchLineBarSpot?); @override void drawGrid( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1644,8 +1678,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawBackground( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1659,8 +1693,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { ); @override void drawRangeAnnotation( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1675,8 +1709,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override void drawExtraLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1692,8 +1726,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override void drawHorizontalLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1711,8 +1745,8 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { @override void drawVerticalLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.LineChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1731,7 +1765,7 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { double getPixelX( double? spotX, _i2.Size? viewSize, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1748,7 +1782,7 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { double getPixelY( double? spotY, _i2.Size? viewSize, - _i12.PaintHolder<_i13.LineChartData>? holder, + _i13.PaintHolder<_i7.LineChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1762,10 +1796,40 @@ class MockLineChartPainter extends _i1.Mock implements _i10.LineChartPainter { returnValue: 0.0, ) as double); @override + _i7.FlSpot getTouchedCoordinates( + double? pixelX, + double? pixelY, + _i2.Size? viewSize, + _i13.PaintHolder<_i7.LineChartData>? holder, + ) => + (super.noSuchMethod( + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + returnValue: _FakeFlSpot_10( + this, + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + ), + ) as _i7.FlSpot); + @override double getTooltipLeft( double? dx, double? tooltipWidth, - _i13.FLHorizontalAlignment? tooltipHorizontalAlignment, + _i7.FLHorizontalAlignment? tooltipHorizontalAlignment, double? tooltipHorizontalOffset, ) => (super.noSuchMethod( diff --git a/test/chart/pie_chart/pie_chart_painter_test.mocks.dart b/test/chart/pie_chart/pie_chart_painter_test.mocks.dart index a1d0683e1..ec4a3623e 100644 --- a/test/chart/pie_chart/pie_chart_painter_test.mocks.dart +++ b/test/chart/pie_chart/pie_chart_painter_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/pie_chart/pie_chart_painter_test.dart. // Do not manually edit this file. diff --git a/test/chart/pie_chart/pie_chart_renderer_test.mocks.dart b/test/chart/pie_chart/pie_chart_renderer_test.mocks.dart index 8e58b42b5..240627c32 100644 --- a/test/chart/pie_chart/pie_chart_renderer_test.mocks.dart +++ b/test/chart/pie_chart/pie_chart_renderer_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/pie_chart/pie_chart_renderer_test.dart. // Do not manually edit this file. diff --git a/test/chart/radar_chart/radar_chart_painter_test.mocks.dart b/test/chart/radar_chart/radar_chart_painter_test.mocks.dart index 84b2cd6ef..29a27a859 100644 --- a/test/chart/radar_chart/radar_chart_painter_test.mocks.dart +++ b/test/chart/radar_chart/radar_chart_painter_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/radar_chart/radar_chart_painter_test.dart. // Do not manually edit this file. diff --git a/test/chart/radar_chart/radar_chart_renderer_test.mocks.dart b/test/chart/radar_chart/radar_chart_renderer_test.mocks.dart index 13ac05859..582bb7f19 100644 --- a/test/chart/radar_chart/radar_chart_renderer_test.mocks.dart +++ b/test/chart/radar_chart/radar_chart_renderer_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/radar_chart/radar_chart_renderer_test.dart. // Do not manually edit this file. diff --git a/test/chart/scatter_chart/scatter_chart_painter_test.mocks.dart b/test/chart/scatter_chart/scatter_chart_painter_test.mocks.dart index 3305195d0..03c2ebecc 100644 --- a/test/chart/scatter_chart/scatter_chart_painter_test.mocks.dart +++ b/test/chart/scatter_chart/scatter_chart_painter_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/scatter_chart/scatter_chart_painter_test.dart. // Do not manually edit this file. diff --git a/test/chart/scatter_chart/scatter_chart_renderer_test.mocks.dart b/test/chart/scatter_chart/scatter_chart_renderer_test.mocks.dart index 890e683be..27c49793b 100644 --- a/test/chart/scatter_chart/scatter_chart_renderer_test.mocks.dart +++ b/test/chart/scatter_chart/scatter_chart_renderer_test.mocks.dart @@ -1,23 +1,23 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/chart/scatter_chart/scatter_chart_renderer_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:typed_data' as _i7; +import 'dart:typed_data' as _i8; import 'dart:ui' as _i2; -import 'package:fl_chart/fl_chart.dart' as _i13; +import 'package:fl_chart/fl_chart.dart' as _i7; import 'package:fl_chart/src/chart/base/base_chart/base_chart_painter.dart' - as _i12; + as _i13; import 'package:fl_chart/src/chart/scatter_chart/scatter_chart_painter.dart' - as _i10; -import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i11; + as _i11; +import 'package:fl_chart/src/utils/canvas_wrapper.dart' as _i12; import 'package:flutter/foundation.dart' as _i5; -import 'package:flutter/gestures.dart' as _i8; +import 'package:flutter/gestures.dart' as _i9; import 'package:flutter/material.dart' as _i6; import 'package:flutter/rendering.dart' as _i3; import 'package:flutter/src/rendering/layer.dart' as _i4; -import 'package:flutter/src/widgets/notification_listener.dart' as _i9; +import 'package:flutter/src/widgets/notification_listener.dart' as _i10; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -138,6 +138,16 @@ class _FakeDiagnosticsNode_7 extends _i1.SmartFake super.toString(); } +class _FakeFlSpot_8 extends _i1.SmartFake implements _i7.FlSpot { + _FakeFlSpot_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [Canvas]. /// /// See the documentation for Mockito's code generation for more information. @@ -247,7 +257,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - void transform(_i7.Float64List? matrix4) => super.noSuchMethod( + void transform(_i8.Float64List? matrix4) => super.noSuchMethod( Invocation.method( #transform, [matrix4], @@ -255,13 +265,13 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { returnValueForMissingStub: null, ); @override - _i7.Float64List getTransform() => (super.noSuchMethod( + _i8.Float64List getTransform() => (super.noSuchMethod( Invocation.method( #getTransform, [], ), - returnValue: _i7.Float64List(0), - ) as _i7.Float64List); + returnValue: _i8.Float64List(0), + ) as _i8.Float64List); @override void clipRect( _i2.Rect? rect, { @@ -586,7 +596,7 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawPoints( _i2.PointMode? pointMode, - _i7.Float32List? points, + _i8.Float32List? points, _i2.Paint? paint, ) => super.noSuchMethod( @@ -645,9 +655,9 @@ class MockCanvas extends _i1.Mock implements _i2.Canvas { @override void drawRawAtlas( _i2.Image? atlas, - _i7.Float32List? rstTransforms, - _i7.Float32List? rects, - _i7.Int32List? colors, + _i8.Float32List? rstTransforms, + _i8.Float32List? rects, + _i8.Int32List? colors, _i2.BlendMode? blendMode, _i2.Rect? cullRect, _i2.Paint? paint, @@ -923,7 +933,7 @@ class MockPaintingContext extends _i1.Mock implements _i3.PaintingContext { _i4.TransformLayer? pushTransform( bool? needsCompositing, _i2.Offset? offset, - _i8.Matrix4? transform, + _i9.Matrix4? transform, _i3.PaintingContextCallback? painter, { _i4.TransformLayer? oldLayer, }) => @@ -1090,7 +1100,7 @@ class MockBuildContext extends _i1.Mock implements _i6.BuildContext { returnValueForMissingStub: null, ); @override - void dispatchNotification(_i9.Notification? notification) => + void dispatchNotification(_i10.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, @@ -1170,7 +1180,7 @@ class MockBuildContext extends _i1.Mock implements _i6.BuildContext { /// /// See the documentation for Mockito's code generation for more information. class MockScatterChartPainter extends _i1.Mock - implements _i10.ScatterChartPainter { + implements _i11.ScatterChartPainter { MockScatterChartPainter() { _i1.throwOnMissingStub(this); } @@ -1178,8 +1188,8 @@ class MockScatterChartPainter extends _i1.Mock @override void paint( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1195,8 +1205,8 @@ class MockScatterChartPainter extends _i1.Mock @override void drawSpots( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1212,8 +1222,8 @@ class MockScatterChartPainter extends _i1.Mock @override void drawTouchTooltips( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1229,10 +1239,10 @@ class MockScatterChartPainter extends _i1.Mock @override void drawTouchTooltip( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i13.ScatterTouchTooltipData? tooltipData, - _i13.ScatterSpot? showOnSpot, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i7.ScatterTouchTooltipData? tooltipData, + _i7.ScatterSpot? showOnSpot, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1248,10 +1258,10 @@ class MockScatterChartPainter extends _i1.Mock returnValueForMissingStub: null, ); @override - _i13.ScatterTouchedSpot? handleTouch( + _i7.ScatterTouchedSpot? handleTouch( _i2.Offset? localPosition, _i2.Size? viewSize, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => (super.noSuchMethod(Invocation.method( #handleTouch, @@ -1260,11 +1270,11 @@ class MockScatterChartPainter extends _i1.Mock viewSize, holder, ], - )) as _i13.ScatterTouchedSpot?); + )) as _i7.ScatterTouchedSpot?); @override void drawGrid( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1278,8 +1288,8 @@ class MockScatterChartPainter extends _i1.Mock ); @override void drawBackground( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1293,8 +1303,8 @@ class MockScatterChartPainter extends _i1.Mock ); @override void drawRangeAnnotation( - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1309,8 +1319,8 @@ class MockScatterChartPainter extends _i1.Mock @override void drawExtraLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => super.noSuchMethod( Invocation.method( @@ -1326,8 +1336,8 @@ class MockScatterChartPainter extends _i1.Mock @override void drawHorizontalLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1345,8 +1355,8 @@ class MockScatterChartPainter extends _i1.Mock @override void drawVerticalLines( _i6.BuildContext? context, - _i11.CanvasWrapper? canvasWrapper, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i12.CanvasWrapper? canvasWrapper, + _i13.PaintHolder<_i7.ScatterChartData>? holder, _i2.Size? viewSize, ) => super.noSuchMethod( @@ -1365,7 +1375,7 @@ class MockScatterChartPainter extends _i1.Mock double getPixelX( double? spotX, _i2.Size? viewSize, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1382,7 +1392,7 @@ class MockScatterChartPainter extends _i1.Mock double getPixelY( double? spotY, _i2.Size? viewSize, - _i12.PaintHolder<_i13.ScatterChartData>? holder, + _i13.PaintHolder<_i7.ScatterChartData>? holder, ) => (super.noSuchMethod( Invocation.method( @@ -1396,10 +1406,40 @@ class MockScatterChartPainter extends _i1.Mock returnValue: 0.0, ) as double); @override + _i7.FlSpot getTouchedCoordinates( + double? pixelX, + double? pixelY, + _i2.Size? viewSize, + _i13.PaintHolder<_i7.ScatterChartData>? holder, + ) => + (super.noSuchMethod( + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + returnValue: _FakeFlSpot_8( + this, + Invocation.method( + #getTouchedCoordinates, + [ + pixelX, + pixelY, + viewSize, + holder, + ], + ), + ), + ) as _i7.FlSpot); + @override double getTooltipLeft( double? dx, double? tooltipWidth, - _i13.FLHorizontalAlignment? tooltipHorizontalAlignment, + _i7.FLHorizontalAlignment? tooltipHorizontalAlignment, double? tooltipHorizontalOffset, ) => (super.noSuchMethod( diff --git a/test/utils/canvas_wrapper_test.mocks.dart b/test/utils/canvas_wrapper_test.mocks.dart index cccfd2559..6eba7105a 100644 --- a/test/utils/canvas_wrapper_test.mocks.dart +++ b/test/utils/canvas_wrapper_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/utils/canvas_wrapper_test.dart. // Do not manually edit this file. diff --git a/test/utils/utils_test.mocks.dart b/test/utils/utils_test.mocks.dart index fe4c97927..3aa8f0cad 100644 --- a/test/utils/utils_test.mocks.dart +++ b/test/utils/utils_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in fl_chart/test/utils/utils_test.dart. // Do not manually edit this file. From 773cabfaf3ab9772da8ade905ef28a008b6da8d9 Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 21:06:58 +0200 Subject: [PATCH 03/10] Add dragSpotUpdatedCallback functionality --- lib/src/chart/line_chart/line_chart.dart | 14 +++++++- lib/src/chart/line_chart/line_chart_data.dart | 34 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 82a601469..8de97dab2 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -40,6 +40,8 @@ class _LineChartState extends AnimatedWidgetBaseState { /// but we need to keep the provided callback to notify it too. BaseTouchCallback? _providedTouchCallback; + DragSpotUpdatedCallback? _dragSpotUpdatedCallback; + final List _showingTouchedTooltips = []; final Map> _showingTouchedIndicators = {}; @@ -101,6 +103,7 @@ class _LineChartState extends AnimatedWidgetBaseState { final lineTouchData = widget.data.lineTouchData; if (lineTouchData.enabled && lineTouchData.handleBuiltInTouches) { _providedTouchCallback = lineTouchData.touchCallback; + _dragSpotUpdatedCallback = lineTouchData.dragSpotUpdatedCallback; return widget.data.copyWith( lineBarsData: _lineBarsData, lineTouchData: widget.data.lineTouchData.copyWith( @@ -121,18 +124,25 @@ class _LineChartState extends AnimatedWidgetBaseState { return; } + // Cancel dragging if (event is FlPanEndEvent || event is FlLongPressEnd) { setState(() { _draggingSpotIndexes = null; }); } + // if indexes of dragging spot exist, changes it's position if (_draggingSpotIndexes != null) { + final (barIndex, spotIndex) = _draggingSpotIndexes!; setState(() { - final (barIndex, spotIndex) = _draggingSpotIndexes!; _lineBarsData[barIndex].spots[spotIndex] = touchResponse!.touchedAxesPoint!; }); + _dragSpotUpdatedCallback?.call(UpdatedDragSpotsData( + barIndex, + spotIndex, + _lineBarsData[barIndex].spots, + )); } _providedTouchCallback?.call(event, touchResponse); @@ -162,6 +172,8 @@ class _LineChartState extends AnimatedWidgetBaseState { ..add(ShowingTooltipIndicators(sortedLineSpots)); }); + // If there is needed event and any lineBar with .isDraggable flag exists, + // sets indexes of needed spot and starts dragging process. if (event is FlPanStartEvent || event is FlLongPressStart) { final barIndex = touchResponse.lineBarSpots?.first.barIndex; final spotIndex = touchResponse.lineBarSpots?.first.spotIndex; diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index f4c9ce1ec..388b09683 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -1076,6 +1076,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { BaseTouchCallback? touchCallback, MouseCursorResolver? mouseCursorResolver, Duration? longPressDuration, + this.dragSpotUpdatedCallback, this.touchTooltipData = const LineTouchTooltipData(), this.getTouchedSpotIndicator = defaultTouchedIndicators, this.touchSpotThreshold = 10, @@ -1096,6 +1097,8 @@ class LineTouchData extends FlTouchData with EquatableMixin { /// Configs of how touch indicator looks like. final GetTouchedSpotIndicator getTouchedSpotIndicator; + final DragSpotUpdatedCallback? dragSpotUpdatedCallback; + /// Distance threshold to handle the touch event. final double touchSpotThreshold; @@ -1120,6 +1123,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { bool? enabled, BaseTouchCallback? touchCallback, MouseCursorResolver? mouseCursorResolver, + DragSpotUpdatedCallback? dragSpotUpdatedCallback, Duration? longPressDuration, LineTouchTooltipData? touchTooltipData, GetTouchedSpotIndicator? getTouchedSpotIndicator, @@ -1133,6 +1137,8 @@ class LineTouchData extends FlTouchData with EquatableMixin { enabled: enabled ?? this.enabled, touchCallback: touchCallback ?? this.touchCallback, mouseCursorResolver: mouseCursorResolver ?? this.mouseCursorResolver, + dragSpotUpdatedCallback: + dragSpotUpdatedCallback ?? this.dragSpotUpdatedCallback, longPressDuration: longPressDuration ?? this.longPressDuration, touchTooltipData: touchTooltipData ?? this.touchTooltipData, getTouchedSpotIndicator: @@ -1159,6 +1165,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { handleBuiltInTouches, getTouchLineStart, getTouchLineEnd, + dragSpotUpdatedCallback, ]; } @@ -1185,6 +1192,8 @@ typedef CalculateTouchDistance = double Function( Offset spotPixelCoordinates, ); +typedef DragSpotUpdatedCallback = void Function(UpdatedDragSpotsData); + /// Default distanceCalculator only considers distance on x axis double _xDistance(Offset touchPoint, Offset spotPixelCoordinates) { return (touchPoint.dx - spotPixelCoordinates.dx).abs(); @@ -1387,6 +1396,31 @@ class LineBarSpot extends FlSpot with EquatableMixin { ]; } +/// Contains information about spots that have been updated using dragging feature. +class UpdatedDragSpotsData with EquatableMixin { + const UpdatedDragSpotsData( + this.updatedBarIndex, + this.updatedSpotIndex, + this.newSpots, + ); + + /// Index of updated bar + final int updatedBarIndex; + + /// Index of updated spot + final int updatedSpotIndex; + + /// New list of spots in updated line bar + final List newSpots; + + @override + List get props => [ + updatedBarIndex, + updatedSpotIndex, + newSpots, + ]; +} + /// A [LineBarSpot] that holds information about the event that selected it class TouchLineBarSpot extends LineBarSpot { TouchLineBarSpot( From 8430ec3e3fbd9a79c92901cfe0462f21e7a7eece Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 21:16:48 +0200 Subject: [PATCH 04/10] Update changelog --- CHANGELOG.md | 1 + lib/src/chart/line_chart/line_chart.dart | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99114db56..2ef4cbfd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * **BUGFIX** (by @Anas35) Fix Tooltip not displaying when value from BackgroundBarChartRodData is less than zero. #1345. * **BUGFIX** (by @imaNNeo) Fix Negative BarChartRodStackItem are not drawn correctly bug, #1347 * **BUGFIX** (by @imaNNeo) Fix bar_chart_helper minY calculation bug, #1388 +* **FEATURE** (by @G33kFreak) Add drag spots feature for LineChart, [#1420](https://github.com/imaNNeo/fl_chart/issues/1420) ## 0.63.0 * **BUGFIX** (by @imaNNeo) Fix PieChart crash on web-renderer html by ignoring `sectionsSpace` when `Path.combine()` does not work (it's flutter engine [issue](https://github.com/flutter/flutter/issues/44572)), #955 diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 8de97dab2..95cd3a3a2 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -138,11 +138,13 @@ class _LineChartState extends AnimatedWidgetBaseState { _lineBarsData[barIndex].spots[spotIndex] = touchResponse!.touchedAxesPoint!; }); - _dragSpotUpdatedCallback?.call(UpdatedDragSpotsData( - barIndex, - spotIndex, - _lineBarsData[barIndex].spots, - )); + _dragSpotUpdatedCallback?.call( + UpdatedDragSpotsData( + barIndex, + spotIndex, + _lineBarsData[barIndex].spots, + ), + ); } _providedTouchCallback?.call(event, touchResponse); From 99d24842859dd80f9415fd204d19a79e1289fbbc Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 21:46:12 +0200 Subject: [PATCH 05/10] Add sample of draggable line chart --- .../presentation/samples/chart_samples.dart | 2 + .../samples/line/line_chart_sample12.dart | 132 ++++++++++++++++++ lib/src/chart/line_chart/line_chart.dart | 24 ++-- lib/src/chart/line_chart/line_chart_data.dart | 14 +- 4 files changed, 155 insertions(+), 17 deletions(-) create mode 100644 example/lib/presentation/samples/line/line_chart_sample12.dart diff --git a/example/lib/presentation/samples/chart_samples.dart b/example/lib/presentation/samples/chart_samples.dart index 4114cd5f6..f5c789554 100644 --- a/example/lib/presentation/samples/chart_samples.dart +++ b/example/lib/presentation/samples/chart_samples.dart @@ -11,6 +11,7 @@ import 'chart_sample.dart'; import 'line/line_chart_sample1.dart'; import 'line/line_chart_sample10.dart'; import 'line/line_chart_sample11.dart'; +import 'line/line_chart_sample12.dart'; import 'line/line_chart_sample2.dart'; import 'line/line_chart_sample3.dart'; import 'line/line_chart_sample4.dart'; @@ -40,6 +41,7 @@ class ChartSamples { LineChartSample(9, (context) => LineChartSample9()), LineChartSample(10, (context) => const LineChartSample10()), LineChartSample(11, (context) => const LineChartSample11()), + LineChartSample(11, (context) => const LineChartSample12()), ], ChartType.bar: [ BarChartSample(1, (context) => BarChartSample1()), diff --git a/example/lib/presentation/samples/line/line_chart_sample12.dart b/example/lib/presentation/samples/line/line_chart_sample12.dart new file mode 100644 index 000000000..102f644a4 --- /dev/null +++ b/example/lib/presentation/samples/line/line_chart_sample12.dart @@ -0,0 +1,132 @@ +import 'package:fl_chart/fl_chart.dart'; +import 'package:fl_chart_app/presentation/resources/app_colors.dart'; +import 'package:flutter/material.dart'; + +class LineChartSample12 extends StatefulWidget { + const LineChartSample12({super.key}); + + @override + State createState() => _LineChartSample12State(); +} + +class _LineChartSample12State extends State { + List get spots1 => [ + const FlSpot(1, 3), + const FlSpot(2, 2), + const FlSpot(4, 5), + const FlSpot(6, 4), + ]; + List get spots2 => [ + const FlSpot(1, 1), + const FlSpot(2, 4), + const FlSpot(3, 6), + const FlSpot(5, 3), + ]; + + UpdatedDragSpotsData? _lastUpdate; + + void _onUpdated(UpdatedDragSpotsData newUpdate) { + setState(() { + _lastUpdate = newUpdate; + }); + } + + String get _formattedLastSpotValue { + if (_lastUpdate == null) { + return 'Updated spot: None'; + } + + final flSpot = _lastUpdate!.newSpots[_lastUpdate!.updatedSpotIndex]; + + return 'new X: ${flSpot.x.toStringAsFixed(2)}, new Y: ${flSpot.y.toStringAsFixed(2)}'; + } + + @override + Widget build(BuildContext context) { + return Column( + children: [ + const SizedBox(height: 12), + Text( + 'Last updated bar index: ${_lastUpdate?.updatedBarIndex ?? 'none'}', + style: const TextStyle( + color: AppColors.mainTextColor2, + fontSize: 12, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 12), + Text( + 'Last updated spot index: ${_lastUpdate?.updatedSpotIndex ?? 'none'}', + style: const TextStyle( + color: AppColors.mainTextColor2, + fontSize: 12, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 12), + Text( + _formattedLastSpotValue, + style: const TextStyle( + color: AppColors.mainTextColor2, + fontSize: 12, + fontWeight: FontWeight.bold, + ), + ), + AspectRatio( + aspectRatio: 1, + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 24.0, + vertical: 10, + ), + child: LayoutBuilder(builder: (context, constraints) { + return LineChart( + LineChartData( + minY: 0, + minX: 0, + maxX: 8, + maxY: 8, + lineTouchData: LineTouchData( + enabled: true, + handleBuiltInTouches: true, + dragSpotUpdateFinishedCallback: _onUpdated, + getTouchedSpotIndicator: + (LineChartBarData barData, List spotIndexes) { + return spotIndexes.map((index) {}).toList(); + }, + touchTooltipData: LineTouchTooltipData( + tooltipBgColor: Colors.transparent, + getTooltipItems: (List lineBarsSpot) { + return lineBarsSpot.map((lineBarSpot) {}).toList(); + }, + ), + ), + lineBarsData: [ + LineChartBarData( + spots: spots1, + isCurved: true, + isDraggable: true, + ), + LineChartBarData( + spots: spots2, + isCurved: true, + isDraggable: false, + color: Colors.red, + ), + ], + gridData: const FlGridData(show: false), + borderData: FlBorderData( + show: true, + border: Border.all( + color: AppColors.borderColor, + ), + ), + ), + ); + }), + ), + ), + ], + ); + } +} diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 95cd3a3a2..c8dd325b7 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -2,6 +2,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_scaffold_widget.dart'; import 'package:fl_chart/src/chart/line_chart/line_chart_renderer.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; /// Renders a line chart as a widget, using provided [LineChartData]. @@ -40,7 +41,7 @@ class _LineChartState extends AnimatedWidgetBaseState { /// but we need to keep the provided callback to notify it too. BaseTouchCallback? _providedTouchCallback; - DragSpotUpdatedCallback? _dragSpotUpdatedCallback; + DragSpotUpdateFinishedCallback? _dragSpotUpdatedCallback; final List _showingTouchedTooltips = []; @@ -62,7 +63,7 @@ class _LineChartState extends AnimatedWidgetBaseState { @override void didUpdateWidget(covariant LineChart oldWidget) { - if (widget.data.lineBarsData != _lineBarsData) { + if (!listEquals(oldWidget.data.lineBarsData, widget.data.lineBarsData)) { _lineBarsData = List.from(widget.data.lineBarsData); } super.didUpdateWidget(oldWidget); @@ -103,7 +104,7 @@ class _LineChartState extends AnimatedWidgetBaseState { final lineTouchData = widget.data.lineTouchData; if (lineTouchData.enabled && lineTouchData.handleBuiltInTouches) { _providedTouchCallback = lineTouchData.touchCallback; - _dragSpotUpdatedCallback = lineTouchData.dragSpotUpdatedCallback; + _dragSpotUpdatedCallback = lineTouchData.dragSpotUpdateFinishedCallback; return widget.data.copyWith( lineBarsData: _lineBarsData, lineTouchData: widget.data.lineTouchData.copyWith( @@ -126,6 +127,16 @@ class _LineChartState extends AnimatedWidgetBaseState { // Cancel dragging if (event is FlPanEndEvent || event is FlLongPressEnd) { + if (_draggingSpotIndexes != null) { + final (barIndex, spotIndex) = _draggingSpotIndexes!; + _dragSpotUpdatedCallback?.call( + UpdatedDragSpotsData( + barIndex, + spotIndex, + _lineBarsData[barIndex].spots, + ), + ); + } setState(() { _draggingSpotIndexes = null; }); @@ -138,13 +149,6 @@ class _LineChartState extends AnimatedWidgetBaseState { _lineBarsData[barIndex].spots[spotIndex] = touchResponse!.touchedAxesPoint!; }); - _dragSpotUpdatedCallback?.call( - UpdatedDragSpotsData( - barIndex, - spotIndex, - _lineBarsData[barIndex].spots, - ), - ); } _providedTouchCallback?.call(event, touchResponse); diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index 388b09683..268c8cb6d 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -1076,7 +1076,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { BaseTouchCallback? touchCallback, MouseCursorResolver? mouseCursorResolver, Duration? longPressDuration, - this.dragSpotUpdatedCallback, + this.dragSpotUpdateFinishedCallback, this.touchTooltipData = const LineTouchTooltipData(), this.getTouchedSpotIndicator = defaultTouchedIndicators, this.touchSpotThreshold = 10, @@ -1097,7 +1097,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { /// Configs of how touch indicator looks like. final GetTouchedSpotIndicator getTouchedSpotIndicator; - final DragSpotUpdatedCallback? dragSpotUpdatedCallback; + final DragSpotUpdateFinishedCallback? dragSpotUpdateFinishedCallback; /// Distance threshold to handle the touch event. final double touchSpotThreshold; @@ -1123,7 +1123,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { bool? enabled, BaseTouchCallback? touchCallback, MouseCursorResolver? mouseCursorResolver, - DragSpotUpdatedCallback? dragSpotUpdatedCallback, + DragSpotUpdateFinishedCallback? dragSpotUpdateFinishedCallback, Duration? longPressDuration, LineTouchTooltipData? touchTooltipData, GetTouchedSpotIndicator? getTouchedSpotIndicator, @@ -1137,8 +1137,8 @@ class LineTouchData extends FlTouchData with EquatableMixin { enabled: enabled ?? this.enabled, touchCallback: touchCallback ?? this.touchCallback, mouseCursorResolver: mouseCursorResolver ?? this.mouseCursorResolver, - dragSpotUpdatedCallback: - dragSpotUpdatedCallback ?? this.dragSpotUpdatedCallback, + dragSpotUpdateFinishedCallback: + dragSpotUpdateFinishedCallback ?? this.dragSpotUpdateFinishedCallback, longPressDuration: longPressDuration ?? this.longPressDuration, touchTooltipData: touchTooltipData ?? this.touchTooltipData, getTouchedSpotIndicator: @@ -1165,7 +1165,7 @@ class LineTouchData extends FlTouchData with EquatableMixin { handleBuiltInTouches, getTouchLineStart, getTouchLineEnd, - dragSpotUpdatedCallback, + dragSpotUpdateFinishedCallback, ]; } @@ -1192,7 +1192,7 @@ typedef CalculateTouchDistance = double Function( Offset spotPixelCoordinates, ); -typedef DragSpotUpdatedCallback = void Function(UpdatedDragSpotsData); +typedef DragSpotUpdateFinishedCallback = void Function(UpdatedDragSpotsData); /// Default distanceCalculator only considers distance on x axis double _xDistance(Offset touchPoint, Offset spotPixelCoordinates) { From c96551aa6d6e52e7583348e57553a424a647ccde Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 22:32:35 +0200 Subject: [PATCH 06/10] minor fixes --- example/lib/presentation/samples/chart_samples.dart | 2 +- lib/src/chart/line_chart/line_chart.dart | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/example/lib/presentation/samples/chart_samples.dart b/example/lib/presentation/samples/chart_samples.dart index f5c789554..9bcde69e3 100644 --- a/example/lib/presentation/samples/chart_samples.dart +++ b/example/lib/presentation/samples/chart_samples.dart @@ -41,7 +41,7 @@ class ChartSamples { LineChartSample(9, (context) => LineChartSample9()), LineChartSample(10, (context) => const LineChartSample10()), LineChartSample(11, (context) => const LineChartSample11()), - LineChartSample(11, (context) => const LineChartSample12()), + LineChartSample(12, (context) => const LineChartSample12()), ], ChartType.bar: [ BarChartSample(1, (context) => BarChartSample1()), diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index c8dd325b7..039956b37 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -63,7 +63,18 @@ class _LineChartState extends AnimatedWidgetBaseState { @override void didUpdateWidget(covariant LineChart oldWidget) { - if (!listEquals(oldWidget.data.lineBarsData, widget.data.lineBarsData)) { + final oldSpots = oldWidget.data.lineBarsData + .map((e) => e.spots) + .toList() + .expand((list) => list) + .toList(); + final currentSpots = oldWidget.data.lineBarsData + .map((e) => e.spots) + .toList() + .expand((list) => list) + .toList(); + + if (!listEquals(oldSpots, currentSpots)) { _lineBarsData = List.from(widget.data.lineBarsData); } super.didUpdateWidget(oldWidget); From 4eeeb77fd70229a6582d4b691e14d70c41017786 Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sat, 26 Aug 2023 23:31:00 +0200 Subject: [PATCH 07/10] Change the comparing logic in didUpdateWidget --- lib/src/chart/line_chart/line_chart.dart | 14 +++++++++++++- lib/src/chart/line_chart/line_chart_data.dart | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 039956b37..9d03b1e5f 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -57,12 +57,24 @@ class _LineChartState extends AnimatedWidgetBaseState { @override void initState() { - _lineBarsData = List.from(widget.data.lineBarsData); + _lineBarsData = List.from( + widget.data.lineBarsData + .map((lineBarData) => lineBarData.copyWith()) + .toList(), + ); super.initState(); } @override void didUpdateWidget(covariant LineChart oldWidget) { + if (!listEquals(oldWidget.data.lineBarsData, widget.data.lineBarsData)) { + _lineBarsData = List.from( + widget.data.lineBarsData + .map((lineBarData) => lineBarData.copyWith()) + .toList(), + ); + } + final oldSpots = oldWidget.data.lineBarsData .map((e) => e.spots) .toList() diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index 268c8cb6d..453f79848 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -479,6 +479,7 @@ class LineChartBarData with EquatableMixin { shadow, isStepLineChart, lineChartStepData, + isDraggable, ]; } From ffe2237377986b8f456df78b9a04ba25e3d39cfc Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sun, 27 Aug 2023 00:06:49 +0200 Subject: [PATCH 08/10] Removed unnecessary logic --- lib/src/chart/line_chart/line_chart.dart | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 9d03b1e5f..d46ddf25d 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -74,21 +74,6 @@ class _LineChartState extends AnimatedWidgetBaseState { .toList(), ); } - - final oldSpots = oldWidget.data.lineBarsData - .map((e) => e.spots) - .toList() - .expand((list) => list) - .toList(); - final currentSpots = oldWidget.data.lineBarsData - .map((e) => e.spots) - .toList() - .expand((list) => list) - .toList(); - - if (!listEquals(oldSpots, currentSpots)) { - _lineBarsData = List.from(widget.data.lineBarsData); - } super.didUpdateWidget(oldWidget); } From e074877a81a4f379780e0c8c0b44a84091f75062 Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sun, 1 Oct 2023 14:13:21 +0200 Subject: [PATCH 09/10] Add draggable callbacks --- lib/src/chart/line_chart/line_chart.dart | 23 ++++++++++++++++--- lib/src/chart/line_chart/line_chart_data.dart | 23 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index d46ddf25d..123c64711 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -41,7 +41,9 @@ class _LineChartState extends AnimatedWidgetBaseState { /// but we need to keep the provided callback to notify it too. BaseTouchCallback? _providedTouchCallback; - DragSpotUpdateFinishedCallback? _dragSpotUpdatedCallback; + DragSpotUpdateCallback? _dragSpotUpdateFinishedCallback; + DragSpotUpdateCallback? _dragSpotUpdateCallback; + DragSpotUpdateCallback? _dragSpotUpdateStartedCallback; final List _showingTouchedTooltips = []; @@ -112,7 +114,8 @@ class _LineChartState extends AnimatedWidgetBaseState { final lineTouchData = widget.data.lineTouchData; if (lineTouchData.enabled && lineTouchData.handleBuiltInTouches) { _providedTouchCallback = lineTouchData.touchCallback; - _dragSpotUpdatedCallback = lineTouchData.dragSpotUpdateFinishedCallback; + _dragSpotUpdateFinishedCallback = + lineTouchData.dragSpotUpdateFinishedCallback; return widget.data.copyWith( lineBarsData: _lineBarsData, lineTouchData: widget.data.lineTouchData.copyWith( @@ -137,7 +140,7 @@ class _LineChartState extends AnimatedWidgetBaseState { if (event is FlPanEndEvent || event is FlLongPressEnd) { if (_draggingSpotIndexes != null) { final (barIndex, spotIndex) = _draggingSpotIndexes!; - _dragSpotUpdatedCallback?.call( + _dragSpotUpdateFinishedCallback?.call( UpdatedDragSpotsData( barIndex, spotIndex, @@ -157,6 +160,13 @@ class _LineChartState extends AnimatedWidgetBaseState { _lineBarsData[barIndex].spots[spotIndex] = touchResponse!.touchedAxesPoint!; }); + _dragSpotUpdateCallback?.call( + UpdatedDragSpotsData( + barIndex, + spotIndex, + _lineBarsData[barIndex].spots, + ), + ); } _providedTouchCallback?.call(event, touchResponse); @@ -200,6 +210,13 @@ class _LineChartState extends AnimatedWidgetBaseState { _draggingSpotIndexes = (barIndex, spotIndex); }); } + _dragSpotUpdateStartedCallback?.call( + UpdatedDragSpotsData( + barIndex, + spotIndex, + _lineBarsData[barIndex].spots, + ), + ); } } } diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index 453f79848..5230eb441 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -1078,6 +1078,8 @@ class LineTouchData extends FlTouchData with EquatableMixin { MouseCursorResolver? mouseCursorResolver, Duration? longPressDuration, this.dragSpotUpdateFinishedCallback, + this.dragSpotUpdateCallback, + this.dragSpotUpdateStartedCallback, this.touchTooltipData = const LineTouchTooltipData(), this.getTouchedSpotIndicator = defaultTouchedIndicators, this.touchSpotThreshold = 10, @@ -1098,7 +1100,14 @@ class LineTouchData extends FlTouchData with EquatableMixin { /// Configs of how touch indicator looks like. final GetTouchedSpotIndicator getTouchedSpotIndicator; - final DragSpotUpdateFinishedCallback? dragSpotUpdateFinishedCallback; + /// Action when dragging of draggable spot is finished. + final DragSpotUpdateCallback? dragSpotUpdateFinishedCallback; + + /// Action when draggable spot has been updated. + final DragSpotUpdateCallback? dragSpotUpdateCallback; + + /// Action when dragging of draggable spot has been started + final DragSpotUpdateCallback? dragSpotUpdateStartedCallback; /// Distance threshold to handle the touch event. final double touchSpotThreshold; @@ -1124,7 +1133,9 @@ class LineTouchData extends FlTouchData with EquatableMixin { bool? enabled, BaseTouchCallback? touchCallback, MouseCursorResolver? mouseCursorResolver, - DragSpotUpdateFinishedCallback? dragSpotUpdateFinishedCallback, + DragSpotUpdateCallback? dragSpotUpdateFinishedCallback, + DragSpotUpdateCallback? dragSpotUpdateCallback, + DragSpotUpdateCallback? dragSpotUpdateStartedCallback, Duration? longPressDuration, LineTouchTooltipData? touchTooltipData, GetTouchedSpotIndicator? getTouchedSpotIndicator, @@ -1140,6 +1151,10 @@ class LineTouchData extends FlTouchData with EquatableMixin { mouseCursorResolver: mouseCursorResolver ?? this.mouseCursorResolver, dragSpotUpdateFinishedCallback: dragSpotUpdateFinishedCallback ?? this.dragSpotUpdateFinishedCallback, + dragSpotUpdateCallback: + dragSpotUpdateCallback ?? this.dragSpotUpdateCallback, + dragSpotUpdateStartedCallback: + dragSpotUpdateStartedCallback ?? this.dragSpotUpdateStartedCallback, longPressDuration: longPressDuration ?? this.longPressDuration, touchTooltipData: touchTooltipData ?? this.touchTooltipData, getTouchedSpotIndicator: @@ -1167,6 +1182,8 @@ class LineTouchData extends FlTouchData with EquatableMixin { getTouchLineStart, getTouchLineEnd, dragSpotUpdateFinishedCallback, + dragSpotUpdateCallback, + dragSpotUpdateStartedCallback, ]; } @@ -1193,7 +1210,7 @@ typedef CalculateTouchDistance = double Function( Offset spotPixelCoordinates, ); -typedef DragSpotUpdateFinishedCallback = void Function(UpdatedDragSpotsData); +typedef DragSpotUpdateCallback = void Function(UpdatedDragSpotsData); /// Default distanceCalculator only considers distance on x axis double _xDistance(Offset touchPoint, Offset spotPixelCoordinates) { From 77646e4549a0d1328089f046fbcc3ecaa55409b5 Mon Sep 17 00:00:00 2001 From: Ruslan Zaripov Date: Sun, 1 Oct 2023 14:41:15 +0200 Subject: [PATCH 10/10] Add initializations for drag feature callbacks --- lib/src/chart/line_chart/line_chart.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 123c64711..4081598a2 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -116,6 +116,9 @@ class _LineChartState extends AnimatedWidgetBaseState { _providedTouchCallback = lineTouchData.touchCallback; _dragSpotUpdateFinishedCallback = lineTouchData.dragSpotUpdateFinishedCallback; + _dragSpotUpdateCallback = lineTouchData.dragSpotUpdateCallback; + _dragSpotUpdateStartedCallback = + lineTouchData.dragSpotUpdateStartedCallback; return widget.data.copyWith( lineBarsData: _lineBarsData, lineTouchData: widget.data.lineTouchData.copyWith(