Issue #580: clockwise/counter-clockwise radar chart direction#998
Merged
Conversation
Radar chart radii were laid out counter-clockwise (increasing math angle) with no way to reverse, so ascending labels 1..6 read as 6..1 clockwise. Add RadarStyler.setCounterClockwise(boolean), defaulting to clockwise (the common radar/spider chart convention). PlotContent_Radar negates the angle step by default and only increments when counter-clockwise is set; the change applies uniformly to the angle table, radii lines/labels, tick-mark polygons, and series polygons, so labels, data, and grid stay aligned. Adds RegressionTestIssue580 (default + geometric bulge direction) and RadarChart03 demo. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an explicit clockwise/counter-clockwise layout option for radar charts (fixing #580) by introducing a new RadarStyler flag (defaulting to clockwise) and updating radar plot angle stepping so labels, grid, and series polygons stay aligned. This also includes a regression test and a demo illustrating the new behavior.
Changes:
- Add
RadarStyler#setCounterClockwise(boolean)/isCounterClockwise()with a new default of clockwise. - Update
PlotContent_Radarto use a single signedangleStepfor consistent winding across precomputed angles and label placement. - Add
RegressionTestIssue580and a newRadarChart03demo to verify/show the behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| xchart/src/main/java/org/knowm/xchart/style/RadarStyler.java | Introduces the counterClockwise styler flag and API for controlling radar winding direction (default clockwise). |
| xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Radar.java | Uses a signed angleStep to flip winding direction while keeping all radar elements aligned. |
| xchart/src/test/java/org/knowm/xchart/regressiontests/RegressionTestIssue580.java | Adds regression coverage for the new default and for winding-direction effects. |
| xchart-demo/src/main/java/org/knowm/xchart/demo/charts/radar/RadarChart03.java | Adds a demo chart showcasing counter-clockwise layout via the new styler option. |
Comment on lines
+45
to
+53
| private static BufferedImage render(String[] labels, double[] values, boolean counterClockwise) { | ||
|
|
||
| RadarChart chart = new RadarChartBuilder().width(500).height(500).build(); | ||
| chart.getStyler().setCounterClockwise(counterClockwise); | ||
| chart.getStyler().setLegendVisible(false); | ||
| chart.setRadiiLabels(labels); | ||
| chart.addSeries("s", values); | ||
| return BitmapEncoder.getBufferedImage(chart); | ||
| } |
Address PR review: directionFlipsHorizontalBulge relied on the default color cycler picking blue. Explicitly set the series line/fill color to blue and disable markers so the pixel assertion tests only the clockwise/counter-clockwise winding, not theme/palette defaults. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #580.
Problem
A radar chart with ascending labels
1 2 3 4 5 6rendered them counter-clockwise, so reading the ring clockwise gave6 5 4 3 2 1. There was no way to reverse the drawing direction without reversing the underlying data (which the reporter explicitly did not want).Root cause: in
PlotContent_Radar, the vertex angle is stepped withstartAngle += radiiAngleand positions use the math conventiony = cy - sin(θ), so increasing angles wind counter-clockwise.setStartAngleInDegreesonly rotates the ring; it can't flip the winding.Fix
RadarStyler.setCounterClockwise(boolean)/isCounterClockwise(), defaulting to clockwise — the common radar/spider chart convention (Excel, ECharts, Chart.js), which also makes ascending labels read1..6clockwise out of the box.PlotContent_Radarcomputes a singleangleStep(negative by default, positive when counter-clockwise) and uses it for the angle table, radii lines/labels, tick-mark polygons, and series polygons, so labels, data, and grid stay aligned.Note: the default flips from the previous (counter-clockwise) rendering. This is intentional per the 4.0.x breaking-changes policy and fixes the surprising behavior; users wanting the old layout call
setCounterClockwise(true).Verification
RegressionTestIssue580: asserts the clockwise default + setter round-trip, and that a dominant vertex bulges to the right half when clockwise and the left half when counter-clockwise.RadarChart03demo showing the counter-clockwise option.xchartsuite passes (132 tests);fmt:checkclean on both modules.Clockwise (new default) — labels read 1..6 clockwise
Counter-clockwise —
setCounterClockwise(true)🤖 Generated with Claude Code