Skip to content

Conversation

@behnam-deriv
Copy link
Collaborator

@behnam-deriv behnam-deriv commented Jan 14, 2026

Clickup link:
Fixes issue: #

This PR contains the following changes:

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Developers Note (Optional)

Pre-launch Checklist (For PR creator)

As a creator of this PR:

  • ✍️ I have included clickup id and package/app_name in the PR title.
  • 👁️ I have gone through the code and removed any temporary changes (commented lines, prints, debug statements etc.).
  • ⚒️ I have fixed any errors/warnings shown by the analyzer/linter.
  • 📝 I have added documentation, comments and logging wherever required.
  • 🧪 I have added necessary tests for these changes.
  • 🔎 I have ensured all existing tests are passing.

Reviewers

Pre-launch Checklist (For Reviewers)

As a reviewer I ensure that:

  • ✴️ This PR follows the standard PR template.
  • 🪩 The information in this PR properly reflects the code changes.
  • 🧪 All the necessary tests for this PR's are passing.

Pre-launch Checklist (For QA)

  • 👌 It passes the acceptance criteria.

Pre-launch Checklist (For Maintainer)

  • [MAINTAINER_NAME] I make sure this PR fulfills its purpose.

Summary by Sourcery

Add support for configuring a default X-axis tick offset used for initial chart load and scrolling to the latest tick, defaulting to the maximum tick offset when unspecified.

New Features:

  • Introduce an optional defaultTickOffset configuration on chart axis models and widgets to control the distance between the latest data point and the right chart edge.

Enhancements:

  • Align initial right bound and "scroll to last tick" behavior to use the configurable default tick offset instead of always using the maximum tick offset.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 14, 2026

Reviewer's Guide

Adds a configurable default tick offset for the X-axis and wires it through chart configuration, X-axis widgets, and model logic so initial load and "scroll to last tick" use this offset instead of always using the maximum current tick offset.

Sequence diagram for applying defaultTickOffset on chart initialization

sequenceDiagram
  participant ChartConfig as ChartAxisConfig
  participant Wrapper as XAxisWrapper
  participant Widget as XAxisBase
  participant Model as XAxisModel

  ChartConfig->>Wrapper: provide maxCurrentTickOffset, defaultTickOffset
  Wrapper->>Widget: new XAxisBase(defaultTickOffset, maxCurrentTickOffset)
  Widget->>Model: new XAxisModel(maxCurrentTickOffset, defaultTickOffset)
  Model->>Model: _defaultTickOffset = clamp(defaultTickOffset, 0, _maxCurrentTickOffset)
  Model->>Model: if null use _maxCurrentTickOffset
  Model->>Model: _rightBoundEpoch = _shiftEpoch(_maxEpoch, _defaultTickOffset)
  Model-->>Widget: initial X axis state with default offset
Loading

Sequence diagram for scroll to last tick using defaultTickOffset

sequenceDiagram
  actor User
  participant UI as ScrollToLastTickButton
  participant Model as XAxisModel

  User->>UI: tap scroll to last tick
  UI->>Model: scrollToLastTick()
  Model->>Model: target = _shiftEpoch(lastEntryEpochOrNow, _defaultTickOffset) + duration
  Model->>Model: compute distance = target - _rightBoundEpoch
  Model-->>UI: animate scroll with distance
  UI-->>User: chart shows latest tick with defaultTickOffset from right edge
Loading

Class diagram for X-axis defaultTickOffset configuration

