feat: add maxValue and checkToShowTick in radarChart#2025
feat: add maxValue and checkToShowTick in radarChart#2025artshooter wants to merge 1 commit intoimaNNeo:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds two new customization features to RadarChart: a maxValue parameter to set a custom maximum value for the chart instead of auto-calculating from data, and a checkToShowTick callback to control which tick labels are displayed. This addresses issue #2002 where users wanted to set specific max values (like 100) and control tick visibility. The implementation follows fl_chart's established patterns for callback-based customization, similar to checkToShowHorizontalLine in axis charts.
Changes:
- Added
maxValueparameter to RadarChartData with validation for finite numbers - Added
checkToShowTickcallback with default behavior to hide the last tick - Updated documentation to describe both new parameters
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/src/chart/radar_chart/radar_chart_data.dart | Added maxValue field and checkToShowTick callback with proper equality, copyWith, and lerp support |
| lib/src/chart/radar_chart/radar_chart_painter.dart | Modified tick rendering to use checkToShowTick callback for label visibility and updated iteration to include all ticks |
| test/chart/radar_chart/radar_chart_data_test.dart | Added comprehensive tests for maxValue functionality (null, custom, validation) and checkToShowTick (equality, copyWith) |
| repo_files/documentations/radar_chart.md | Documented maxValue and checkToShowTick parameters with descriptions and defaults |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (index != ticks.length - 1) { | ||
| if (data.radarShape == RadarShape.circle) { | ||
| canvasWrapper.drawCircle(centerOffset, tickRadius, _tickPaint); | ||
| } else { | ||
| canvasWrapper.drawPath( | ||
| _generatePolygonPath( | ||
| centerX, | ||
| centerY, | ||
| tickRadius, | ||
| data.titleCount, | ||
| ), | ||
| _tickPaint, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (!data.checkToShowTick(index, ticks)) return; |
There was a problem hiding this comment.
The tick line drawing is hardcoded to skip the last tick (index != ticks.length - 1), while the tick label drawing is controlled by the checkToShowTick callback. This creates an inconsistency where:
- If a user wants to show the last tick label via checkToShowTick, the tick line won't be drawn
- The tick line visibility is not user-controllable
Consider using checkToShowTick to control BOTH the tick line and label drawing, or add a separate callback for tick lines if independent control is needed. The current implementation limits the flexibility that checkToShowTick is supposed to provide.
| if (index != ticks.length - 1) { | |
| if (data.radarShape == RadarShape.circle) { | |
| canvasWrapper.drawCircle(centerOffset, tickRadius, _tickPaint); | |
| } else { | |
| canvasWrapper.drawPath( | |
| _generatePolygonPath( | |
| centerX, | |
| centerY, | |
| tickRadius, | |
| data.titleCount, | |
| ), | |
| _tickPaint, | |
| ); | |
| } | |
| } | |
| if (!data.checkToShowTick(index, ticks)) return; | |
| final showTick = data.checkToShowTick(index, ticks); | |
| if (!showTick) { | |
| return; | |
| } | |
| if (data.radarShape == RadarShape.circle) { | |
| canvasWrapper.drawCircle(centerOffset, tickRadius, _tickPaint); | |
| } else { | |
| canvasWrapper.drawPath( | |
| _generatePolygonPath( | |
| centerX, | |
| centerY, | |
| tickRadius, | |
| data.titleCount, | |
| ), | |
| _tickPaint, | |
| ); | |
| } |
Summary
This PR implements the customization features for RadarChart as discussed in #2002.
Note: This is a follow-up to PR #2007. The previous PR was submitted from the GitHub account
artsooter, which is no longer available.I've created this new PR with a fresh account to implement the feedback.
Changes
maxValue parameter: Allows setting a custom maximum value for the RadarChart instead of auto-calculating from data.
checkToShowTick callback: Implemented as suggested in the review. This function determines which ticks should be displayed by receiving the tick
index, and list of all ticks. Returns a boolean to control visibility. Default behavior shows all ticks except the last one.
Documentation: Added descriptions for both parameters to
radar_chart.md.Documentation