@@ -2,6 +2,7 @@ import 'dart:math';
2
2
3
3
import 'package:flutter/gestures.dart' ;
4
4
import 'package:flutter/widgets.dart' ;
5
+ import 'package:interactive_chart/src/x_axis_offset_details.dart' ;
5
6
import 'package:intl/intl.dart' as intl;
6
7
7
8
import 'candle_data.dart' ;
@@ -60,6 +61,11 @@ class InteractiveChart extends StatefulWidget {
60
61
/// This provides the width of a candlestick at the current zoom level.
61
62
final ValueChanged <double >? onCandleResize;
62
63
64
+ /// Optional event fired when the user moves the chart along the X axis.
65
+ ///
66
+ /// Provides X-axis offset details.
67
+ final ValueChanged <XAxisOffsetDetails >? onXOffsetChanged;
68
+
63
69
const InteractiveChart ({
64
70
Key ? key,
65
71
required this .candles,
@@ -70,6 +76,7 @@ class InteractiveChart extends StatefulWidget {
70
76
this .overlayInfo,
71
77
this .onTap,
72
78
this .onCandleResize,
79
+ this .onXOffsetChanged,
73
80
}) : this .style = style ?? const ChartStyle (),
74
81
assert (candles.length >= 3 ,
75
82
"InteractiveChart requires 3 or more CandleData" ),
@@ -252,7 +259,8 @@ class _InteractiveChartState extends State<InteractiveChart> {
252
259
final zoomAdjustment = (currCount - prevCount) * candleWidth;
253
260
final focalPointFactor = focalPoint.dx / w;
254
261
startOffset -= zoomAdjustment * focalPointFactor;
255
- startOffset = startOffset.clamp (0 , _getMaxStartOffset (w, candleWidth));
262
+ final maxStartOffset = _getMaxStartOffset (w, candleWidth);
263
+ startOffset = startOffset.clamp (0 , maxStartOffset);
256
264
// Fire candle width resize event
257
265
if (candleWidth != _candleWidth) {
258
266
widget.onCandleResize? .call (candleWidth);
@@ -262,6 +270,13 @@ class _InteractiveChartState extends State<InteractiveChart> {
262
270
_candleWidth = candleWidth;
263
271
_startOffset = startOffset;
264
272
});
273
+
274
+ if (_prevStartOffset != startOffset) {
275
+ widget.onXOffsetChanged? .call (XAxisOffsetDetails (
276
+ offset: startOffset,
277
+ maxOffset: maxStartOffset,
278
+ ));
279
+ }
265
280
}
266
281
267
282
_handleResize (double w) {
0 commit comments