【问题标题】:d3-org-chart, how to expand and highlight a node in onNodeClick eventd3-org-chart,如何在 onNodeClick 事件中展开和突出显示节点
【发布时间】:2023-01-28 01:57:04
【问题描述】:
var chart = new d3.OrgChart()
    .container('.chart-container')
    .data(dataFlattened)
    .nodeWidth((d) => 250)
    .initialZoom(0.7)
    .nodeHeight((d) => 175)
    .childrenMargin((d) => 40)
    .compactMarginBetween((d) => 15)
    .compactMarginPair((d) => 80)
    .nodeContent(function (d, i, arr, state) {
        return `*** html content obmitted ***`;
    })
    .onNodeClick(function (d) {
        // d = id of the node clicked
        // How to expand and change the color of the node here?
    })
    .render();

【问题讨论】:

    标签: d3.js orgchart


    【解决方案1】:

    单击节点时,您可以像这样使用高亮节点。

    var chart = new d3.OrgChart()
        .container('.chart-container')
        .data(dataFlattened)
        .nodeWidth((d) => 250)
        .initialZoom(0.7)
        .nodeHeight((d) => 175)
        .childrenMargin((d) => 40)
        .compactMarginBetween((d) => 15)
        .compactMarginPair((d) => 80)
        .nodeContent(function (d, i, arr, state) {
            return `*** html content obmitted ***`;
        })
        .onNodeClick(function (d) {
            // d = id of the node clicked
            // How to expand and change the color of the node here?
            d => chart.setHighlighted(d).render()
        })
        .render();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多