Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tooltip): Tooltip textStyle lineHeight does not work in default #20398

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/component/tooltip/TooltipHTMLContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ function assembleFont(textStyleModel: Model<TooltipOption['textStyle']>): string

cssText.push('font:' + textStyleModel.getFont());

// @ts-ignore, leave it to the tooltip refactor.
const lineHeight = textStyleModel.get('lineHeight') ?? Math.round(fontSize * 3 / 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use zrUtil.retrive2 instead.


fontSize
// @ts-ignore, leave it to the tooltip refactor.
&& cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
&& cssText.push('line-height:' + lineHeight + 'px');

const shadowColor = textStyleModel.get('textShadowColor');
const shadowBlur = textStyleModel.get('textShadowBlur') || 0;
Expand Down
21 changes: 19 additions & 2 deletions src/component/tooltip/tooltipMarkup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ type TextStyle = string | RichTextStyle;

const TOOLTIP_LINE_HEIGHT_CSS = 'line-height:1';

function getTooltipLineHeight(
textStyle: TooltipOption['textStyle']
) {
const lineHeight = textStyle.lineHeight;
if (lineHeight === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use == null to check undefined or null values.

return TOOLTIP_LINE_HEIGHT_CSS;
}
else {
return `line-height:${encodeHTML(lineHeight + '')}px`;
}
}
// TODO: more textStyle option
function getTooltipTextStyle(
textStyle: TooltipOption['textStyle'],
Expand Down Expand Up @@ -272,6 +283,7 @@ function buildSection(
const subMarkupText = ctx.renderMode === 'richText'
? subMarkupTextList.join(gaps.richText)
: wrapBlockHTML(
toolTipTextStyle,
subMarkupTextList.join(''),
noHeader ? topMarginForOuterGap : gaps.html
);
Expand All @@ -282,13 +294,15 @@ function buildSection(

const displayableHeader = makeValueReadable(fragment.header, 'ordinal', ctx.useUTC);
const {nameStyle} = getTooltipTextStyle(toolTipTextStyle, ctx.renderMode);
const tooltipLineHeight = getTooltipLineHeight(toolTipTextStyle);
if (ctx.renderMode === 'richText') {
return wrapInlineNameRichText(ctx, displayableHeader, nameStyle as RichTextStyle) + gaps.richText
+ subMarkupText;
}
else {
return wrapBlockHTML(
`<div style="${nameStyle};${TOOLTIP_LINE_HEIGHT_CSS};">`
toolTipTextStyle,
`<div style="${nameStyle};${tooltipLineHeight};">`
+ encodeHTML(displayableHeader)
+ '</div>'
+ subMarkupText,
Expand Down Expand Up @@ -350,6 +364,7 @@ function buildNameValue(
))
)
: wrapBlockHTML(
toolTipTextStyle,
(noMarker ? '' : markerStr)
+ (noName ? '' : wrapInlineNameHTML(readableName, !noMarker, nameStyle as string))
+ (noValue ? '' : wrapInlineValueHTML(
Expand Down Expand Up @@ -406,12 +421,14 @@ function getGap(gapLevel: number): {
}

function wrapBlockHTML(
textStyle: TooltipOption['textStyle'],
encodedContent: string,
topGap: number
): string {
const clearfix = '<div style="clear:both"></div>';
const marginCSS = `margin: ${topGap}px 0 0`;
return `<div style="${marginCSS};${TOOLTIP_LINE_HEIGHT_CSS};">`
const tooltipLineHeight = getTooltipLineHeight(textStyle);
return `<div style="${marginCSS};${tooltipLineHeight};">`
+ encodedContent + clearfix
+ '</div>';
}
Expand Down
278 changes: 278 additions & 0 deletions test/tooltip-textStyle-lineHeight.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.