echarts.format.truncateText 像这一类的AP接口文档里好像没有
这个接口暂时还没对外开发
可是感觉这部分的功能都很好用,但是没有明确的文档看看
echarts.format.truncateText(name, 40, '14px Microsoft Yahei', '…')
同问,第二个参数是什么意思,好像并不是字符串最大长度
查看源码,大概明白了,第二个参数应该是文本宽度(单位:像素px)。
/**
* 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 are less
* then minChar, ellipsis will not show, which is
* better for user hint in some cases.
* @param {number} [options.placeholder=''] When all truncated, use the placeholder.
* @return {string}
*/
function truncateText(text, containerWidth, font, ellipsis, options) {
if (!containerWidth) {
return '';
}
var textLines = (text + '').split('\n');
options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
// FIXME
// It is not appropriate that every line has '...' when truncate multiple lines.
for (var i = 0, len = textLines.length; i < len; i++) {
textLines[i] = truncateSingleLine(textLines[i], options);
}
return textLines.join('\n');
}
/**
* @public
* @param {string} text
* @param {string} font
* @return {Object} width
*/
function measureText(text, font) {
return methods$1.measureText(text, font);
}
// Avoid assign to an exported variable, for transforming to cjs.
methods$1.measureText = function (text, font) {
var ctx = getContext();
ctx.font = font || DEFAULT_FONT$1;
return ctx.measureText(text);
};
Most helpful comment
可是感觉这部分的功能都很好用,但是没有明确的文档看看