Skip to content

refactor(ui-rnative-visualization): align axis API with react-visualization + fix tick values#730

Open
gamegee wants to merge 3 commits into
mainfrom
dls-/761/fix-xaxis-rnative
Open

refactor(ui-rnative-visualization): align axis API with react-visualization + fix tick values#730
gamegee wants to merge 3 commits into
mainfrom
dls-/761/fix-xaxis-rnative

Conversation

@gamegee
Copy link
Copy Markdown
Collaborator

@gamegee gamegee commented Jun 1, 2026

Summary

Split out from #728 so the react-native-visualization axis work lands independently.

  • fix(charts): respect xAxis.data as the source of truth for tick values — buildTicksData derives ticks from the data itself instead of scale.ticks(), removing d3-invented intermediate ticks. The ticks: [] short-circuit is preserved.
  • refactor(charts): align the axis API with react-visualization — consolidate axis config onto a single BaseAxisProps type, add a nice opt-out on numeric scales (default true), and cap toScaledPoints iteration at xData.length so a series with more points than the axis has labels no longer overflows the right edge.
  • Updates the app-sandbox-rnative LineCharts demo accordingly.

Test plan

  • nx test ui-rnative-visualization
  • Verify LineChart in app-sandbox-rnative renders ticks from xAxis.data and clips series that exceed the axis length

Made with Cursor

When `xAxis.data` is provided without explicit `ticks`, `buildTicksData` now
derives ticks from the data itself (numeric values for numeric data, indices
for string data) instead of falling back to `scale.ticks()`. This removes
d3-invented intermediate ticks (e.g. `1, 3` for `[0, 2, 4]`, or `0.5, 1.5`
between `'Jan', 'Feb', 'Mar'`).

The existing `ticks: []` short-circuit (passing an empty array to render no
labels) is preserved.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings June 1, 2026 13:31
@gamegee gamegee requested a review from a team as a code owner June 1, 2026 13:31
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ldls Ready Ready Preview, Comment Jun 1, 2026 1:40pm
ldls-react-native Ready Ready Preview, Comment Jun 1, 2026 1:40pm

Request Review

gamegee and others added 2 commits June 1, 2026 15:38
Consolidate axis configuration onto a single `BaseAxisProps` type (merging the
former `AxisConfigProps` fields: `scaleType`, `data`, `domain`), add a `nice`
opt-out on numeric scales (default `true`; set `false` to keep the domain
exactly as provided), and cap `toScaledPoints` iteration at `xData.length` so a
series with more points than the axis has labels no longer overflows the right
edge of the chart.

Co-authored-by: Cursor <cursoragent@cursor.com>
Group the tick-value source-of-truth fix and the axis API alignment refactor
into a single patch version plan for @ledgerhq/lumen-ui-rnative-visualization.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gamegee gamegee force-pushed the dls-/761/fix-xaxis-rnative branch from 5c8f421 to d1e2350 Compare June 1, 2026 13:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the React Native visualization axis configuration to better align with the react-visualization API, while also fixing x-axis tick generation so ticks match xAxis.data exactly (no intermediate “invented” d3 ticks). It also adjusts chart rendering behavior to avoid series overflowing past the x-axis label range and updates the RN sandbox demo accordingly.

Changes:

  • Derive tick values from xAxis.data when provided (preserving the ticks: [] short-circuit) and add tests for the new tick priority behavior.
  • Consolidate axis configuration into BaseAxisProps, add numeric-scale nice opt-out, and cap toScaledPoints iteration to xData.length.
  • Update CartesianChart overflow handling and refresh the app-sandbox-rnative LineCharts examples.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libs/ui-rnative-visualization/src/lib/utils/types.ts Switches axis config types to BaseAxisProps in chart context types.