classDiagram
  class ChartAxisConfig {
    +double initialTopBoundQuote
    +double initialBottomBoundQuote
    +double maxCurrentTickOffset
    +double~nullable~ defaultTickOffset
    +bool showQuoteGrid
    +bool showEpochGrid
    +double defaultIntervalWidth
    +ChartAxisConfig copyWith(double~nullable~ initialTopBoundQuote, double~nullable~ initialBottomBoundQuote, double~nullable~ maxCurrentTickOffset, double~nullable~ defaultTickOffset)
  }

  class XAxisWrapper {
    +ChartAxisConfig chartAxisConfig
    +Widget build(BuildContext context)
  }

  class XAxisBase {
    +int minEpoch
    +int maxEpoch
    +double? msPerPx
    +double? minIntervalWidth
    +double? maxIntervalWidth
    +EdgeInsets? dataFitPadding
    +double~nullable~ defaultTickOffset
    +Duration scrollAnimationDuration
  }

  class XAxisMobile {
  }

  class XAxisWeb {
  }

  class XAxisModel {
    -double _maxCurrentTickOffset
    -double _defaultTickOffset
    -int _maxEpoch
    -int _rightBoundEpoch
    +XAxisModel(int minEpoch, int maxEpoch, double maxCurrentTickOffset, double~nullable~ defaultTickOffset, double~nullable~ msPerPx, double~nullable~ minIntervalWidth, double~nullable~ maxIntervalWidth, EdgeInsets~nullable~ dataFitPadding, void Function(double scale)~nullable~ onScale, void Function(double delta)~nullable~ onScroll)
    -int _shiftEpoch(int epoch, double offset)
  }

  ChartAxisConfig "1" --> "1" XAxisWrapper : used by
  XAxisWrapper "1" --> "1" XAxisBase : creates
  XAxisBase <|-- XAxisMobile
  XAxisBase <|-- XAxisWeb
  XAxisBase "1" --> "1" XAxisModel : configures

  %% Highlight of defaultTickOffset flow
  ChartAxisConfig : +defaultTickOffset
  XAxisBase : +defaultTickOffset
  XAxisModel : -_defaultTickOffset
Loading

File-Level Changes

Change Details Files
Introduce a configurable default tick offset in the X-axis model and use it for initial right bound and scroll-to-last-tick behavior.
  • Extend XAxisModel constructor to accept an optional default tick offset parameter.
  • Store the default tick offset in a new _defaultTickOffset field, clamped between 0 and _maxCurrentTickOffset, defaulting to _maxCurrentTickOffset.
  • Initialize _rightBoundEpoch using _shiftEpoch on _maxEpoch with _defaultTickOffset instead of _maxRightBoundEpoch.
  • Update scrollToLastTick target calculation to use _defaultTickOffset instead of _maxCurrentTickOffset.
  • Add documentation comments describing the purpose and behavior of _defaultTickOffset.
lib/src/deriv_chart/chart/x_axis/x_axis_model.dart
Expose default tick offset as part of chart axis configuration and propagate it through X-axis widgets (web and mobile) into the X-axis model.
  • Add an optional defaultTickOffset field to ChartAxisConfig with documentation, constructor wiring, and copyWith support.
  • Add a defaultTickOffset property to XAxisBase and plumb it into XAxisState when creating XAxisModel.
  • Update XAxisWrapper to pass chartAxisConfig.defaultTickOffset into both XAxisWeb and XAxisMobile.
  • Update XAxisWeb and XAxisMobile constructors to forward defaultTickOffset to the base class.
lib/src/models/chart_axis_config.dart
lib/src/deriv_chart/chart/x_axis/widgets/x_axis_base.dart
lib/src/deriv_chart/chart/x_axis/x_axis_wrapper.dart
lib/src/deriv_chart/chart/x_axis/widgets/x_axis_mobile.dart
lib/src/deriv_chart/chart/x_axis/widgets/x_axis_web.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@claude
Copy link

claude bot commented Jan 14, 2026

Claude finished @behnam-deriv's task —— View job


PR Review: Default Tick Offset Implementation

Summary

This PR successfully adds a defaultTickOffset configuration option to control the distance between the latest data point and the right chart edge. The implementation is clean and well-documented, but there are a few issues that should be addressed.


Issues Found

🔴 High Priority

1. Incomplete copyWith implementation in ChartAxisConfig (lib/src/models/chart_axis_config.dart:76-88)

The copyWith method is missing several fields that are present in the constructor. This breaks the copy functionality for those fields:

ChartAxisConfig copyWith({
  double? initialTopBoundQuote,
  double? initialBottomBoundQuote,
  double? maxCurrentTickOffset,
  double? defaultTickOffset,
}) =>
    ChartAxisConfig(
      initialTopBoundQuote: initialTopBoundQuote ?? this.initialTopBoundQuote,
      initialBottomBoundQuote:
          initialBottomBoundQuote ?? this.initialBottomBoundQuote,
      maxCurrentTickOffset: maxCurrentTickOffset ?? this.maxCurrentTickOffset,
      defaultTickOffset: defaultTickOffset ?? this.defaultTickOffset,
    );

