bumbeishvili / org-chart

Highly customizable org chart. Integrations available for Angular, React, Vue
https://stackblitz.com/edit/web-platform-o5t1ha
MIT License
928 stars 330 forks source link

Updating single node #361

Open l99057j opened 9 months ago

l99057j commented 9 months ago

I'm using the library to display a hierarchical workflow with the status of each task being updated in real time. After the initial display of the chart, a SignalR connection is established. When a task's status changes, a message is received and the underlying chart data is updated...

let task = chart.data().find(x => x.id.toLowerCase() === status.taskId.toLowerCase()); if (task) { task.status = status.taskStatus; task.startTime = status.startTime; task.finishTime = status.finishTime; }

... and I then refresh the node like so...

function refreshNode(id) { let node = chart.getChartState().allNodes.find(x => x.id == id); if (node) { chart.update(node); } }

Console statements in my nodeContent function show that even though I'm passing a node to chart.update ALL nodes are being re-rendered. Is there a way to force an update on a single node to avoid unnecessary processing?

bumbeishvili commented 9 months ago

Since it's an HTML, you can just get the dom element of that specific node via pre set id or class using js and update it like that

Or probably a better way would be


function refreshNode(id) {
        let attrs = chart.getChartState()

      attrs.svg
            .selectAll(".node-foreign-object-div")
             .filter(x => x.id == id);
            .html(function (d, i, arr) {
                return attrs.nodeContent.bind(this)(d, i, arr, attrs)
            })

  }
}