Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DERG-2179] update maxCurrentTickOffset if changed in chart updates #308

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/deriv_chart/chart/x_axis/x_axis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class _XAxisState extends State<XAxis> with TickerProviderStateMixin {
isLive: widget.isLive,
granularity: context.read<ChartConfig>().granularity,
entries: widget.entries,
maxCurrentTickOffset:
context.read<ChartConfig>().chartAxisConfig.maxCurrentTickOffset,
);
}

Expand Down
16 changes: 9 additions & 7 deletions lib/src/deriv_chart/chart/x_axis/x_axis_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ class XAxisModel extends ChangeNotifier {
required int granularity,
required AnimationController animationController,
required bool isLive,
required this.maxCurrentTickOffset,
required double maxCurrentTickOffset,
this.defaultIntervalWidth = 20,
bool startWithDataFitMode = false,
int? minEpoch,
int? maxEpoch,
this.onScale,
this.onScroll,
}) {
_maxCurrentTickOffset = maxCurrentTickOffset;

_nowEpoch = entries.isNotEmpty
? entries.last.epoch
: DateTime.now().millisecondsSinceEpoch;
Expand Down Expand Up @@ -92,9 +94,7 @@ class XAxisModel extends ChangeNotifier {
});
}

/// Max distance between [rightBoundEpoch] and [_nowEpoch] in pixels.
/// Limits panning to the right.
final double maxCurrentTickOffset;
double _maxCurrentTickOffset = 200;

// TODO(NA): Allow customization of this setting.
/// Scaling will not resize intervals to be smaller than this.
Expand Down Expand Up @@ -152,10 +152,10 @@ class XAxisModel extends ChangeNotifier {
set rightBoundEpoch(int value) => _rightBoundEpoch = value;

/// Current scrolling lower bound.
int get _minRightBoundEpoch => _shiftEpoch(_minEpoch, maxCurrentTickOffset);
int get _minRightBoundEpoch => _shiftEpoch(_minEpoch, _maxCurrentTickOffset);

/// Current scrolling upper bound.
int get _maxRightBoundEpoch => _shiftEpoch(_maxEpoch, maxCurrentTickOffset);
int get _maxRightBoundEpoch => _shiftEpoch(_maxEpoch, _maxCurrentTickOffset);

/// Has hit left or right panning limit.
bool get hasHitLimit =>
Expand Down Expand Up @@ -457,7 +457,7 @@ class XAxisModel extends ChangeNotifier {
final int target = _shiftEpoch(
// _lastEntryEpoch will be removed later.
(_entries?.isNotEmpty ?? false) ? _entries!.last.epoch : _nowEpoch,
maxCurrentTickOffset) +
_maxCurrentTickOffset) +
duration.inMilliseconds;

final double distance = target > _rightBoundEpoch
Expand Down Expand Up @@ -498,13 +498,15 @@ class XAxisModel extends ChangeNotifier {
List<Tick>? entries,
int? minEpoch,
int? maxEpoch,
double? maxCurrentTickOffset,
}) {
_updateIsLive(isLive);
_updateGranularity(granularity);
_updateEntries(entries);

_minEpoch = minEpoch ?? _minEpoch;
_maxEpoch = maxEpoch ?? _maxEpoch;
_maxCurrentTickOffset = maxCurrentTickOffset ?? _maxCurrentTickOffset;
}

/// Returns a list of timestamps in the grid without any overlaps.
Expand Down
Loading