This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new f10ff4922da fix(radar-chart): make inside label positions render where
their names say (#38119)
f10ff4922da is described below
commit f10ff4922daefa7f07d5e8eb6a1337e9353bf9b6
Author: Vansh Gilhotra <[email protected]>
AuthorDate: Sat Nov 14 08:43:29 2026 +0530
fix(radar-chart): make inside label positions render where their names say
(#38119)
Co-authored-by: rusackas <[email protected]>
Co-authored-by: Evan Rusackas <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Joe Li <[email protected]>
---
.../src/Radar/transformProps.ts | 26 ++++-
.../test/Radar/transformProps.test.ts | 122 ++++++++++++++++++++-
2 files changed, 145 insertions(+), 3 deletions(-)
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts
b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts
index 25a91cf3a6a..0107e942046 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts
@@ -48,10 +48,31 @@ import {
} from '../utils/series';
import { resolveLegendLayout } from '../utils/legendLayout';
import { defaultGrid } from '../defaults';
-import { Refs } from '../types';
+import { LabelPositionEnum, Refs } from '../types';
import { getDefaultTooltip } from '../utils/tooltip';
import { findGlobalMax, renderNormalizedTooltip } from './utils';
+// ZRender anchors an "inside*" label to the named edge of its target and
+// grows the text inward from there (see `calculateTextPosition` in
+// zrender/src/contain/text.ts). A radar point symbol is far smaller than its
+// label, so the text overflows out the opposite side: "Inside Top" lands
+// below the point, "Inside Left" lands to its right, and the corner
+// positions land on the opposite diagonal. This is geometry on a small
+// symbol, not radar-specific. Map each directional inside position to its
+// opposite so the label lands where its name says.
+const RADAR_LABEL_POSITION_OVERRIDES: Partial<
+ Record<LabelPositionEnum, LabelPositionEnum>
+> = {
+ [LabelPositionEnum.InsideTop]: LabelPositionEnum.InsideBottom,
+ [LabelPositionEnum.InsideBottom]: LabelPositionEnum.InsideTop,
+ [LabelPositionEnum.InsideLeft]: LabelPositionEnum.InsideRight,
+ [LabelPositionEnum.InsideRight]: LabelPositionEnum.InsideLeft,
+ [LabelPositionEnum.InsideTopLeft]: LabelPositionEnum.InsideBottomRight,
+ [LabelPositionEnum.InsideBottomLeft]: LabelPositionEnum.InsideTopRight,
+ [LabelPositionEnum.InsideTopRight]: LabelPositionEnum.InsideBottomLeft,
+ [LabelPositionEnum.InsideBottomRight]: LabelPositionEnum.InsideTopLeft,
+};
+
export function formatLabel({
params,
labelType,
@@ -260,7 +281,8 @@ export default function transformProps(
},
label: {
show: showLabels,
- position: labelPosition,
+ position:
+ RADAR_LABEL_POSITION_OVERRIDES[labelPosition] ?? labelPosition,
formatter,
},
} as RadarSeriesDataItemOption);
diff --git
a/superset-frontend/plugins/plugin-chart-echarts/test/Radar/transformProps.test.ts
b/superset-frontend/plugins/plugin-chart-echarts/test/Radar/transformProps.test.ts
index 4a0e2009715..f484160daf2 100644
---
a/superset-frontend/plugins/plugin-chart-echarts/test/Radar/transformProps.test.ts
+++
b/superset-frontend/plugins/plugin-chart-echarts/test/Radar/transformProps.test.ts
@@ -24,7 +24,7 @@ import {
EchartsRadarChartProps,
EchartsRadarFormData,
} from '../../src/Radar/types';
-import { LegendOrientation } from '../../src/types';
+import { LabelPositionEnum, LegendOrientation } from '../../src/types';
interface RadarIndicator {
name: string;
@@ -372,3 +372,123 @@ describe('radar center positioning', () => {
expect(y).toBeLessThan(50);
});
});
+
+describe('label position configuration', () => {
+ const createChartPropsWithLabelPosition = (position: LabelPositionEnum) =>
+ new ChartProps({
+ ...chartProps,
+ formData: {
+ ...formData,
+ groupby: ['name'],
+ metrics: ['SUM(eu_sales)'],
+ labelPosition: position,
+ showLabels: true,
+ },
+ queriesData: [
+ {
+ data: [
+ {
+ name: 'Test Series',
+ 'SUM(eu_sales)': 2434.13,
+ },
+ ],
+ },
+ ],
+ });
+
+ test('should apply top label position to radar series data items', () => {
+ const props = createChartPropsWithLabelPosition(LabelPositionEnum.Top);
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.position).toBe('top');
+ });
+
+ test('should apply left label position to radar series data items', () => {
+ const props = createChartPropsWithLabelPosition(LabelPositionEnum.Left);
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.position).toBe('left');
+ });
+
+ test('should apply right label position to radar series data items', () => {
+ const props = createChartPropsWithLabelPosition(LabelPositionEnum.Right);
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.position).toBe('right');
+ });
+
+ test('should apply bottom label position to radar series data items', () => {
+ const props = createChartPropsWithLabelPosition(LabelPositionEnum.Bottom);
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.position).toBe('bottom');
+ });
+
+ test('should apply inside label position to radar series data items', () => {
+ const props = createChartPropsWithLabelPosition(LabelPositionEnum.Inside);
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.position).toBe('inside');
+ });
+
+ // ZRender anchors an "inside*" label to the named edge of the point symbol
+ // and grows the text inward, so on a symbol smaller than its label the text
+ // overflows out the opposite side ("Inside Top" lands below the point,
+ // "Inside Left" lands to its right, corners land on the opposite diagonal).
+ // transformProps maps each directional inside position to its opposite
+ // before handing it to ECharts, so the dropdown choice renders where its
+ // name says.
+ test.each([
+ [LabelPositionEnum.InsideTop, 'insideBottom'],
+ [LabelPositionEnum.InsideBottom, 'insideTop'],
+ [LabelPositionEnum.InsideLeft, 'insideRight'],
+ [LabelPositionEnum.InsideRight, 'insideLeft'],
+ [LabelPositionEnum.InsideTopLeft, 'insideBottomRight'],
+ [LabelPositionEnum.InsideBottomLeft, 'insideTopRight'],
+ [LabelPositionEnum.InsideTopRight, 'insideBottomLeft'],
+ [LabelPositionEnum.InsideBottomRight, 'insideTopLeft'],
+ ])(
+ 'should swap %s to the ECharts position %s to compensate for the reversed
rendering',
+ (selected, expectedEchartsPosition) => {
+ const props = createChartPropsWithLabelPosition(selected);
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.position).toBe(
+ expectedEchartsPosition,
+ );
+ },
+ );
+
+ test('should hide labels when showLabels is false', () => {
+ const props = new ChartProps({
+ ...chartProps,
+ formData: {
+ ...formData,
+ groupby: ['name'],
+ metrics: ['SUM(eu_sales)'],
+ labelPosition: LabelPositionEnum.Top,
+ showLabels: false,
+ },
+ queriesData: [
+ {
+ data: [
+ {
+ name: 'Test Series',
+ 'SUM(eu_sales)': 2434.13,
+ },
+ ],
+ },
+ ],
+ });
+ const result = transformProps(props as EchartsRadarChartProps);
+ const series = result.echartOptions.series as RadarSeriesOption[];
+
+ expect((series[0].data as any)[0].label.show).toBe(false);
+ });
+});