【问题标题】:d3.js - Truncate node text for specified node d.typed3.js - 截断指定节点 d.type 的节点文本
【发布时间】:2021-09-22 03:40:33
【问题描述】:

我想根据节点 d.type(或 d.data.type 取决于 d3.js 版本)截断指定节点的节点文本/标签。

所以对于我使用的一般截断:

if (d.name.length > 60)
    return d.name.substring(0, 30) + '...';
else
    return d.name;

但是我如何为特定的 d.type(或 d.data.type)节点执行此操作?

例如,if d.data.type == 'unit1' 然后截断标签

fiddle

【问题讨论】:

    标签: javascript jquery d3.js


    【解决方案1】:

    为什么不延长你的条件?

    if (d.name.length > 60 && d.data.type == 'unit1')
        return d.name.substring(0, 30) + '...';
    else
        return d.name;
    

    但是您的数据没有每个节点的type,只有叶子。也许这是你的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-14
      • 2016-11-03
      • 1970-01-01
      • 2013-10-21
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多