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

Function prepareTruncateOptions

libs/echarts/echarts-en.simple.js:7863–7899  ·  view source on GitHub ↗
(containerWidth, font, ellipsis, options)

Source from the content-addressed store, hash-verified

7861}
7862
7863function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
7864 options = extend({}, options);
7865
7866 options.font = font;
7867 var ellipsis = retrieve2(ellipsis, '...');
7868 options.maxIterations = retrieve2(options.maxIterations, 2);
7869 var minChar = options.minChar = retrieve2(options.minChar, 0);
7870 // FIXME
7871 // Other languages?
7872 options.cnCharWidth = getWidth('国', font);
7873 // FIXME
7874 // Consider proportional font?
7875 var ascCharWidth = options.ascCharWidth = getWidth('a', font);
7876 options.placeholder = retrieve2(options.placeholder, '');
7877
7878 // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
7879 // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
7880 var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
7881 for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
7882 contentWidth -= ascCharWidth;
7883 }
7884
7885 var ellipsisWidth = getWidth(ellipsis, font);
7886 if (ellipsisWidth > contentWidth) {
7887 ellipsis = '';
7888 ellipsisWidth = 0;
7889 }
7890
7891 contentWidth = containerWidth - ellipsisWidth;
7892
7893 options.ellipsis = ellipsis;
7894 options.ellipsisWidth = ellipsisWidth;
7895 options.contentWidth = contentWidth;
7896 options.containerWidth = containerWidth;
7897
7898 return options;
7899}
7900
7901function truncateSingleLine(textLine, options) {
7902 var containerWidth = options.containerWidth;

Callers 2

truncateTextFunction · 0.70
parsePlainTextFunction · 0.70

Calls 4

maxMethod · 0.80
extendFunction · 0.70
retrieve2Function · 0.70
getWidthFunction · 0.70

Tested by

no test coverage detected