diff --git a/__tests__/integration/snapshots/static/mockFacetPieLegend.svg b/__tests__/integration/snapshots/static/mockFacetPieLegend.svg
new file mode 100644
index 0000000000..a63a8d4891
--- /dev/null
+++ b/__tests__/integration/snapshots/static/mockFacetPieLegend.svg
@@ -0,0 +1,3782 @@
+
\ No newline at end of file
diff --git a/__tests__/plots/static/index.ts b/__tests__/plots/static/index.ts
index 94b9d57016..b064404b80 100644
--- a/__tests__/plots/static/index.ts
+++ b/__tests__/plots/static/index.ts
@@ -342,3 +342,4 @@ export { mockPieSpiderRight } from './mock-pie-spider-right';
export { mockPieSpiderMany } from './mock-pie-spider-many';
export { mockPieSpiderHide } from './mock-pie-spider-hide';
export { mockPieSpiderExceed } from './mock-pie-spider-exceed';
+export { mockFacetPieLegend } from './mock-facet-pie-legend';
diff --git a/__tests__/plots/static/mock-facet-pie-legend.ts b/__tests__/plots/static/mock-facet-pie-legend.ts
new file mode 100644
index 0000000000..b325c293e7
--- /dev/null
+++ b/__tests__/plots/static/mock-facet-pie-legend.ts
@@ -0,0 +1,138 @@
+import { G2Spec } from '../../../src';
+
+export function mockFacetPieLegend(): G2Spec {
+ return {
+ type: 'facetRect',
+ data: {
+ type: 'inline',
+ value: [
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 96968.81,
+ ff543d1f8d0b4f29bef22d0cbed88def: 28457.53,
+ f043bde8c6ec4ed0b125cf45901ff47a: '装订机',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 107777.25,
+ ff543d1f8d0b4f29bef22d0cbed88def: 25285.57,
+ f043bde8c6ec4ed0b125cf45901ff47a: '收纳具',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 194752177.78,
+ ff543d1f8d0b4f29bef22d0cbed88def: 46626257.69,
+ f043bde8c6ec4ed0b125cf45901ff47a: '复印机',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 170635564.26,
+ ff543d1f8d0b4f29bef22d0cbed88def: 40305299.8,
+ f043bde8c6ec4ed0b125cf45901ff47a: '电话',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 5104153.12,
+ ff543d1f8d0b4f29bef22d0cbed88def: 1061636.93,
+ f043bde8c6ec4ed0b125cf45901ff47a: '桌子',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 96855.78,
+ ff543d1f8d0b4f29bef22d0cbed88def: 20490.12,
+ f043bde8c6ec4ed0b125cf45901ff47a: '信封',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 81068.67,
+ ff543d1f8d0b4f29bef22d0cbed88def: 16255.18,
+ f043bde8c6ec4ed0b125cf45901ff47a: '纸张',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 76659.47,
+ ff543d1f8d0b4f29bef22d0cbed88def: 18298.37,
+ f043bde8c6ec4ed0b125cf45901ff47a: '笔',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 4715752.38,
+ ff543d1f8d0b4f29bef22d0cbed88def: 1196462.6,
+ f043bde8c6ec4ed0b125cf45901ff47a: '椅子',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 95937.35,
+ ff543d1f8d0b4f29bef22d0cbed88def: 21738.01,
+ f043bde8c6ec4ed0b125cf45901ff47a: '胶带',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 77825.34,
+ ff543d1f8d0b4f29bef22d0cbed88def: 16735.45,
+ f043bde8c6ec4ed0b125cf45901ff47a: '橡皮',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 90100.33,
+ ff543d1f8d0b4f29bef22d0cbed88def: 16531.52,
+ f043bde8c6ec4ed0b125cf45901ff47a: '便签纸',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 199045124.34,
+ ff543d1f8d0b4f29bef22d0cbed88def: 45315823.8,
+ f043bde8c6ec4ed0b125cf45901ff47a: '配件',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 86760.25,
+ ff543d1f8d0b4f29bef22d0cbed88def: 17712.47,
+ f043bde8c6ec4ed0b125cf45901ff47a: '本子',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 168698505.65,
+ ff543d1f8d0b4f29bef22d0cbed88def: 34857916.67,
+ f043bde8c6ec4ed0b125cf45901ff47a: '投影仪',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 4658877.77,
+ ff543d1f8d0b4f29bef22d0cbed88def: 1220090.14,
+ f043bde8c6ec4ed0b125cf45901ff47a: '柜子',
+ },
+ {
+ '09e62ad4dd204ccda464e7b83db3c43e': 5645597.27,
+ ff543d1f8d0b4f29bef22d0cbed88def: 1389893.06,
+ f043bde8c6ec4ed0b125cf45901ff47a: '书架',
+ },
+ ],
+ transform: [
+ {
+ type: 'rename',
+ '09e62ad4dd204ccda464e7b83db3c43e': '单价求和',
+ ff543d1f8d0b4f29bef22d0cbed88def: '单位成本求和',
+ },
+ {
+ type: 'fold',
+ fields: ['单价求和', '单位成本求和'],
+ key: 'folded_key',
+ value: 'folded_value',
+ },
+ ],
+ },
+ encode: { x: 'folded_key' },
+ axis: { x: { title: false } },
+ children: [
+ {
+ type: 'view',
+ coordinate: { type: 'theta' },
+ frame: false,
+ children: [
+ {
+ type: 'interval',
+ encode: {
+ color: 'f043bde8c6ec4ed0b125cf45901ff47a',
+ y: 'folded_value',
+ },
+ axis: { y: { title: '单价求和' } },
+ transform: [{ type: 'stackY' }],
+ labels: [
+ {
+ text: 'f043bde8c6ec4ed0b125cf45901ff47a',
+ position: 'outside',
+ transform: [{ type: 'overlapHide' }],
+ },
+ ],
+ scale: { y: { facet: false } },
+ },
+ ],
+ },
+ ],
+ };
+}
diff --git a/src/composition/facetRect.ts b/src/composition/facetRect.ts
index 798a845bdb..d17a55e591 100644
--- a/src/composition/facetRect.ts
+++ b/src/composition/facetRect.ts
@@ -90,6 +90,7 @@ export const inferColor = useDefaultAdaptor(
const title = typeof encodeColor === 'string' ? encodeColor : '';
const [domain, type] = domainColor();
+
return {
encode: { color: encodeColor },
scale: { color: deepMix({}, scaleColor, { domain, type }) },
diff --git a/src/runtime/scale.ts b/src/runtime/scale.ts
index 0465c82026..cb693d1301 100644
--- a/src/runtime/scale.ts
+++ b/src/runtime/scale.ts
@@ -416,7 +416,7 @@ function categoricalColors(
library,
);
const { category10: c10, category20: c20 } = theme;
- const defaultPalette = unique(values.flat()).length <= c10.length ? c10 : c20;
+ const defaultPalette = unique(domain).length <= c10.length ? c10 : c20;
const { palette = defaultPalette, offset } = options;
if (Array.isArray(palette)) return palette;
// Built-in palettes have higher priority.