Problem: The following constructor parameters are not included in copyWith:

  • defaultIntervalWidth
  • showQuoteGrid
  • showEpochGrid
  • showFrame
  • smoothScrolling

Impact: If someone calls copyWith() on a ChartAxisConfig instance, these fields will be reset to their default values instead of being preserved.

Fix: Either add all missing fields to copyWith, or remove the method entirely if it's not being used.


🟡 Medium Priority

2. Missing test coverage

No tests were added for the new defaultTickOffset functionality. The feature should have tests covering:

  • Default behavior (when defaultTickOffset is null, it should use maxCurrentTickOffset)
  • Clamping behavior (values outside 0 to maxCurrentTickOffset should be clamped)
  • Initial chart load with custom defaultTickOffset
  • "Scroll to last tick" behavior with custom defaultTickOffset

Location: Should add tests in /test/deriv_chart/chart/x_axis/ directory


3. Potential null-safety issue with clamping

In x_axis_model.dart:89-90:

_defaultTickOffset = defaultTickOffset?.clamp(0, _maxCurrentTickOffset) ??
    _maxCurrentTickOffset;

Concern: If _maxCurrentTickOffset is 0 or negative, the clamp range would be invalid (min > max). While this is unlikely given the default value of 150, it could cause issues if someone passes an invalid maxCurrentTickOffset.

Recommendation: Add validation or a comment explaining the assumption that _maxCurrentTickOffset is always positive.


🟢 Low Priority / Suggestions

4. Documentation could be more explicit

While the documentation is good, it could be clearer about:

  • What happens when defaultTickOffset > maxCurrentTickOffset (it gets clamped, but this could be stated more prominently)
  • The relationship between defaultTickOffset and maxCurrentTickOffset

5. Missing changelog entry

Consider adding an entry to CHANGELOG.md describing this new feature for users upgrading the library.


Positive Observations

Good architectural design: The feature is implemented cleanly through the widget hierarchy (ChartAxisConfig → XAxisWrapper → XAxisBase → XAxisModel)

Consistent documentation: All three places where the parameter is documented (ChartAxisConfig, XAxisBase, XAxisModel) have matching descriptions

Backward compatible: Making defaultTickOffset optional with a sensible default ensures no breaking changes

Proper threading: The parameter is correctly passed through all layers (wrapper → mobile/web → base → model)


Recommendations

Before merging:

  1. Must fix: Complete the copyWith method in ChartAxisConfig to include all fields
  2. Strongly recommended: Add tests for the new functionality
  3. Consider: Add validation for edge cases (e.g., negative maxCurrentTickOffset)

After merging:

  • Update CHANGELOG.md with the new feature
  • Consider adding an example in the example app demonstrating different defaultTickOffset values

Conclusion

The implementation is solid and follows the codebase patterns well. The main blocker is the incomplete copyWith method which could cause bugs if used. Once that's fixed and tests are added, this PR will be ready to merge.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `lib/src/deriv_chart/chart/x_axis/x_axis_model.dart:89-90` </location>
<code_context>
     _isLive = isLive;
     _maxCurrentTickOffset = maxCurrentTickOffset;
-    _rightBoundEpoch = _maxRightBoundEpoch;
+    _defaultTickOffset = defaultTickOffset?.clamp(0, _maxCurrentTickOffset) ??
+        _maxCurrentTickOffset;
+    _rightBoundEpoch = _shiftEpoch(_maxEpoch, _defaultTickOffset);
     _dataFitMode = startWithDataFitMode;
</code_context>

<issue_to_address>
**issue (bug_risk):** Clamp result is `num`, which may not assign cleanly to `double` without an explicit cast.

Because `clamp` returns `num`, this expression is `num?`, so assigning it to a `double` field can cause analyzer issues in strong mode. Please make the bounds `double` and/or cast the result, e.g. `defaultTickOffset?.clamp(0.0, _maxCurrentTickOffset).toDouble()` or `(defaultTickOffset?.clamp(0.0, _maxCurrentTickOffset) as double?) ?? _maxCurrentTickOffset;`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@behnam-deriv
Copy link
Collaborator Author

The copyWith is not used in ChartAxisConfig

@behnam-deriv behnam-deriv merged commit e3b525d into master Jan 15, 2026
7 checks passed
@behnam-deriv behnam-deriv deleted the add-default-tick-offset branch January 15, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants