Skip to content

Commit

Permalink
edge.isBundledBezier() should return false for styleless instance
Browse files Browse the repository at this point in the history
- The internal style function, `ele.isBundledBezier()` will not work in a styleless instance, because `ele.pstyle()` will always return `undefined`.  It should have a check like the other style functions.  Most of these functions are derived state functions, which have this check implicitly.
- `edge.isBundledBezier()` is only used in a few places.  The only place that would affect a headless instance is `ele.remove()`.
- This patch includes a fix and several test cases.

Ref : Removing parallel edges in headless mode #2377
  • Loading branch information
maxkfranz committed Apr 30, 2019
1 parent 778d679 commit 14d13df
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/collection/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ elesfn.hidden = function(){
};

elesfn.isBundledBezier = cachePrototypeStyleFunction('isBundledBezier', function(){
if( !this.cy().styleEnabled() ){ return false; }

return !this.removed() && this.pstyle('curve-style').value === 'bezier' && this.takesUpSpace();
});

Expand Down
38 changes: 38 additions & 0 deletions test/collection-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,44 @@ describe('Collection style', function(){

expect( cy.$('#c').visible() ).to.be.true;
});

it('ele.isBundledBezier() true for `curve-style: bezier`', function(){
var edges = cy.add([
{ data: { id: 'bez1', source: 'n1', target: 'n2' } },
{ data: { id: 'bez2', source: 'n1', target: 'n2' } },
{ data: { id: 'bez3', source: 'n1', target: 'n2' } }
]);

edges.style('curve-style', 'bezier');

edges.forEach(function(edge){
expect(edge.isBundledBezier(), edge.id()).to.be.true;
});
});

it('ele.isBundledBezier() false for style disabled', function(){
var cy = cytoscape({
headless: true,
styleEnabled: false,
elements: [
{ data: { id: 'n1' } },
{ data: { id: 'n2' } }
]
});

var edges = cy.add([
{ data: { id: 'bez1', source: 'n1', target: 'n2' } },
{ data: { id: 'bez2', source: 'n1', target: 'n2' } },
{ data: { id: 'bez3', source: 'n1', target: 'n2' } }
]);

// this should be a nop
edges.style('curve-style', 'bezier');

edges.forEach(function(edge){
expect(edge.isBundledBezier(), edge.id()).to.be.false;
});
});
});

describe('eles.addClass() etc', function(){
Expand Down
37 changes: 37 additions & 0 deletions test/core-graph-manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ describe('Core graph manipulation', function(){
expect( cy.$('#foo').numericStyle('border-width') ).to.equal(10);
});


});

describe('eles.restore()', function(){
Expand Down Expand Up @@ -231,6 +232,42 @@ describe('Core graph manipulation', function(){

});

it('removes a parallel edge headlessly', function(){
// re. headlessly calling edge.isBundledBezier() #2377

var cy = cytoscape({
headless: true,
styleEnabled: false, // important
elements: [
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{
data: {
id: 'ab2',
source: 'a',
target: 'b'
}
},
{
data: {
id: 'ab1',
source: 'a',
target: 'b'
}
}]
});

cy.edges()[0].remove();

expect(cy.edges().length, 'number of edges (A)').to.equal(1);
expect(cy.nodes().length, 'number of nodes (A)').to.equal(2);

cy.edges()[0].remove();

expect(cy.edges().length, 'number of edges (B)').to.equal(0);
expect(cy.nodes().length, 'number of nodes (B)').to.equal(2);
});

it('removes via selector', function(){
cy.remove('edge');

Expand Down

0 comments on commit 14d13df

Please sign in to comment.