Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 5 additions & 3 deletions src/component/tooltip/TooltipHTMLContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { isString, indexOf, each, bind, isFunction, isArray, isDom } from 'zrender/src/core/util';
import { isString, indexOf, each, bind, isFunction, isArray, isDom, retrieve2 } from 'zrender/src/core/util';
import { normalizeEvent } from 'zrender/src/core/event';
import { transformLocalCoord } from 'zrender/src/core/dom';
import env from 'zrender/src/core/env';
Expand Down 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 = retrieve2(textStyleModel.get('lineHeight'), Math.round(fontSize * 3 / 2));

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 || lineHeight === null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use lineHeight == null should be enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, that's work well

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.