Skip to content

feat: add maxValue and checkToShowTick in radarChart#2025

Open
artshooter wants to merge 1 commit intoimaNNeo:mainfrom
artshooter:feat/radar-custom-maxValue-and-ticks
Open

feat: add maxValue and checkToShowTick in radarChart#2025
artshooter wants to merge 1 commit intoimaNNeo:mainfrom
artshooter:feat/radar-custom-maxValue-and-ticks

Conversation

@artshooter
Copy link
Copy Markdown
Contributor

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

  1. maxValue parameter: Allows setting a custom maximum value for the RadarChart instead of auto-calculating from data.

  2. 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.

  3. Documentation: Added descriptions for both parameters to radar_chart.md.

Documentation

PropName Description default value
maxValue Defines a custom maximum value for the [RadarChart]. If provided, this value will be used instead of the automatically calculated maximum from the data. null
checkToShowTick Determines which ticks should be displayed on the [RadarChart]. By default, shows all ticks except the last one. showTickWithoutLast

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 maxValue parameter to RadarChartData with validation for finite numbers
  • Added checkToShowTick callback 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.

Comment on lines +201 to +217
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;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. If a user wants to show the last tick label via checkToShowTick, the tick line won't be drawn
  2. 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.

Suggested change
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,
);
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants