cytoscape.js icon indicating copy to clipboard operation
cytoscape.js copied to clipboard

Edge.segmentPoints() and controlPoints() return undefined immediately after adding an edge.

Open feel0321 opened this issue 1 year ago • 0 comments

Before you post

A request for help or a request for a how-to should be directed to Phind.

If your issue pertains to an extension, your issue should be filed in that extension's repository -- not here.

Environment info

  • Cytoscape.js version : 3.31.0-unstable
  • Browser/Node.js & version : Chrome 127.0.6533.89 / Node v18.17.0

Current (buggy) behaviour

I want to get segmentPoint or controlPoint immediately after edge is added. but edge.segmentPoints() and edge.controlPoints() method returns undefined when immediately after edge is added.

this is my checked.

  1. edge.segmentPoints() method returns array with using setTimeout
// this is array
setTimeout(() => console.log(edge.segmentPoints()))
  1. edge.segmentPoints() method returns array after edge.midpoint(). you can check my jsbin link.

  2. I found an issue ( #2250) and pr (https://github.com/cytoscape/cytoscape.js/commit/d0d70c20f7e2cfa4d87e6c44be82aed4d30607ab)

I think segments and unbundled-bezier edge required recalculateRenderedStyle(). I test a little bit, it returns array

BRp$c.getSegmentPoints = function( edge ){
    // add line
    this.recalculateRenderedStyle( edge );
    
    let rs = edge[0]._private.rscratch;
    let type = rs.edgeType;
    
    if( type === 'segments' ){
      // this.recalculateRenderedStyle( edge );
      return getPts( rs.segpts );
    }
  };

but it's my first issue. so I have no confidence. how about this?

Desired behaviour

edge.segmentPoints() and edge.controlPoints() method should return array immediately after the edge is added.

Minimum steps to reproduce

https://jsbin.com/ruqahuc/1/edit?html,js,output

  1. you can see undefined in console.
  2. if you remove midpoint() comment, you can see array in console.

For reviewers

Reviewers should ensure that the following tasks are carried out for incorporated issues:

  • [ ] Ensure that the reporter has included a reproducible demo. They can easily fork this JSBin demo: http://jsbin.com/fiqugiq
  • [ ] The issue has been associated with a corresponding milestone.
  • [ ] The commits have been incorporated into the corresponding branches. Bug-fix patches go on
    • [ ] master,
    • [ ] unstable, and
    • [ ] the previous feature release branch (e.g. 1.1.x if the current release is 1.2).
  • [ ] The issue has been labelled as a bug, if necessary.

feel0321 avatar Aug 12 '24 16:08 feel0321