File tree 1 file changed +17
-2
lines changed
packages/vchart/src/plugin/components/tooltip-handler
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -304,17 +304,32 @@ export class DomTooltipHandler extends BaseTooltipHandler {
304
304
}
305
305
protected _updateDomStyle ( sizeKey : 'width' | 'height' = 'width' ) {
306
306
const rootDom = this . _rootDom ;
307
-
308
307
const contentDom = [ ...( rootDom . children as any ) ] . find ( child =>
309
308
child . className . includes ( TOOLTIP_CONTENT_BOX_CLASS_NAME )
310
309
) ;
310
+ const titleDom = [ ...( rootDom . children as any ) ] . find ( child => child . className . includes ( TOOLTIP_TITLE_CLASS_NAME ) ) ;
311
311
312
312
if ( contentDom ) {
313
313
const tooltipSpec = this . _component . getSpec ( ) as ITooltipSpec ;
314
314
const contentStyle : Partial < CSSStyleDeclaration > = { } ;
315
+ const titleLabel = tooltipSpec . style ?. titleLabel ;
316
+ const autoFixTitleWidth = titleLabel && titleLabel . autoWidth && titleLabel . multiLine !== false ;
317
+
318
+ if ( autoFixTitleWidth && titleDom ) {
319
+ const maxWidth = [ ...( contentDom . children as any ) ] . reduce ( ( res , col ) => {
320
+ return sizeKey === 'height'
321
+ ? res + col . getBoundingClientRect ( ) . width
322
+ : Math . max ( res , col . getBoundingClientRect ( ) . width ) ;
323
+ } , 0 ) ;
324
+
325
+ if ( maxWidth > 0 ) {
326
+ titleDom . style . maxWidth = `${ maxWidth } px` ;
327
+ // 需要再计算一次,因为之前可能因为没有设置maxWidth, content的dom被撑宽了
328
+ titleDom . style . maxWidth = `${ Math . ceil ( contentDom . getBoundingClientRect ( ) . width ) } px` ;
329
+ }
330
+ }
315
331
316
332
if ( isValid ( tooltipSpec ?. style ?. maxContentHeight ) ) {
317
- const titleDom = rootDom . children [ 0 ] ;
318
333
const titleHeight =
319
334
titleDom && titleDom . className . includes ( TOOLTIP_TITLE_CLASS_NAME )
320
335
? titleDom . getBoundingClientRect ( ) . height + ( tooltipSpec . style . spaceRow ?? 0 )
You can’t perform that action at this time.
0 commit comments