You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "theBstar (via GitHub)" <gi...@apache.org> on 2023/02/08 09:38:57 UTC

[GitHub] [echarts] theBstar commented on pull request #17451: feat(graph) full path emphasis. close #17448

theBstar commented on PR #17451:
URL: https://github.com/apache/echarts/pull/17451#issuecomment-1422306011

   I am using this patch in my project. Thanks for the contribution (PR) 🙌 .
   
   I was rendering a sankey with some custom tooltip & label formater function. It started becoming unresponsive, when I had ~70 nodes & ~300 edges. 
   
   I have made a few changes in your code (no change in logic) to decrease memory allocations (array shift & push) & indexOf checks (which is O(n)). Sharing both functions after changes below
   
   ```js
   
     GraphNode.prototype.getFullPathDataIndices = function () {
           const connectedEdgesMap = {};
           const connectedNodesMap = {};
         
           for (let i = 0; i < this.edges.length; i++) {
               const adjacentEdge = this.edges[i];
               if (adjacentEdge.dataIndex < 0) {
                 continue;
               }
   
               connectedEdgesMap[adjacentEdge.dataIndex] = true;
             
               const sourceNodesQueue = [adjacentEdge.node1];
               const targetNodesQueue = [adjacentEdge.node2];
   
               let nodeIteratorIndex = 0;
               while (nodeIteratorIndex < sourceNodesQueue.length) {
                 const sourceNode = sourceNodesQueue[nodeIteratorIndex];
                 nodeIteratorIndex++;
                 connectedNodesMap[sourceNode.dataIndex] = true;
   
                 for (let j = 0; j < sourceNode.inEdges.length; j++) {
                   connectedEdgesMap[sourceNode.inEdges[j].dataIndex] = true;
                   sourceNodesQueue.push(sourceNode.inEdges[j].node1);
                 }
               }
             
               nodeIteratorIndex = 0;
               while (nodeIteratorIndex < targetNodesQueue.length) {
                 const targetNode = targetNodesQueue[nodeIteratorIndex];
                 nodeIteratorIndex++;
                 
                 connectedNodesMap[targetNode.dataIndex] = true;
                 for (let j = 0; j < targetNode.outEdges.length; j++) {
                   connectedEdgesMap[targetNode.outEdges[j].dataIndex] = true;
                   targetNodesQueue.push(targetNode.outEdges[j].node2);
                 }
               }
           }
   
           return {
             edge: Object.keys(connectedEdgesMap),
             node: Object.keys(connectedNodesMap),
           };
       };
   
   ```
   
   ```js
   GraphEdge.prototype.getFullPathDataIndices = function () {
       const connectedEdgesMap = {};
       const connectedNodesMap = {};
     
       connectedEdgesMap[this.dataIndex] = true;
       const sourceNodes = [this.node1];
       const targetNodes = [this.node2];
      
       let nodeIteratorIndex = 0;
       while (nodeIteratorIndex < sourceNodes.length) {
         const sourceNode = sourceNodes[nodeIteratorIndex];
         nodeIteratorIndex++;
   
         connectedNodesMap[sourceNode.dataIndex] = true;
   
         for (let j = 0; j < sourceNode.inEdges.length; j++) {
           connectedEdgesMap[sourceNode.inEdges[j].dataIndex] = true;
           sourceNodes.push(sourceNode.inEdges[j].node1);
         }
       }
   
       nodeIteratorIndex = 0;
       while (nodeIteratorIndex < targetNodes.length) {
         const targetNode = targetNodes[nodeIteratorIndex];
         nodeIteratorIndex++;
   
         connectedNodesMap[targetNode.dataIndex] = true;
         
         for (let j = 0; j < targetNode.outEdges.length; j++) {
           connectedEdgesMap[targetNode.outEdges[j].dataIndex] = true;
           targetNodes.push(targetNode.outEdges[j].node2);
         }
       }
   
       return {
         edge: Object.keys(connectedEdgesMap),
         node: Object.keys(connectedNodesMap),
       };
     };
     
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org