Skip to content

Commit 53d2503

Browse files
committed
refactor: optimize fontFamily of tooltip
1 parent 4bf0b28 commit 53d2503

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/vchart/src/plugin/components/tooltip-handler/dom-tooltip-handler.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { ILayoutPoint } from '../../../typings';
1717
import { TooltipHandlerType } from '../../../component/tooltip/constant';
1818
import { getSvgHtml } from './utils/svg';
1919
import { escapeHTML } from './utils/common';
20-
20+
import { token } from '../../../theme/token';
2121
/**
2222
* The tooltip handler class.
2323
*/
@@ -82,6 +82,7 @@ export class DomTooltipHandler extends BaseTooltipHandler {
8282
parentElement.appendChild(this._container);
8383
}
8484
const tooltipElement = document.createElement('div');
85+
const globalTheme = this._chartOption?.getTheme() ?? {};
8586

8687
setStyleToDom(tooltipElement, {
8788
left: '0',
@@ -90,7 +91,7 @@ export class DomTooltipHandler extends BaseTooltipHandler {
9091
padding: '12px',
9192
position: 'absolute',
9293
zIndex: DEFAULT_TOOLTIP_Z_INDEX,
93-
fontFamily: 'sans-serif',
94+
fontFamily: (globalTheme?.fontFamily ?? token.fontFamily) as string,
9495
fontSize: '11px',
9596
borderRadius: '3px',
9697
borderStyle: 'solid',
@@ -170,7 +171,9 @@ export class DomTooltipHandler extends BaseTooltipHandler {
170171
}
171172

172173
protected _initStyle() {
173-
this._domStyle = getDomStyle(this._component.getSpec(), this._chartOption?.getTheme() ?? {});
174+
const tooltipSpec = this._component.getSpec() as ITooltipSpec;
175+
176+
this._domStyle = getDomStyle(tooltipSpec);
174177
}
175178

176179
// protected _updateDomString(actualTooltip?: ITooltipActual) {

packages/vchart/src/plugin/components/tooltip-handler/utils/style.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { isArray, isValid, isValidNumber, lowerCamelCaseToMiddle, normalizePadding } from '@visactor/vutils';
22
import type { ITooltipSpec, ITooltipTextTheme, ITooltipTheme } from '../../../../component/tooltip';
3-
import type { ITheme } from '../../../../theme';
4-
import { token } from '../../../../theme/token';
53

64
const DEFAULT_SHAPE_SPACING = 8;
75
const DEFAULT_KEY_SPACING = 26;
@@ -32,7 +30,7 @@ export const getTextStyle = (style: ITooltipTextTheme = {}) => {
3230
return textStyle;
3331
};
3432

35-
export const getDomStyle = (spec: ITooltipSpec = {}, globalTheme: ITheme) => {
33+
export const getDomStyle = (spec: ITooltipSpec = {}) => {
3634
const { style = {}, enterable, transitionDuration } = spec;
3735
const {
3836
panel = {},
@@ -57,12 +55,11 @@ export const getDomStyle = (spec: ITooltipSpec = {}, globalTheme: ITheme) => {
5755
panelStyle.transitionProperty = transitionDuration ? 'transform' : 'initial';
5856
panelStyle.transitionTimingFunction = transitionDuration ? 'ease-out' : 'initial';
5957
}
60-
panelStyle.fontFamily = (globalTheme?.fontFamily ?? token.fontFamily) as string;
6158

6259
if (isValidNumber(commonSpaceRow)) {
6360
rowStyle.marginBottom = `${commonSpaceRow}px`;
6461
}
65-
if (isValidNumber(maxContentHeight)) {
62+
if (isValid(maxContentHeight)) {
6663
contentStyle.maxHeight = `${maxContentHeight}px`;
6764
contentStyle.overflowY = 'auto';
6865
// todo 让内容宽度往外阔一点,给滚动条留出位置

0 commit comments

Comments
 (0)