echarts icon indicating copy to clipboard operation
echarts copied to clipboard

feat(graph) full path emphasis. close #17448

Open ElayGelbart opened this issue 2 years ago • 2 comments

Graph Emphasis Full Path:

This pull request is in the type of:

  • [ ] bug fixing
  • [x] new feature
  • [ ] others

this pull request adding the functionality to emphasis the full path from start to finish on hover/highlight event

Fixed issues

  • #17448

Details

Before: What was the problem?

There was only three options, 'self','series','adjacency'. it was needed to emphasis the whole path of nodes/edges to highlight all the related paths to specific node/edge

'adjacency' provide only one before one after emphasis.

image

After: How does it behave after the fixing?

after we can have fullPath option on emphasis:focus

chaer.setOption({
  series: [
    {
      type: 'sankey',
      nodes: data.nodes,
      links: data.links,
      lineStyle: {
        color: 'gradient',
        curveness: 0.5
      },
      emphasis: {
        focus: 'fullPath'
      }
    }
  ];
});

image

Document Info

One of the following should be checked.

  • [ ] This PR doesn't relate to document changes
  • [ ] The document should be updated later
  • [x] The document changes have been made in apache/echarts-doc#276

Misc

ZRender Changes

  • [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

Please refer to test/emphasis-fullPath.html

Others

Merging options

  • [ ] Please squash the commits into a single one when merging.

Other information

ElayGelbart avatar Aug 01 '22 07:08 ElayGelbart

Thanks for your contribution! The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the PR: awaiting doc label.

echarts-bot[bot] avatar Aug 01 '22 07:08 echarts-bot[bot]

  • https://github.com/apache/echarts-doc/pull/276
  • echarts-doc pull request adding changes

ElayGelbart avatar Aug 01 '22 08:08 ElayGelbart

Hey I know you're busy, when this will get review ? @plainheart @pissang

ElayGelbart avatar Aug 23 '22 12:08 ElayGelbart

Is there any release date for this PR merge ?

ElayGelbart avatar Dec 10 '22 13:12 ElayGelbart

This feature is ready to release in Feb or there are other requested changes ?

ElayGelbart avatar Jan 11 '23 13:01 ElayGelbart

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


  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),
        };
    };

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),
    };
  };
  

theBstar avatar Feb 08 '23 09:02 theBstar

@Ovilia @theBstar

Code is updated to improve performance :)

ElayGelbart avatar Feb 21 '23 14:02 ElayGelbart

@plainheart Fixed code by your recommendations

ElayGelbart avatar Feb 22 '23 16:02 ElayGelbart

I think this is a bug, right? image

Hey @Ovilia , This is not a bug, Liquid node is connected to Bio-conversion node...

ElayGelbart avatar Mar 05 '23 07:03 ElayGelbart

@Ovilia I agree with @ElayGelbart. It's a bit hard to see but they do connect with a very thin line.

plainheart avatar Mar 06 '23 04:03 plainheart

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

echarts-bot[bot] avatar Mar 09 '23 08:03 echarts-bot[bot]

发现个问题:focus 配置为 'trajectory' 时,当节点数 data,超过 100 ,边 links 超过 300 的时候,会导致页面崩溃

lhd163 avatar Sep 06 '23 06:09 lhd163

@lhd163 Thanks for your feedback. Please file a bug report with a reproduction example.

plainheart avatar Sep 11 '23 12:09 plainheart