Skip to content

fix(LineChart): correct PointMode valueIndex and dot alignment#173

Open
saadkhalidkhan wants to merge 2 commits into
ehsannarmani:masterfrom
saadkhalidkhan:fix/linechart-point-mode-value-index
Open

fix(LineChart): correct PointMode valueIndex and dot alignment#173
saadkhalidkhan wants to merge 2 commits into
ehsannarmani:masterfrom
saadkhalidkhan:fix/linechart-point-mode-value-index

Conversation

@saadkhalidkhan

@saadkhalidkhan saadkhalidkhan commented Jun 6, 2026

Copy link
Copy Markdown

Summary

  • Fix incorrect valueIndex in PopupProperties.Mode.PointMode for large datasets (reported with 30 data points)
  • Replace indexOfFirst { x >= xPosition } with nearest-neighbor lookup on pathData.xPositions to avoid off-by-one errors from floating-point rounding
  • Snap PointMode popups to the exact data point value and position instead of interpolating along the line
  • Align dot x coordinates with line path xPositions for consistent marker placement

Fixes #129

Root cause

calculateValueIndex mapped touch position using indexOfFirst { x >= xPosition } against path bounds width. Small floating-point differences pushed the index to the next data point (e.g. index 4 instead of 3). PointMode also reused interpolated popup values instead of the tapped point.

Commits

  1. fix(LineChart): correct PointMode valueIndex with nearest data point
  2. fix(LineChart): align dot x positions with line path xPositions

Test plan

  • :compose-charts:compileDebugKotlinAndroid builds successfully
  • :app:compileDebugKotlinAndroid builds successfully
  • LineChart with 30 points + PopupProperties.Mode.PointMode() — tap each dot, valueIndex matches label index
  • Same chart with Mode.Normal — behavior unchanged
  • Chart with dots enabled — markers align with line vertices on dense datasets

Replace indexOfFirst lookup that biased toward the next index due to
floating-point rounding. Find the nearest xPositions entry within the
PointMode threshold and snap popups to the exact data point value.
Use the same x coordinates as the line path when drawing dots so marker
positions stay consistent with large datasets and view ranges.
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.

dot position is not in correct position

1 participant