Skip to content

feat: Jim/GRWT-6012/implement trend line drawing tool in interactive layer #392

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

Draft
wants to merge 284 commits into
base: master
Choose a base branch
from

Conversation

jim-deriv
Copy link
Contributor

@jim-deriv jim-deriv commented Jun 12, 2025

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

Implement a trend line drawing tool in the interactive chart layer and refactor the drawing architecture to support a new v2 pipeline with overlay painting, customizable toolbars, and streamlined state management

New Features:

  • Add trend line drawing tool with interactive endpoints, neon glow effect, and value/epoch labels on selection
  • Introduce v2 drawing pipeline with paintOverYAxis support, DrawingContext, and unified drawing state management
  • Add interactive layer floating menu with draggable toolbar for selected drawings
  • Add ColorPicker widget and TextStyleJsonConverter for customizable drawing tool appearance

Enhancements:

  • Refactor interactive layer behaviours and states with InteractiveLayerController, streamline state transitions and animation control
  • Remove debounce timers and simplify repository updates to immediate writes
  • Consolidate painting helpers for alignment guides, value and epoch labels
  • Unify mobile/desktop drawing previews and remove deprecated crosshair preview
  • Update custom gesture detector to include tap radius threshold and improve tap detection
  • Remove extra ClipRect wrapper in main_chart and simplify build logic

ramin-deriv and others added 29 commits June 9, 2025 10:32
…deriv/flutter-chart-public into jim/grwt-6012/implement-trend-line-drawing-tool-in-interactive-layer
Copy link

sourcery-ai bot commented Jun 12, 2025

Reviewer's Guide

This PR refactors the interactive layer to embrace a new DrawingV2 API (with injected DrawingContext and state callbacks), overhauls drawing tool configs to support toolbar menus, ChartConfig/ChartTheme and label rendering, upgrades state management via a dedicated controller and floating menu widget, and adds UI/gesture enhancements like value/epoch labels, color picker and tap‐cancellation logic.

Sequence diagram for Adding a Trend Line

sequenceDiagram
    actor User
    participant ILB as InteractiveLayerBehaviour
    participant IATS as InteractiveAddingToolState
    participant TLAPD as TrendLineAddingPreviewDesktop
    participant IL as InteractiveLayer (_GestureHandlerState)
    participant ILS as _InteractiveLayerState
    participant Repo as DrawingToolsRepo

    User->>+ILB: Selects Trend Line Tool
    ILB->>+IATS: startAddingTool(trendLineConfig)
    IATS->>ILB: getAddingDrawingPreview(drawing)
    ILB-->>IATS: tlAddingPreviewDesktop
    IATS->>TLAPD: (created with TrendLineInteractableDrawing)
    User->>TLAPD: Hovers mouse on chart
    TLAPD->>TLAPD: onHover(event)
    TLAPD->>PaintHelpers: drawValueLabel()
    TLAPD->>PaintHelpers: drawEpochLabel()
    Note right of TLAPD: Preview with labels shown
    User->>TLAPD: Clicks first point
    TLAPD->>TLAPD: onCreateTap() (sets startPoint)
    User->>TLAPD: Clicks second point
    TLAPD->>TLAPD: onCreateTap() (sets endPoint)
    TLAPD->>IL: addDrawing(updatedConfig)
    IL->>ILS: _addDrawingToRepo(updatedConfig)
    ILS->>Repo: add(configWithId)
    Repo-->>ILS: configWithId
    ILS-->>IL: configWithId
    IL-->>TLAPD: configWithId
    TLAPD->>ILB: (callback via onCreateTap)
    ILB->>IL: clearAddingDrawing()
    ILB->>ILB: aNewToolsIsAdded(drawingFromConfig)
    ILB->>InteractiveSelectedToolState: updateStateTo(selectedState)
    deactivate IATS
    deactivate ILB
Loading

Class diagram for State Management Core

classDiagram
    class InteractiveLayerController {
        +InteractiveState currentState
        +InteractableDrawing? selectedDrawing
        +Offset floatingMenuPosition
        +InteractiveLayerController(Offset floatingMenuInitialPosition)
        +notifyListeners()
    }
    InteractiveLayerController --|> ChangeNotifier

    class InteractiveLayerBehaviour {
        <<Abstract>>
        +InteractiveLayerController controller
        +AnimationController stateChangeController
        +InteractiveLayerBase interactiveLayer
        +VoidCallback onUpdate
        +init(InteractiveLayerBase, VoidCallback, AnimationController)
        +updateStateTo(InteractiveState, StateChangeAnimationDirection, bool waitForAnimation, bool animate) Future~void~
        +startAddingTool(DrawingToolConfig)
        +aNewToolsIsAdded(InteractableDrawing)
        +getToolState(DrawingV2) Set~DrawingToolState~
        +List~DrawingV2~ previewDrawings
        +List~Widget~ previewWidgets
    }
    InteractiveLayerBehaviour ..> InteractiveLayerController : uses
    InteractiveLayerBehaviour ..> InteractiveState : manages

    class InteractiveState {
        <<Abstract>>
        +InteractiveLayerBehaviour interactiveLayerBehaviour
        +InteractiveState(InteractiveLayerBehaviour)
        +getToolState(DrawingV2) Set~DrawingToolState~
        +List~DrawingV2~ previewDrawings
        +List~Widget~ previewWidgets
        +onTap(TapUpDetails)
        +onPanUpdate(DragUpdateDetails)
        +onPanEnd(DragEndDetails)
        +onPanStart(DragStartDetails)
        +onHover(PointerHoverEvent)
    }
    InteractiveState ..> InteractiveLayerBehaviour : uses