libs/ui-rnative-visualization/src/lib/utils/ticks/ticks.ts Updates tick resolution priority to prefer axis.data over scale.ticks().
libs/ui-rnative-visualization/src/lib/utils/ticks/ticks.test.ts Adds coverage for tick derivation from numeric/string axis.data and priority rules.
libs/ui-rnative-visualization/src/lib/utils/scales/scales.ts Adds nice parameter support to numeric scale creation and updates scale-type typing.
libs/ui-rnative-visualization/src/lib/utils/scales/scales.test.ts Adds tests verifying default nice behavior and explicit nice: false.
libs/ui-rnative-visualization/src/lib/utils/index.ts Removes exports for the old axis config types from utils barrel.
libs/ui-rnative-visualization/src/lib/utils/domain/domain.ts Migrates axis config typing to BaseAxisProps.
libs/ui-rnative-visualization/src/lib/Components/Scrubber/utils.ts Migrates scrubber axis config typing to BaseAxisProps.
libs/ui-rnative-visualization/src/lib/Components/Scrubber/types.ts Adds an optional wrapper style prop to support overflow/offset layout.
libs/ui-rnative-visualization/src/lib/Components/Scrubber/ScrubberProvider.tsx Applies wrapper style and updates memo dependencies.
libs/ui-rnative-visualization/src/lib/Components/ReferenceLine/utils.ts Migrates reference line axis config typing to BaseAxisProps.
libs/ui-rnative-visualization/src/lib/Components/LineChart/types.ts Updates xAxis/yAxis prop types to the new axis props shape.
libs/ui-rnative-visualization/src/lib/Components/LineChart/LineChart.tsx Uses default axis props and passes unified axis configs through to chart + axes.
libs/ui-rnative-visualization/src/lib/Components/LineChart/LineChart.stories.tsx Adds stories demonstrating numeric/string xAxis.data tick behavior.
libs/ui-rnative-visualization/src/lib/Components/Line/utils.ts Caps point iteration to xData.length to prevent right-edge overflow.
libs/ui-rnative-visualization/src/lib/Components/Line/utils.test.ts Adds tests for capped iteration, numeric xData, categorical centering, etc.
libs/ui-rnative-visualization/src/lib/Components/CartesianChart/utils.ts Reworks overflow buffer documentation and replaces negative-margin approach with offset approach.
libs/ui-rnative-visualization/src/lib/Components/CartesianChart/types.ts Migrates CartesianChart axis config typing to BaseAxisProps.
libs/ui-rnative-visualization/src/lib/Components/CartesianChart/context/useBuildChartContext.ts Threads nice through scale building using BaseAxisProps.
libs/ui-rnative-visualization/src/lib/Components/CartesianChart/context/useBuildChartContext.test.ts Adds integration tests for default nice behavior and opt-out.
libs/ui-rnative-visualization/src/lib/Components/CartesianChart/CartesianChart.tsx Updates SVG sizing/offset handling and passes wrapper style to scrubber provider.
libs/ui-rnative-visualization/src/lib/Components/Axis/index.ts Introduces an Axis barrel export for types/constants.
libs/ui-rnative-visualization/src/lib/Components/Axis/Axis.types.ts Defines AxisBounds and consolidates axis config into BaseAxisProps (incl. nice).
libs/ui-rnative-visualization/src/lib/Components/Axis/Axis.constants.ts Adds default axis prop objects for x/y axis.
apps/app-sandbox-rnative/src/app/blocks/LineCharts.tsx Updates the sandbox LineCharts demo to match the refactored chart API and sizing behavior.
.nx/version-plans/version-plan-1780320400001-rnative-visualization.md Adds a patch version plan describing the tick fix + axis API refactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +13
scaleType: 'linear',
nice: false,
};
Comment on lines +69 to +73
getXAxisConfig: (id?: string) => BaseAxisProps | undefined;
/**
* Returns the y-axis config. Accepts an optional axis ID for future multi-axis support.
*/
getYAxisConfig: (id?: string) => AxisConfigProps | undefined;
getYAxisConfig: (id?: string) => BaseAxisProps | undefined;
Comment on lines +45 to +47
// The SVG canvas is enlarged by the overflow buffer on every side so edge
// content (labels, points, ticks) is not clipped, then shifted back by the
// negative margin so the drawing area still spans the container footprint.
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