feat(tooltip): add text label support for crosshairs#7278
feat(tooltip): add text label support for crosshairs#7278
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the tooltip interaction by introducing support for text labels on crosshairs. This feature allows users to display custom text alongside the crosshair lines, providing more informative visual cues, and includes extensive options for positioning, offsetting, and styling these new labels. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request introduces text label support for crosshairs, which is a valuable enhancement for tooltip interaction. The implementation correctly adds new options for text content, position, and offset, and ensures proper cleanup of text elements. The type definitions and theme updates are also well-integrated. However, there are a few areas for improvement regarding parameter usage and property access within the updateRuleX and updateRuleY functions, which could lead to unexpected behavior or confusion.
| style: { | ||
| text: labelX, | ||
| fontSize: 12, | ||
| fill: defaults.textFill || defaults.stroke, |
There was a problem hiding this comment.
The fill style for the Text object is set using defaults.textFill || defaults.stroke. However, defaults.textFill is not explicitly defined within the defaults object constructed in updateRuleX. The intended property for crosshair text fill, crosshairsTextFill, is passed through ...rest and would be available as defaults.crosshairsTextFill. As a result, the text fill will always fallback to defaults.stroke, ignoring any crosshairsTextFill configuration.
| fill: defaults.textFill || defaults.stroke, | |
| fill: defaults.crosshairsTextFill || defaults.stroke, |
| style: { | ||
| text: labelY, | ||
| fontSize: 12, | ||
| fill: defaults.textFill || defaults.stroke, |
There was a problem hiding this comment.
Similar to updateRuleX, the fill style for the Text object in updateRuleY is set using defaults.textFill || defaults.stroke. defaults.textFill is not defined in the defaults object here. It should be defaults.crosshairsTextFill to correctly apply the configured crosshair text fill. This will cause the text fill to incorrectly fallback to defaults.stroke.
| fill: defaults.textFill || defaults.stroke, | |
| fill: defaults.crosshairsTextFill || defaults.stroke, |
src/interaction/tooltip.ts Outdated
| textYposition = 'end', | ||
| textXoffsetX = 5, | ||
| textXoffsetY = 0, | ||
| textYoffsetX = 0, | ||
| textYoffsetY = 5, |
There was a problem hiding this comment.
The parameters textYposition, textYoffsetX, and textYoffsetY are defined in the updateRuleX function signature but are not used within the function's logic. These parameters are specifically for the Y-axis crosshair text, which is handled by updateRuleY. This suggests a potential copy-paste error or an oversight, leading to unnecessary parameters and potential confusion for future maintainers.
| textYposition = 'end', | |
| textXoffsetX = 5, | |
| textXoffsetY = 0, | |
| textYoffsetX = 0, | |
| textYoffsetY = 5, | |
| textXposition = 'start', | |
| textXoffsetX = 5, | |
| textXoffsetY = 0, |
src/interaction/tooltip.ts Outdated
| root.ruleX = ruleX; | ||
| | ||
| // Render text if crosshairsLabelX or crosshairsLabel textX / textY is provided | ||
| const labelX = defaults.textX ?? defaults.text; |
There was a problem hiding this comment.
The fallback defaults.text for labelX might not be the most appropriate. defaults.text is a generic property, and if textX is not provided, it might display unintended text. It would be clearer to explicitly use defaults.textX without a generic fallback, as the intention seems to be to only display a label if textX is specifically provided for the crosshair.
| const labelX = defaults.textX ?? defaults.text; | |
| const labelX = defaults.textX; |
src/interaction/tooltip.ts Outdated
| root.ruleY = ruleY; | ||
| | ||
| // Render text if crosshairsLabelY or textY is provided | ||
| const labelY = defaults.textY ?? defaults.text; |
There was a problem hiding this comment.
The fallback defaults.text for labelY might not be the most appropriate. defaults.text is a generic property, and if textY is not provided, it might display unintended text. It would be clearer to explicitly use defaults.textY without a generic fallback, as the intention seems to be to only display a label if textY is specifically provided for the crosshair.
| const labelY = defaults.textY ?? defaults.text; | |
| const labelY = defaults.textY; |
- Add textX and textY options to display labels on crosshairs lines - Support customizable text position and offset configuration - Add textFill style for crosshairs labels in dark theme - Update hideRuleX and hideRuleY to clean up text elements Closes antvis#7275
f067d70 to 42f61b1 Compare
This PR adds text label support for crosshairs in tooltip interaction, addressing issue #7275.
Features
textXandtextYoptions to display labels on crosshairs linestextXposition,textYposition)textXoffsetX,textXoffsetY, etc.)crosshairsTextFillstyle for dark themeUsage Example
Checklist
Closes #7275