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

Function truncateSingleLine

libs/echarts/echarts.simple.js:7901–7937  ·  view source on GitHub ↗
(textLine, options)

Source from the content-addressed store, hash-verified

7899}
7900
7901function truncateSingleLine(textLine, options) {
7902 var containerWidth = options.containerWidth;
7903 var font = options.font;
7904 var contentWidth = options.contentWidth;
7905
7906 if (!containerWidth) {
7907 return '';
7908 }
7909
7910 var lineWidth = getWidth(textLine, font);
7911
7912 if (lineWidth <= containerWidth) {
7913 return textLine;
7914 }
7915
7916 for (var j = 0; ; j++) {
7917 if (lineWidth <= contentWidth || j >= options.maxIterations) {
7918 textLine += options.ellipsis;
7919 break;
7920 }
7921
7922 var subLength = j === 0
7923 ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
7924 : lineWidth > 0
7925 ? Math.floor(textLine.length * contentWidth / lineWidth)
7926 : 0;
7927
7928 textLine = textLine.substr(0, subLength);
7929 lineWidth = getWidth(textLine, font);
7930 }
7931
7932 if (textLine === '') {
7933 textLine = options.placeholder;
7934 }
7935
7936 return textLine;
7937}
7938
7939function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
7940 var width = 0;

Callers 2

truncateTextFunction · 0.70
parsePlainTextFunction · 0.70

Calls 2

getWidthFunction · 0.70
estimateLengthFunction · 0.70

Tested by

no test coverage detected