Loading

Class diagram for Helper Classes (DrawingContext and PaintHelpers)

classDiagram
    class DrawingContext {
        +Size fullSize
        +Size contentSize
        +DrawingContext(Size fullSize, Size contentSize)
    }

    class PaintHelpers {
        <<Utility>>
        +drawPointAlignmentGuides(Canvas, Size, Offset, Color) void
        +drawValueLabel(Canvas, QuoteToY, double, int, Size, TextStyle, double, Color, Color, bool, double, double, double) void
        +drawEpochLabel(Canvas, EpochToX, int, Size, TextStyle, double, Color, Color) void
    }

    TrendLineInteractableDrawing ..> PaintHelpers : uses
    HorizontalLineInteractableDrawing ..> PaintHelpers : uses
    TrendLineAddingPreviewDesktop ..> PaintHelpers : uses
    HorizontalLineAddingPreviewDesktop ..> PaintHelpers : uses
Loading

Class diagram for AddOnsRepository Changes

classDiagram
    class Repository~T~ {
        <<Abstract>>
        +List~T~ items
        +void add(T config)
        +void updateAt(int index, T config)
        +void removeAt(int index)
        +void remove(T config)
        +void clear()
    }
    Repository --|> ChangeNotifier

    class AddOnsRepository~T extends AddOnConfig~ {
        +void remove(T config)
    }
    AddOnsRepository --|> Repository~T~
Loading

File-Level Changes

Change Details Files
Refactor interactive layer core to use DrawingContext and simplified update/remove workflow
  • Inject DrawingContext and GetDrawingState into drawing creation
  • Remove debounce timers and simplify config update logic
  • Refactor init/dispose to sync and remove drawings dynamically
  • Add onRemoveDrawing callback and track added drawing IDs
lib/src/deriv_chart/interactive_layer/interactive_layer.dart
lib/src/deriv_chart/interactive_layer/interactive_layer_gesture_handler.dart
lib/src/deriv_chart/interactive_layer/drawing_context.dart
lib/src/deriv_chart/interactive_layer/helpers/types.dart
Overhaul drawing tool API to support toolbar menus and label rendering
  • Extend paint API to accept ChartConfig and ChartTheme
  • Implement paintOverYAxis to render value and epoch labels
  • Add neon glow and hover effects in TrendLine and HorizontalLine drawables
  • Introduce buildDrawingToolBarMenu with color picker and thickness controls
lib/src/deriv_chart/interactive_layer/interactable_drawings/trend_line/trend_line_interactable_drawing.dart
lib/src/deriv_chart/interactive_layer/interactable_drawings/horizontal_line/horizontal_line_interactable_drawing.dart
lib/src/add_ons/drawing_tools_ui/line/line_drawing_tool_config.dart
lib/src/add_ons/drawing_tools_ui/horizontal/horizontal_drawing_tool_config.dart
Enhance state management and behaviors with controller and floating menu
  • Introduce InteractiveLayerController for state and menu positioning
  • Augment updateStateTo with animate flags; unify startAddingTool/aNewToolsIsAdded
  • Embed SelectedDrawingFloatingMenu in InteractiveSelectedToolState via previewWidgets
  • Refactor behaviour classes to use new controller and state transitions
lib/src/deriv_chart/interactive_layer/interactive_layer_behaviours/interactive_layer_behaviour.dart
lib/src/deriv_chart/interactive_layer/interactive_layer_behaviours/interactive_layer_desktop_behaviour.dart
lib/src/deriv_chart/interactive_layer/interactive_layer_behaviours/interactive_layer_mobile_behaviour.dart
lib/src/deriv_chart/interactive_layer/interactive_layer_states/interactive_selected_tool_state.dart
lib/src/deriv_chart/interactive_layer/interactive_layer_controller.dart
Add UI/gesture enhancements: labeling, color picking and tap filtering
  • Extend paint_helpers with drawValueLabel and drawEpochLabel
  • Introduce ColorPicker and TextStyleJsonConverter for persistent labels
  • Implement tapRadius check in CustomGestureDetector
  • Remove extra ClipRect wrapper in main_chart for cleaner layering
lib/src/deriv_chart/interactive_layer/helpers/paint_helpers.dart
lib/src/deriv_chart/interactive_layer/widgets/color_picker.dart
lib/src/deriv_chart/chart/helpers/text_style_json_converter.dart
lib/src/deriv_chart/chart/gestures/custom_gesture_detector.dart
lib/src/deriv_chart/chart/main_chart.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

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.

2 participants