Skip to content

Issue #580: clockwise/counter-clockwise radar chart direction#998

Merged
timmolter merged 3 commits into
developfrom
issue-580-radar-direction
Jul 9, 2026
Merged

Issue #580: clockwise/counter-clockwise radar chart direction#998
timmolter merged 3 commits into
developfrom
issue-580-radar-direction

Conversation

@timmolter

Copy link
Copy Markdown
Member

Fixes #580.

Problem

A radar chart with ascending labels 1 2 3 4 5 6 rendered them counter-clockwise, so reading the ring clockwise gave 6 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 with startAngle += radiiAngle and positions use the math convention y = cy - sin(θ), so increasing angles wind counter-clockwise. setStartAngleInDegrees only rotates the ring; it can't flip the winding.

Fix

  • Add RadarStyler.setCounterClockwise(boolean) / isCounterClockwise(), defaulting to clockwise — the common radar/spider chart convention (Excel, ECharts, Chart.js), which also makes ascending labels read 1..6 clockwise out of the box.
  • PlotContent_Radar computes a single angleStep (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.
  • New RadarChart03 demo showing the counter-clockwise option.
  • Full xchart suite passes (132 tests); fmt:check clean on both modules.

Clockwise (new default) — labels read 1..6 clockwise

Counter-clockwise — setCounterClockwise(true)

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_Radar to use a single signed angleStep for consistent winding across precomputed angles and label placement.
  • Add RegressionTestIssue580 and a new RadarChart03 demo 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);
}
timmolter and others added 2 commits July 9, 2026 13:02
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>
@timmolter timmolter merged commit d4e147a into develop Jul 9, 2026
1 check passed
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.

Radar chart reverted sequence

2 participants