From 7aa73b2ab6462c9a18c36ebfe8e2f8e5bc5c01ce Mon Sep 17 00:00:00 2001 From: Dai Xuezhou Date: Tue, 29 Jul 2025 17:43:49 +0800 Subject: [PATCH 1/2] feat(radar): add clockwise options support Support to control the direction of radar chart through `clockwise` field, which is anti-clockwise by default. --- src/coord/radar/Radar.ts | 5 ++++- src/coord/radar/RadarModel.ts | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/coord/radar/Radar.ts b/src/coord/radar/Radar.ts index 6ce88ec75f..c0fb4df295 100644 --- a/src/coord/radar/Radar.ts +++ b/src/coord/radar/Radar.ts @@ -126,6 +126,7 @@ class Radar implements CoordinateSystem, CoordinateSystemMaster { const refContainer = createBoxLayoutReference(radarModel, api).refContainer; const center = radarModel.get('center'); + const clockwise = radarModel.get('clockwise') || false; const viewSize = Math.min(refContainer.width, refContainer.height) / 2; this.cx = numberUtil.parsePercent(center[0], refContainer.width) + refContainer.x; this.cy = numberUtil.parsePercent(center[1], refContainer.height) + refContainer.y; @@ -140,9 +141,11 @@ class Radar implements CoordinateSystem, CoordinateSystemMaster { this.r0 = numberUtil.parsePercent(radius[0], viewSize); this.r = numberUtil.parsePercent(radius[1], viewSize); + const sign = clockwise ? -1 : 1; + each(this._indicatorAxes, function (indicatorAxis, idx) { indicatorAxis.setExtent(this.r0, this.r); - let angle = (this.startAngle + idx * Math.PI * 2 / this._indicatorAxes.length); + let angle = (this.startAngle + sign * idx * Math.PI * 2 / this._indicatorAxes.length); // Normalize to [-PI, PI] angle = Math.atan2(Math.sin(angle), Math.cos(angle)); indicatorAxis.angle = angle; diff --git a/src/coord/radar/RadarModel.ts b/src/coord/radar/RadarModel.ts index 4723a34541..fafed8b598 100644 --- a/src/coord/radar/RadarModel.ts +++ b/src/coord/radar/RadarModel.ts @@ -60,6 +60,8 @@ export interface RadarOption extends ComponentOption, CircleLayoutOptionMixin { startAngle?: number + clockwise?: boolean + shape?: 'polygon' | 'circle' // TODO. axisType seems to have issue. @@ -106,6 +108,7 @@ class RadarModel extends ComponentModel implements CoordinateSystem optionUpdated() { const boundaryGap = this.get('boundaryGap'); const splitNumber = this.get('splitNumber'); + const clockwise = this.get('clockwise'); const scale = this.get('scale'); const axisLine = this.get('axisLine'); const axisTick = this.get('axisTick'); @@ -135,6 +138,7 @@ class RadarModel extends ComponentModel implements CoordinateSystem const innerIndicatorOpt: InnerIndicatorAxisOption = zrUtil.merge(zrUtil.clone(indicatorOpt), { boundaryGap: boundaryGap, splitNumber: splitNumber, + clockwise: clockwise, scale: scale, axisLine: axisLine, axisTick: axisTick, @@ -187,6 +191,8 @@ class RadarModel extends ComponentModel implements CoordinateSystem startAngle: 90, + clockwise: false, + axisName: { show: true, color: tokens.color.axisLabel From f27e1e39e45400d0b6be4ab2150e7d10d19f3874 Mon Sep 17 00:00:00 2001 From: Dai Xuezhou Date: Tue, 29 Jul 2025 19:18:09 +0800 Subject: [PATCH 2/2] test(radar): add radar chart direction test case --- test/radar-clockwise-interactive.html | 330 ++++++++++++++++++++++++++ test/radar-clockwise.html | 124 ++++++++++ 2 files changed, 454 insertions(+) create mode 100644 test/radar-clockwise-interactive.html create mode 100644 test/radar-clockwise.html diff --git a/test/radar-clockwise-interactive.html b/test/radar-clockwise-interactive.html new file mode 100644 index 0000000000..eed01d2d63 --- /dev/null +++ b/test/radar-clockwise-interactive.html @@ -0,0 +1,330 @@ + + + + + + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/test/radar-clockwise.html b/test/radar-clockwise.html new file mode 100644 index 0000000000..c2e18ba523 --- /dev/null +++ b/test/radar-clockwise.html @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file