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

Function parsePlainText

libs/echarts/echarts.simple.js:7987–8031  ·  view source on GitHub ↗

* @public * @param {string} text * @param {string} font * @param {Object} [truncate] * @return {Object} block: {lineHeight, lines, height, outerHeight, canCacheByTextString} * Notice: for performance, do not calculate outerWidth util needed. * `canCacheByTextString` means the result `lines`

(text, font, padding, textLineHeight, truncate)

Source from the content-addressed store, hash-verified

7985 * without travel the result `lines`.
7986 */
7987function parsePlainText(text, font, padding, textLineHeight, truncate) {
7988 text != null && (text += '');
7989
7990 var lineHeight = retrieve2(textLineHeight, getLineHeight(font));
7991 var lines = text ? text.split('\n') : [];
7992 var height = lines.length * lineHeight;
7993 var outerHeight = height;
7994 var canCacheByTextString = true;
7995
7996 if (padding) {
7997 outerHeight += padding[0] + padding[2];
7998 }
7999
8000 if (text && truncate) {
8001 canCacheByTextString = false;
8002 var truncOuterHeight = truncate.outerHeight;
8003 var truncOuterWidth = truncate.outerWidth;
8004 if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
8005 text = '';
8006 lines = [];
8007 }
8008 else if (truncOuterWidth != null) {
8009 var options = prepareTruncateOptions(
8010 truncOuterWidth - (padding ? padding[1] + padding[3] : 0),
8011 font,
8012 truncate.ellipsis,
8013 {minChar: truncate.minChar, placeholder: truncate.placeholder}
8014 );
8015
8016 // FIXME
8017 // It is not appropriate that every line has '...' when truncate multiple lines.
8018 for (var i = 0, len = lines.length; i < len; i++) {
8019 lines[i] = truncateSingleLine(lines[i], options);
8020 }
8021 }
8022 }
8023
8024 return {
8025 lines: lines,
8026 height: height,
8027 outerHeight: outerHeight,
8028 lineHeight: lineHeight,
8029 canCacheByTextString: canCacheByTextString
8030 };
8031}
8032
8033/**
8034 * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'

Callers 2

getPlainTextRectFunction · 0.70
renderPlainTextFunction · 0.70

Calls 4

retrieve2Function · 0.70
getLineHeightFunction · 0.70
prepareTruncateOptionsFunction · 0.70
truncateSingleLineFunction · 0.70

Tested by

no test coverage detected