Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

echarts.format.truncateText #7479

Closed
baixiaoji opened this issue Jan 12, 2018 · 6 comments
Closed

echarts.format.truncateText #7479

baixiaoji opened this issue Jan 12, 2018 · 6 comments
Labels
stale Inactive for a long time. Will be closed in 7 days.

Comments

@baixiaoji
Copy link

Other comments [其他信息]

echarts.format.truncateText 像这一类的AP接口文档里好像没有

@pissang
Copy link
Contributor

pissang commented Jan 12, 2018

这个接口暂时还没对外开发

@baixiaoji
Copy link
Author

可是感觉这部分的功能都很好用,但是没有明确的文档看看

@TheoXiong
Copy link

TheoXiong commented May 9, 2019

echarts.format.truncateText(name,  40,  '14px Microsoft Yahei',  '…')

同问,第二个参数是什么意思,好像并不是字符串最大长度

@TheoXiong
Copy link

查看源码,大概明白了,第二个参数应该是文本宽度(单位:像素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);
};

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2021

This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.

@github-actions github-actions bot added the stale Inactive for a long time. Will be closed in 7 days. label Sep 3, 2021
@github-actions
Copy link
Contributor

This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Inactive for a long time. Will be closed in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants