@@ -3,13 +3,22 @@ import { isArray, get, deepMix, isEqual } from '@antv/util';
33import { interaction , animation , theme , tooltip , scale } from '../../adaptor/common' ;
44import { Params } from '../../core/adaptor' ;
55import { schema as schemaGeometry } from '../../adaptor/geometries' ;
6- import { deepAssign , flow , getAdjustAppendPadding , normalPadding , resolveAllPadding } from '../../utils' ;
6+ import {
7+ deepAssign ,
8+ flow ,
9+ findGeometry ,
10+ transformLabel ,
11+ getAdjustAppendPadding ,
12+ normalPadding ,
13+ resolveAllPadding ,
14+ } from '../../utils' ;
715import { Datum } from '../../types' ;
816import { log , LEVEL } from '../../../src/utils' ;
917import { getColorMap , layoutVennData , islegalSets } from './utils' ;
1018import { CustomInfo , VennData , VennOptions } from './types' ;
1119import { ID_FIELD } from './constant' ;
1220import './shape' ;
21+ import './label' ;
1322
1423/** 图例默认预留空间 */
1524export const LEGEND_SPACE = 40 ;
@@ -99,12 +108,12 @@ function data(params: Params<VennOptions>): Params<VennOptions> {
99108 */
100109function geometry ( params : Params < VennOptions > ) : Params < VennOptions > {
101110 const { chart, options } = params ;
102- const { pointStyle, label , setsField, sizeField } = options ;
111+ const { pointStyle, setsField, sizeField } = options ;
103112
104113 // 获取容器大小
105114 const [ t , r , b , l ] = normalPadding ( chart . appendPadding ) ;
106115 // 处理 legend 的位置. 默认预留 40px, 业务上可以通过 appendPadding 增加
107- const customInfo : CustomInfo = { offsetX : l , offsetY : t , label } ;
116+ const customInfo : CustomInfo = { offsetX : l , offsetY : t } ;
108117 // coordinateBBox + appendPadding = viewBBox, 不需要再计算 appendPadding 部分,因此直接使用 viewBBox
109118 const { width, height } = chart . viewBBox ;
110119 // 处理padding输入不合理的情况, w 和 h 不能为负数
@@ -119,8 +128,6 @@ function geometry(params: Params<VennOptions>): Params<VennOptions> {
119128 sizeField : sizeField ,
120129 seriesField : ID_FIELD ,
121130 rawFields : [ setsField , sizeField ] ,
122- // 不使用 G2 的label,直接在自定义 shape 中实现
123- label : false ,
124131 schema : {
125132 shape : 'venn' ,
126133 style : pointStyle ,
@@ -136,6 +143,39 @@ function geometry(params: Params<VennOptions>): Params<VennOptions> {
136143 return params ;
137144}
138145
146+ /**
147+ * 处理 label
148+ * @param params
149+ */
150+ function label ( params : Params < VennOptions > ) : Params < VennOptions > {
151+ const { chart, options } = params ;
152+ const { label } = options ;
153+
154+ // 获取容器大小
155+ const [ t , r , b , l ] = normalPadding ( chart . appendPadding ) ;
156+ // 传入 label 布局函数所需的 自定义参数
157+ const customLabelInfo = { offsetX : l , offsetY : t } ;
158+
159+ const geometry = findGeometry ( chart , 'schema' ) ;
160+
161+ if ( ! label ) {
162+ geometry . label ( false ) ;
163+ } else {
164+ const { callback, ...cfg } = label ;
165+ geometry . label ( {
166+ fields : [ 'id' ] ,
167+ callback,
168+ cfg : deepMix ( { } , transformLabel ( cfg ) , {
169+ // 使用 G2 的 自定义label 修改位置
170+ type : 'venn' ,
171+ customLabelInfo,
172+ } ) ,
173+ } ) ;
174+ }
175+
176+ return params ;
177+ }
178+
139179/**
140180 * legend 配置
141181 * @param params
@@ -174,6 +214,7 @@ export function adaptor(params: Params<VennOptions>) {
174214 theme ,
175215 data ,
176216 geometry ,
217+ label ,
177218 scale ( { } ) ,
178219 legend ,
179220 axis ,
0 commit comments