Skip to content

Commit 916a426

Browse files
author
荊芥
committed
fix: 修复分面图下多图例显示配置
1 parent 7426dd3 commit 916a426

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/plots/facet/adaptor.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function facetAdaptor(params: Params<FacetOptions>): Params<FacetOptions> {
4141
} else {
4242
const plot = viewOptions as IPlot;
4343
const plotOptions = plot.options;
44+
45+
// 如果 view 内部没有指定映射字段,则使用 options 内指定的映射字段
46+
['seriesField', 'colorField', 'shapeField', 'sizeField', 'groupField'].forEach((key) => {
47+
if (options[key] && typeof plotOptions[key] === 'undefined') {
48+
plotOptions[key] = options[key];
49+
}
50+
});
51+
4452
// @ts-ignore 仪表盘没 tooltip
4553
if (plotOptions.tooltip) {
4654
// 配置 tooltip 交互
@@ -56,7 +64,20 @@ function facetAdaptor(params: Params<FacetOptions>): Params<FacetOptions> {
5664

5765
function component(params: Params<FacetOptions>): Params<FacetOptions> {
5866
const { chart, options } = params;
59-
const { axes, meta, tooltip, coordinate, theme, legend, interactions, annotations } = options;
67+
const {
68+
axes,
69+
meta,
70+
tooltip,
71+
coordinate,
72+
theme,
73+
legend,
74+
interactions,
75+
annotations,
76+
shapeField,
77+
sizeField,
78+
shapeLegend,
79+
sizeLegend,
80+
} = options;
6081

6182
// 3. meta 配置
6283
let scales: Record<string, any> = {};
@@ -91,6 +112,17 @@ function component(params: Params<FacetOptions>): Params<FacetOptions> {
91112

92113
// 7. legend 配置(默认展示)
93114
chart.legend(legend);
115+
if (shapeField) {
116+
chart.legend(shapeField, shapeLegend ? shapeLegend : false);
117+
}
118+
119+
if (sizeField) {
120+
chart.legend(sizeField, sizeLegend ? sizeLegend : false);
121+
}
122+
// /** 默认不展示 shape 图例,当 shapeLegend 为 undefined 也不展示图例 */
123+
if (!legend && !shapeLegend && !sizeLegend) {
124+
chart.legend(false);
125+
}
94126

95127
// theme 配置
96128
if (theme) {

src/plots/facet/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,24 @@ export interface FacetOptions<T extends keyof Types.FacetCfgMap = keyof Types.Fa
149149
* @title 图例配置
150150
*/
151151
readonly interactions?: Interaction[];
152+
/**
153+
* @title 形状字段
154+
* @description 形状映射字段
155+
*/
156+
readonly shapeField?: string;
157+
/**
158+
* @title 大小字段
159+
* @description 大小映射字段
160+
*/
161+
readonly sizeField?: string;
162+
/**
163+
* @title 形状图例配置
164+
* @description 形状图例的配置项
165+
*/
166+
readonly shapeLegend?: Legend | false;
167+
/**
168+
* @title 大小图例配置
169+
* @description 大小图例的配置项
170+
*/
171+
readonly sizeLegend?: Legend | false;
152172
}

0 commit comments

Comments
 (0)