Refactor: Introduce customizable tooltips for LineChart#136
Open
abdo-essam wants to merge 2 commits intoTheChance101:developfrom
Open
Refactor: Introduce customizable tooltips for LineChart#136abdo-essam wants to merge 2 commits intoTheChance101:developfrom
abdo-essam wants to merge 2 commits intoTheChance101:developfrom
Conversation
This commit introduces a major enhancement to the LineChart, allowing for extensive customization of tooltips that appear on data point clicks. The previous hardcoded tooltip has been replaced with a flexible `TooltipConfig` model. Key changes include: - **Added `TooltipConfig`:** A new data class to control tooltip appearance and behavior, including colors, size, text style, and content. - **Customizable Content:** Tooltips can now display Y-values, X-values, both, or fully custom-formatted text. This supports localization and varied data representation. - **Marker Styles:** The circular marker at the selected point can now be a stroke (outline), solid (filled), or disabled entirely. - **Refactored Drawing Logic:** Replaced `CircleWithRectAndText` with a new `TooltipWithMarker` component that handles the new customizable drawing. - **Enabled Multi-Line Tooltips:** Removed the restriction that disabled tooltips on multi-line charts. - **Added Documentation:** Included a new `TOOLTIP_CUSTOMIZATION.md` file and comprehensive usage examples in `LineChartTooltipExamples.kt`.
Collaborator
|
Great work, I will review it with other pull requests to take them into the new version release, so it may take some time. Don't hesitate to reach out to me to ask about anything, and don't feel bad if it take sometime |
This commit introduces advanced customization options for line chart tooltips: - **Individual Corner Radii**: Allows setting unique corner radii for each corner of the tooltip box via the new `TooltipCornerRadii` data class. - **Tooltip Positioning**: Adds a `TooltipPosition` sealed class (Center, Left, Right) to control the horizontal alignment of the tooltip relative to the data point. The implementation handles drawing tooltips with either uniform or individual corner radii and updates the tooltip's position based on the new alignment setting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Customizable Tooltips to LineChart
Summary
This PR adds comprehensive tooltip customization support to the LineChart component while maintaining full backward compatibility. Users can now localize tooltips, display X/Y coordinates, customize appearance, and control the marker circle style.
Problem Solved
Previously, the LineChart tooltip had several limitations:
Solution
Added a flexible
TooltipConfigsystem that allows:Changes Made
New Files
TooltipConfig.kt- Configuration model with sealed classes for type-safe optionsLineChartTooltipExamples.kt- 9 comprehensive usage examplesModified Files
LineParameters.kt- AddedtooltipConfigparameter with defaultCircleWithRectAndText.kt- Complete refactor with better naming:circleWithRectAndText()→drawTooltipWithMarker()chartRectangleWithText()→drawTooltipBox()drawMarkerCircle()andgenerateTooltipText()DefaultLines.kt- Updated to use new API with xAxisDataQuadraticLines.kt- Updated to use new API with xAxisDataChartContent.kt- Passes xAxisData to drawing functionsAPI Design
TooltipConfig
Content Types
TooltipContent.YValue(label, formatter)- Y value only (default)TooltipContent.XValue(label, xAxisData)- X value onlyTooltipContent.XYValue(xLabel, yLabel, xAxisData, yFormatter)- Both X and YTooltipContent.Custom(formatter)- Complete custom controlMarker Styles
MarkerStyle.Stroke(strokeWidth)- Outline circle (default)MarkerStyle.Solid- Filled circleMarkerStyle.None- No markerUsage Examples
Localized Tooltip
Show X and Y Coordinates
Custom Styling with Solid Marker
Backward Compatibility
✅ 100% backward compatible - All existing code works without changes. The default
TooltipConfig()produces the same behavior as before.Testing
./gradlew :chart:buildCode Quality
Improved Naming
circleWithRectAndText()→drawTooltipWithMarker()(clearer intent)chartRectangleWithText()→drawTooltipBox()(more descriptive)drawMarkerCircle()(separated concern)generateTooltipText()(content generation)Better Organization
Documentation
LineChartTooltipExamples.ktBreaking Changes
None - This is a purely additive change with full backward compatibility.
Checklist