-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: Snap TimeSeries seek events to nearest data point to eliminate floating-point precision errors #8602
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
base: develop
Are you sure you want to change the base?
fix: Snap TimeSeries seek events to nearest data point to eliminate floating-point precision errors #8602
Conversation
👷 Deploy request for heartex-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for label-studio-docs-new-theme pending review.Visit the deploys page to approve it
|
✅ Deploy Preview for label-studio-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for label-studio-playground ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
* @param {Array} timeData - Array of time values from the data | ||
* @returns {number} - The snapped time value (or original if no data) | ||
*/ | ||
export const snapToNearestDataPoint = (targetTime, timeData) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please create some unit tests for this as it would make sure that future updates wont break it and to lock in the expected behaviour
/jira create
|
/git merge
|
…recision errors When clicking on a TimeSeries visualization, seek events were emitting inaccurate time values due to floating-point precision errors in the pixel-to-time conversion calculations. For example, clicking on data point 1770.677344 would emit a seek event with value 1770.6719467913167, which doesn't exist in the original dataset. This caused synchronization issues with audio/video players and affected annotation accuracy. Changes: - Added snapToNearestDataPoint() helper function in helpers.js using efficient binary search (O(log n)) to find the closest actual data point - Refactored emitSeekSync() to snap center time before emitting - Refactored plotClickHandler() to snap clicked time before processing - Refactored handleMainAreaClick() to snap clicked time before processing Benefits: - Seek events now emit exact data point values from the dataset - Eliminates ~135 lines of duplicated code across 3 locations - Maintains backward compatibility with no breaking changes - Improves synchronization accuracy with video/audio players - Ensures annotation precision in time-based labeling tasks Bug demonstration: https://www.loom.com/share/5f1f429a21f0438ca5f11e7146570bfe Fix demonstration: https://www.loom.com/share/b1b2b9ea3230461eb6e58848c40edfe2 Files changed: - web/libs/editor/src/tags/object/TimeSeries/helpers.js - web/libs/editor/src/tags/object/TimeSeries.jsx Related To: HumanSignal#8601
a622089
to
7b744fe
Compare
/git merge
|
Reason for Change
Problem:
When clicking on a TimeSeries visualization, seek events emit inaccurate time values that don't match the clicked data point due to floating-point precision errors in pixel-to-time conversion calculations.
For example:
1770.677344
emits seek event1770.6719467913167
1733.719
emits seek event1733.72516
These incorrect values don't exist in the original dataset, causing:
Root Cause:
The pixel-to-time conversion uses continuous interpolation with multiple floating-point operations that accumulate rounding errors:
Solution:
Implemented data point snapping using binary search (O(log n)) to find and return the nearest actual data point from the dataset instead of using interpolated values. Created a shared
snapToNearestDataPoint()
helper function to eliminate code duplication across three locations.Videos
Rollout Strategy
No special rollout needed - This is a bug fix with backward compatibility:
Testing
Manual Testing Performed:
Basic Click Test
Edge Cases
Synchronization Test
sync
attributeMultiChannel Test
plotClickHandler
works correctly with snappingCode Quality:
Risks
Risk Level: LOW
Performance:
Backward Compatibility:
Security:
Reviewer Notes
Key Points to Review:
Helper Function (
web/libs/editor/src/tags/object/TimeSeries/helpers.js
)snapToNearestDataPoint()
function uses binary searchThree Refactored Locations (
web/libs/editor/src/tags/object/TimeSeries.jsx
)emitSeekSync()
- Line ~1164plotClickHandler()
- Line ~1189handleMainAreaClick()
- Line ~1650Code Quality Improvements:
Testing the Fix:
General Notes
Implementation Details:
The
snapToNearestDataPoint()
helper function:Files Changed:
web/libs/editor/src/tags/object/TimeSeries/helpers.js
- Added shared helper functionweb/libs/editor/src/tags/object/TimeSeries.jsx
- Refactored three locations to use helperBenefits:
No Migration Required - This is a transparent bug fix that improves accuracy without requiring any user action or configuration changes.
Related Issues
This fix addresses floating-point precision errors that may have affected: