MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / placeToken

Function placeToken

libs/echarts/echarts.simple.js:8700–8761  ·  view source on GitHub ↗
(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign)

Source from the content-addressed store, hash-verified

8698}
8699
8700function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
8701 var tokenStyle = style.rich[token.styleName] || {};
8702 tokenStyle.text = token.text;
8703
8704 // 'ctx.textBaseline' is always set as 'middle', for sake of
8705 // the bias of "Microsoft YaHei".
8706 var textVerticalAlign = token.textVerticalAlign;
8707 var y = lineTop + lineHeight / 2;
8708 if (textVerticalAlign === 'top') {
8709 y = lineTop + token.height / 2;
8710 }
8711 else if (textVerticalAlign === 'bottom') {
8712 y = lineTop + lineHeight - token.height / 2;
8713 }
8714
8715 !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(
8716 hostEl,
8717 ctx,
8718 tokenStyle,
8719 textAlign === 'right'
8720 ? x - token.width
8721 : textAlign === 'center'
8722 ? x - token.width / 2
8723 : x,
8724 y - token.height / 2,
8725 token.width,
8726 token.height
8727 );
8728
8729 var textPadding = token.textPadding;
8730 if (textPadding) {
8731 x = getTextXForPadding(x, textAlign, textPadding);
8732 y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
8733 }
8734
8735 setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
8736 setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
8737 setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
8738 setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
8739
8740 setCtx(ctx, 'textAlign', textAlign);
8741 // Force baseline to be "middle". Otherwise, if using "top", the
8742 // text will offset downward a little bit in font "Microsoft YaHei".
8743 setCtx(ctx, 'textBaseline', 'middle');
8744
8745 setCtx(ctx, 'font', token.font || DEFAULT_FONT);
8746
8747 var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
8748 var textFill = getFill(tokenStyle.textFill || style.textFill);
8749 var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);
8750
8751 // Fill after stroke so the outline will not cover the main part.
8752 if (textStroke) {
8753 setCtx(ctx, 'lineWidth', textStrokeWidth);
8754 setCtx(ctx, 'strokeStyle', textStroke);
8755 ctx.strokeText(token.text, x, y);
8756 }
8757 if (textFill) {

Callers 1

drawRichTextFunction · 0.70

Calls 8

needDrawBackgroundFunction · 0.70
drawBackgroundFunction · 0.70
getTextXForPaddingFunction · 0.70
setCtxFunction · 0.70
retrieve3Function · 0.70
getStrokeFunction · 0.70
getFillFunction · 0.70
retrieve2Function · 0.70

Tested by

no test coverage detected