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

Function truncateText

libs/echarts/echarts-en.simple.js:7846–7861  ·  view source on GitHub ↗

* Show ellipsis if overflow. * * @public * @param {string} text * @param {string} containerWidth * @param {string} font * @param {number} [ellipsis='...'] * @param {Object} [options] * @param {number} [options.maxIterations=3] * @param {number} [options.minChar=0] If truncate result

(text, containerWidth, font, ellipsis, options)

Source from the content-addressed store, hash-verified

7844 * @return {string}
7845 */
7846function truncateText(text, containerWidth, font, ellipsis, options) {
7847 if (!containerWidth) {
7848 return '';
7849 }
7850
7851 var textLines = (text + '').split('\n');
7852 options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
7853
7854 // FIXME
7855 // It is not appropriate that every line has '...' when truncate multiple lines.
7856 for (var i = 0, len = textLines.length; i < len; i++) {
7857 textLines[i] = truncateSingleLine(textLines[i], options);
7858 }
7859
7860 return textLines.join('\n');
7861}
7862
7863function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
7864 options = extend({}, options);

Callers 2

parseRichTextFunction · 0.70
avoidOverlapFunction · 0.70

Calls 2

prepareTruncateOptionsFunction · 0.70
truncateSingleLineFunction · 0.70

Tested by

no test coverage detected