Skip to content

Sync ChartDetailView state with external valueElements updates#311

Open
vivekjyani wants to merge 4 commits intomainfrom
NO-2078
Open

Sync ChartDetailView state with external valueElements updates#311
vivekjyani wants to merge 4 commits intomainfrom
NO-2078

Conversation

@vivekjyani
Copy link
Copy Markdown
Contributor

@vivekjyani vivekjyani commented Apr 16, 2026

Context / Spec

NO-2078ChartDetailView could get out of sync when chart updates were applied externally (change API, mirrored field updates, reset/recompute flows). The view initialized local @State once and then did not reliably re-sync both value elements and axis coordinates from model updates.

What Changed

1) ChartDetailView now syncs both chart values and chart coordinates from model updates

File: Sources/JoyfillUI/View/Fields/ChartView/ChartDetailView.swift

  • Updated initial chartCoordinatesData source to read from chartDataModel.chartCoordinates.
  • Added .onChange sync for chartDataModel.valueElements -> local valueElements.
  • Added .onChange sync for chartDataModel.chartCoordinates -> local chartCoordinatesData.
  • Both sync paths guard against redundant assignments.

2) External change payload now applies chart axis data through DocumentEditor

Files:

  • Sources/JoyfillUI/ViewModels/DocumentEditor.swift

  • Sources/JoyfillUI/ViewModels/DocumentEditor+Formulas.swift

  • In parseChanges, axis values (xTitle, yTitle, xMin, xMax, yMin, yMax) are read from the incoming change payload and assembled into ChartData.

  • updateValue(...) now accepts optional chartData and, when present, updates the stored chart axis fields in the target field before refresh/dependency recalculation.

3) ChartDataModel now carries axis data as a single coordinates object

Files:

  • Sources/JoyfillUI/ViewModels/Models.swift

  • Sources/JoyfillUI/ViewModels/DocumentEditor.swift

  • Replaced separate axis properties on ChartDataModel (x/y title/min/max) with:

    • chartCoordinates: ChartAxisConfiguration?
  • Updated chart model construction in DocumentEditor to populate this coordinates object from field data.

4) Added UI regression coverage

File: JoyfillSwiftUIExample/JoyfillUITests/ChangeUITests/OnChangeHandlerUITests.swift

Added testChartCoordinatess() to validate chart detail synchronization behavior across chart instances/pages by editing one chart configuration and asserting corresponding values are reflected in the paired chart UI.

Design Decisions

  • .onChange synchronization in ChartDetailView keeps the existing local edit flow intact while correctly responding to external model updates.
  • Single chartCoordinates model property reduces drift risk vs passing six separate axis fields.
  • Optional chartData in updateValue keeps non-chart update paths unchanged while enabling full chart updates when axis values are provided.

Public API Impact

No external/public API changes. This PR updates internal view-model wiring and chart state synchronization behavior.

Test Coverage

Added UI test coverage:

  • testChartCoordinatess() in OnChangeHandlerUITests

Reviewer Notes

  • Scope is now broader than the original description: 5 files changed across view sync, editor change parsing, model shape, and UI regression tests.
  • Main functional outcome: chart value elements and axis configuration now stay in sync when updates originate externally, not only from direct local editing.

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.

1 participant