Skip to content

Commit

Permalink
update maxCurrentTickOffset if changed in chart updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ramin-deriv committed Apr 19, 2024
1 parent 932bffe commit 7b5bd51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
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
29 changes: 15 additions & 14 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 @@ -492,19 +492,20 @@ class XAxisModel extends ChangeNotifier {
}

/// Updates the [XAxisModel] model variables.
void update({
bool? isLive,
int? granularity,
List<Tick>? entries,
int? minEpoch,
int? maxEpoch,
}) {
void update(
{bool? isLive,
int? granularity,
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

0 comments on commit 7b5bd51

Please sign in to comment.