【问题标题】:how to get silbling elements in sunburst如何在旭日形首饰中获取兄弟元素
【发布时间】:2015-06-15 21:55:40
【问题描述】:

我是 d3.js 的新手,我正在创建基于 surburst 的可视化。有人可以让我知道如何在 d3.js 中获取兄弟元素的外部元素。

【问题讨论】:

    标签: d3.js sunburst-diagram


    【解决方案1】:

    根据您的数据构建层次结构的主要部分将由 d3 完成。检查specpartition.nodes(root),了解如何将此信息放入节点。基本上,d3 将使用对其parentchildren 的引用来填充每个节点,从而提供导航层次结构所需的一切。

    作为起点,您可以看看这个sunburst diagram。当悬停在弧上时,该弧及其直到根节点的祖先都会突出显示。层次结构中要突出显示的节点的选择发生在单个函数中:

    // Given a node in a partition layout, return an array of all of its ancestor
    // nodes, highest first, but excluding the root.
    function getAncestors(node) {
      var path = [];
      var current = node;
      while (current.parent) {
        path.unshift(current);
        current = current.parent;
      }
      return path;
    }
    

    这个函数的一个更简单的版本将选择节点及其兄弟而不是祖先:

    function getAncestors(node) {
      return node.parent.children;
    }
    

    我将上面的示例改编为plunk,展示了这将如何帮助解决您的问题。在这个 plunk 中,悬停的节点及其兄弟节点将被突出显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 2018-03-22
      相关资源
      最近更新 更多