diff --git a/CHANGELOG.md b/CHANGELOG.md index 6961e8314..c50181599 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## {newVersion} -* [Improvement] allowed to have topTitles in the [BarChart](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md), see [BarChartSample5](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#sample-5-source-code), #394. -* [Improvement] [BREAKING] renamed `rodStackItem` to `rodStackItems` in [BarChartRodData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#barchartroddata). +* [Improvement] Allowed to have topTitles in the [BarChart](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md), see [BarChartSample5](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#sample-5-source-code), #394. +* [Improvement] Added `touchedStackItem` and `touchedStackItemIndex` properties in the [BarTouchedSpot](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#bartouchedspot) to determine in which [BarChartRodStackItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#barchartrodstackitem) click happened, #393. +* [Improvement] [BREAKING] Renamed `rodStackItem` to `rodStackItems` in [BarChartRodData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#barchartroddata). ## 0.10.1 * [Improvement] Show barGroups `x` value instead of `index` in bottom titles, #342. diff --git a/lib/src/chart/bar_chart/bar_chart_data.dart b/lib/src/chart/bar_chart/bar_chart_data.dart index 30bdb3a41..c8929e37f 100644 --- a/lib/src/chart/bar_chart/bar_chart_data.dart +++ b/lib/src/chart/bar_chart/bar_chart_data.dart @@ -752,10 +752,18 @@ class BarTouchedSpot extends TouchedSpot with EquatableMixin { final BarChartRodData touchedRodData; final int touchedRodDataIndex; + /// It can be null, if nothing found + final BarChartRodStackItem touchedStackItem; + + /// It can be -1, if nothing found + final int touchedStackItemIndex; + /// When touch happens, a [BarTouchedSpot] returns as a output, /// it tells you where the touch happened. - /// [touchedBarGroup], and [touchedBarGroupIndex] tells you in which group touch happened, - /// [touchedRodData], and [touchedRodDataIndex] tells you in which rod touch happened. + /// [touchedBarGroup], and [touchedBarGroupIndex] tell you in which group touch happened, + /// [touchedRodData], and [touchedRodDataIndex] tell you in which rod touch happened, + /// [touchedStackItem], and [touchedStackItemIndex] tell you in which rod stack touch happened + /// ([touchedStackItemIndex] means nothing found). /// You can also have the touched x and y in the chart as a [FlSpot] using [spot] value, /// and you can have the local touch coordinates on the screen as a [Offset] using [offset] value. BarTouchedSpot( @@ -763,12 +771,16 @@ class BarTouchedSpot extends TouchedSpot with EquatableMixin { int touchedBarGroupIndex, BarChartRodData touchedRodData, int touchedRodDataIndex, + BarChartRodStackItem touchedStackItem, + int touchedStackItemIndex, FlSpot spot, Offset offset, ) : touchedBarGroup = touchedBarGroup, touchedBarGroupIndex = touchedBarGroupIndex, touchedRodData = touchedRodData, touchedRodDataIndex = touchedRodDataIndex, + touchedStackItem = touchedStackItem, + touchedStackItemIndex = touchedStackItemIndex, super(spot, offset); /// Used for equality check, see [EquatableMixin]. @@ -778,6 +790,8 @@ class BarTouchedSpot extends TouchedSpot with EquatableMixin { touchedBarGroupIndex, touchedRodData, touchedRodDataIndex, + touchedStackItem, + touchedStackItemIndex, spot, offset, ]; diff --git a/lib/src/chart/bar_chart/bar_chart_painter.dart b/lib/src/chart/bar_chart/bar_chart_painter.dart index 11d551c98..7f8ba0209 100644 --- a/lib/src/chart/bar_chart/bar_chart_painter.dart +++ b/lib/src/chart/bar_chart/bar_chart_painter.dart @@ -689,7 +689,20 @@ class BarChartPainter extends AxisChartPainter with TouchHandler= toPixel) { + touchedStackIndex = stackIndex; + touchedStack = stackItem; + break; + } + } + + return BarTouchedSpot(nearestGroup, i, nearestBarRod, j, touchedStack, touchedStackIndex, nearestSpot, nearestSpotPos); } } } diff --git a/test/chart/data_pool.dart b/test/chart/data_pool.dart index beab7051c..ee472e0dc 100644 --- a/test/chart/data_pool.dart +++ b/test/chart/data_pool.dart @@ -2427,6 +2427,8 @@ final BarTouchedSpot barTouchedSpot1 = BarTouchedSpot( 1, barChartRodData1, 2, + barChartRodStackItem1, + 1, flSpot1, Offset.zero, ); @@ -2435,6 +2437,8 @@ final BarTouchedSpot barTouchedSpot1Clone = BarTouchedSpot( 1, barChartRodData1Clone, 2, + barChartRodStackItem1Clone, + 1, flSpot1Clone, Offset.zero, ); @@ -2443,6 +2447,8 @@ final BarTouchedSpot barTouchedSpot2 = BarTouchedSpot( 1, barChartRodData1, 2, + barChartRodStackItem2, + 2, flSpot1, Offset.zero, ); @@ -2451,6 +2457,8 @@ final BarTouchedSpot barTouchedSpot3 = BarTouchedSpot( 1, barChartRodData2, 2, + barChartRodStackItem2, + 2, flSpot1, Offset.zero, ); @@ -2459,6 +2467,8 @@ final BarTouchedSpot barTouchedSpot4 = BarTouchedSpot( 2, barChartRodData1, 2, + barChartRodStackItem2, + 2, flSpot1, Offset.zero, ); @@ -2467,6 +2477,8 @@ final BarTouchedSpot barTouchedSpot5 = BarTouchedSpot( 1, barChartRodData1, 3, + barChartRodStackItem2, + 2, flSpot1, Offset.zero, ); @@ -2475,6 +2487,8 @@ final BarTouchedSpot barTouchedSpot6 = BarTouchedSpot( 1, barChartRodData1, 2, + barChartRodStackItem2, + 2, flSpot2, Offset.zero, ); @@ -2483,6 +2497,8 @@ final BarTouchedSpot barTouchedSpot7 = BarTouchedSpot( 1, barChartRodData1, 2, + barChartRodStackItem2, + 2, flSpot1, const Offset(1, 10), );