-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Make Predict Charts Interactive #22402
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
Conversation
- Add touch interaction to PredictDetailsChart component - Display crosshair line when user drags on chart - Show colored labels next to each data point following their line position - Labels have series color as background with design token text color - Implement smart label positioning (left/right) to prevent off-screen issues - Add directional gesture detection to allow vertical scrolling - Use PanResponder with horizontal/vertical gesture discrimination - Render tooltip overlay on top of all chart lines for proper z-index - Support multi-series charts with individual colored indicators - Labels track data points vertically as user drags horizontally
- Move time label to top of chart with connecting line - Replace dashed crosshair with solid line throughout - Extend crosshair line from top to bottom of chart - Use theme-aware colors for time label (gray/white) - Use text.alternative color for better theme consistency
- Implement automatic label spacing when lines cross - Sort labels by Y position to detect overlaps - Shift overlapping labels down with 4px minimum spacing - Preserve circle indicators at actual data points - Labels remain readable when multiple series converge - Use proper type guards instead of non-null assertions
- Add activeIndex prop to ChartLegend component - Show values at dragged position while user interacts with chart - Revert to latest values when user releases touch - Legend updates in real-time as user drags across chart - Provides better context for historical data exploration
- Truncate series labels to 25 characters maximum - Append ellipsis (...) when labels exceed limit - Prevent labels from overflowing off screen - Calculate label width based on truncated text - Improves readability for long outcome titles
…overlay - Update LineChart mock to filter out transparent tooltip overlay - Add missing SVG component mocks (Circle and Rect) - Fix test assertions to use regex for partial text matching in legend - All 22 tests now passing
caieu
left a comment
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.
LGTM
- Add 23 tests covering component rendering, value display, and edge cases - Test activeIndex behavior for interactive chart updates - Test multiple series with different data lengths - Test value formatting with different ranges - Test empty data and out-of-bounds scenarios - All tests passing with no linting errors
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
- Add 18 new tests for PredictDetailsChart interactive functionality - Test touch interactions and pan handler setup - Test ChartTooltip SVG rendering and overlay layers - Test label truncation with long labels and special characters - Test active index behavior and legend updates during drag - Test collision detection for crossing and close series values - Test tooltip positioning across different data ranges - Test theme support and color application - Test multiple series rendering with overlays - Test data point and timestamp formatting - Total: 40 tests passing (22 original + 18 new) - No linting errors
|
caieu
left a comment
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.
LGTM


Interactive Chart for Predict Markets
Overview
This PR adds interactive drag-to-view functionality to the Predict market details chart, allowing users to explore historical price data by dragging their finger across the chart.
CHANGELOG entry: null
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-11-10.at.12.25.35.mov
Features
1. Touch Interaction
2. Visual Feedback
3. Smart Label Positioning
4. Dynamic Legend Values
5. Gesture Handling
6. Theme Support
colors.border.muted(gray in light mode, white in dark mode)colors.text.alternative(gray in light mode, white in dark mode)colors.background.defaultfor text on colored backgroundsTechnical Implementation
Components Modified
PredictDetailsChart.tsxPanResponderfor touch gesture handlingChartLegend.tsxactiveIndexprop to display dragged position valuesKey Technical Decisions
LineChartoverlay rendered last for proper z-indexgestureState.dxandgestureState.dyto determine horizontal vs vertical movementTesting
Manual Testing Steps
Edge Cases Tested
Screenshots/Demo
Add screenshots or screen recording demonstrating the interactive features
Performance Considerations
useCallbackfor gesture handlers to prevent unnecessary re-rendersAccessibility
Breaking Changes
None. All changes are additive and backward compatible.
Dependencies
No new dependencies added. Uses existing:
react-native-svg-charts(already in use)react-native-svg(already in use)PanResponder(built-in)Future Enhancements
Potential improvements for future PRs:
Commits
ba2a015- feat: add interactive chart with drag-to-view values in Predict3a40cd1- refactor: improve chart tooltip styling and positioning93142d5- feat: add label collision detection to chart tooltip2a6f32b- feat: update legend values dynamically based on dragged positiona9d37d6- feat: add character limit to tooltip labelsChecklist
Related Issues
Link any related issues or tickets here
Note
Adds touch-driven crosshair/tooltip overlay with dynamic legend updates to Predict details chart, plus extensive tests and minor type/mocks updates.
PredictDetailsChart.tsx):PanResponderwith horizontal/vertical gesture discrimination.ChartTooltipoverlay (crosshair, timestamp, per-series circles/labels) rendered via transparentLineChartlayer.activeIndextoChartLegendto show values at the dragged position; revert when inactive.ChartSeries.datasupports optionallabel; generate formattedlabelfor timestamps; collision handling and side-switching for tooltip labels; theme-aware colors.components/ChartLegend.tsx):activeIndexto display contextual values; fallback to last point; formatting viaformatTickValue.PredictDetailsChart.test.tsxto cover interactions, overlays, label truncation/collisions, theme, multiple series, and axis labels; adjustLineChartmock to hide transparent overlay; addCircle/Rectto SVG mocks.ChartLegend.test.tsxwith value formatting, activeIndex behaviors, edge cases, and multi-series coverage.Written by Cursor Bugbot for commit 98d1802. This will update automatically on new commits. Configure here.