Skip to content

Commit

Permalink
add tests; fixes to codebase from tests; docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Sep 10, 2014
1 parent d5da20f commit 7682ea5
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 74 deletions.
4 changes: 4 additions & 0 deletions documentation/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ button:active {
right: 0;
opacity: 0.666;
font-size: 0.8em;

border: 1px solid #4183C4;
color: #4183C4;
background: transparent;
}

/*.run + * {
Expand Down
26 changes: 13 additions & 13 deletions documentation/docmaker.json
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,19 @@
},

{
"name": "eles.allAre",
"descr": "Determine whether all elements in the collection match a selector.",
"formats": [
{
"args": [
{ "name": "selector", "descr": "The selector to match against." }
]
}
]

},

{
"name": "eles.some",
"descr": "Determine whether any element in this collection satisfies the specified test function.",
"formats": [
Expand Down Expand Up @@ -1756,19 +1769,6 @@
]
}
]
},

{
"name": "eles.allAre",
"descr": "Determine whether all elements in the collection match a selector.",
"formats": [
{
"args": [
{ "name": "selector", "descr": "The selector to match against." }
]
}
]

}
]
},
Expand Down
82 changes: 41 additions & 41 deletions documentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ <h2 id="notation/position">Position <a href="#notation/position"><span class="ic
<p>A node&#39;s position refers to the centre point of its bounding box.</p>
<p>There is an important distinction to make for position: A position may be a <em>model</em> position or a <em>rendered</em> position.</p>
<p>A model position &mdash; as its name suggests &mdash; is the position stored in the model for an element. An element&#39;s model position remains constant, despite changes to zoom and pan.</p>
<p>A rendered position is an on-screen location relative to the viewport. For example, a rendered position of <code>{ x: 100, y: 100 }</code> specifies a point 100 pixels to the right and 100 pixels down from the top-left corner of the viewport. An element&#39;s rendered position naturally changes as zoom and pan changes, because the element&#39;s on-screen position in the viewport changes as zooming and panning are applied.</p>
<p>A rendered position is an on-screen location relative to the viewport. For example, a rendered position of <code>{ x: 100, y: 100 }</code> specifies a point 100 pixels to the right and 100 pixels down from the top-left corner of the viewport. An element&#39;s rendered position naturally changes as zoom and pan changes, because the element&#39;s on-screen position in the viewport changes as zooming and panning are applied. Panning is always measured in rendered coordinates.</p>
<p>In this documentation, &quot;position&quot; refers to model position unless otherwise stated.</p>
<h2 id="notation/elements-json">Elements JSON <a href="#notation/elements-json"><span class="icon-bookmark"></span></a></h2>
<p>Examples are given that outline format of the elements JSON used to load elements into Cytoscape.js:</p>
Expand Down Expand Up @@ -6825,6 +6825,44 @@ <h2 id="collection/comparison">Comparison <a href="#collection/comparison"><span
</div>
</div>

<div class="function">
<div class="name" id="collection/comparison/eles.allAre"><span class="fn-name">eles.allAre()</span> <a href="#collection/comparison/eles.allAre"><span class="icon-bookmark"></span></a></div>



<div class="descr"><p>Determine whether all elements in the collection match a selector.</p>
</div>


<div class="formats">

<div class="format">

<div class="name">eles.allAre( <span class="comma">, </span>selector )</div>

<div class="descr"></div>
<ul class="args">

<li>
<span class="name"><a href="#selectors">selector</a></span>

<span class="descr"><p>The selector to match against.</p>
</span>


</li>

</ul>
</div>

</div>


<div class="details">

</div>
</div>

<div class="function">
<div class="name" id="collection/comparison/eles.some"><span class="fn-name">eles.some()</span> <a href="#collection/comparison/eles.some"><span class="icon-bookmark"></span></a></div>

Expand Down Expand Up @@ -6981,44 +7019,6 @@ <h2 id="collection/comparison">Comparison <a href="#collection/comparison"><span
</div>
</div>

<div class="function">
<div class="name" id="collection/comparison/eles.allAre"><span class="fn-name">eles.allAre()</span> <a href="#collection/comparison/eles.allAre"><span class="icon-bookmark"></span></a></div>



<div class="descr"><p>Determine whether all elements in the collection match a selector.</p>
</div>


<div class="formats">

<div class="format">

<div class="name">eles.allAre( <span class="comma">, </span>selector )</div>

<div class="descr"></div>
<ul class="args">

<li>
<span class="name"><a href="#selectors">selector</a></span>

<span class="descr"><p>The selector to match against.</p>
</span>


</li>

</ul>
</div>

</div>


<div class="details">

</div>
</div>




Expand Down Expand Up @@ -11176,12 +11176,12 @@ <h2 id="performance/optimisations">Optimisations <a href="#performance/optimisat

<div class="section lvl3"><a href="#collection/comparison/eles.is"><span class="icon-bookmark bookmark-icon"></span> eles.is() </a></div>

<div class="section lvl3"><a href="#collection/comparison/eles.allAre"><span class="icon-bookmark bookmark-icon"></span> eles.allAre() </a></div>

<div class="section lvl3"><a href="#collection/comparison/eles.some"><span class="icon-bookmark bookmark-icon"></span> eles.some() </a></div>

<div class="section lvl3"><a href="#collection/comparison/eles.every"><span class="icon-bookmark bookmark-icon"></span> eles.every() </a></div>

<div class="section lvl3"><a href="#collection/comparison/eles.allAre"><span class="icon-bookmark bookmark-icon"></span> eles.allAre() </a></div>


<div class="section lvl2">
<span class="expander">
Expand Down
4 changes: 2 additions & 2 deletions src/collection-comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

some: function( fn, thisArg ){
for( var i = 0; i < this.length; i++ ){
var ret = fn.apply( thisArg, [ ele, i, this ] );
var ret = fn.apply( thisArg, [ this[i], i, this ] );

if( ret ){
return true;
Expand All @@ -23,7 +23,7 @@

every: function( fn, thisArg ){
for( var i = 0; i < this.length; i++ ){
var ret = fn.apply( thisArg, [ ele, i, this ] );
var ret = fn.apply( thisArg, [ this[i], i, this ] );

if( !ret ){
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/collection-data-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@
var includeLabels = options.includeLabels === undefined ? true : options.includeLabels;

// recalculate projections etc
cy_p.renderer.recalculateRenderedStyle( this );
if( styleEnabled ){
cy_p.renderer.recalculateRenderedStyle( this );
}

var x1 = Infinity;
var x2 = -Infinity;
Expand All @@ -464,7 +466,7 @@
for( var i = 0; i < eles.length; i++ ){
var ele = eles[i];
var _p = ele._private;
var display = _p.style['display'].value;
var display = styleEnabled ? _p.style['display'].value : 'element';
var isNode = _p.group === 'nodes';
var ex1, ex2, ey1, ey2, x, y;
var includedEle = false;
Expand Down
14 changes: 5 additions & 9 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
reg = reg || {};

if( reg && reg.cy ){
while( container.firstChild ){ // clean the container
container.removeChild( container.firstChild );
if( container ){
while( container.firstChild ){ // clean the container
container.removeChild( container.firstChild );
}
}

reg.cy.notify({ type: 'destroy' }); // destroy the renderer
Expand All @@ -43,7 +45,7 @@

var readies = reg.readies = reg.readies || [];

container._cyreg = reg; // make sure container assoc'd reg points to this cy
if( container ){ container._cyreg = reg; } // make sure container assoc'd reg points to this cy
reg.cy = cy;

var head = window !== undefined && container !== undefined && !opts.headless;
Expand Down Expand Up @@ -195,12 +197,6 @@
parEle.removeChild( domEle );
}

var domEle = this.container();
var parEle = domEle.parentNode;
if( parEle ){
parEle.removeChild( domEle );
}

return this;
},

Expand Down
27 changes: 24 additions & 3 deletions test/collection-building-and-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('Collection building and filtering', function(){
cytoscape({
elements: {
nodes: [
{ data: { id: 'n1', val: 1 } },
{ data: { id: 'n2', val: 2 } },
{ data: { id: 'n3', val: 3 } }
{ data: { id: 'n1', val: 1, sortVal: 2 } },
{ data: { id: 'n2', val: 2, sortVal: 1 } },
{ data: { id: 'n3', val: 3, sortVal: 3 } }
],

edges: [
Expand Down Expand Up @@ -56,6 +56,27 @@ describe('Collection building and filtering', function(){

});

it('eles.stdFilter()', function(){
expect( cy.$('#n1, #n2').stdFilter(function( ele ){
return ele.id() === 'n1';
}).same(n1) ).to.be.true;

expect( cy.$('#n1, #n2').stdFilter(function( ele ){
return ele.id() === 'n1';
}).same(n1) ).to.be.true;
});

it('eles.sort()', function(){
var sorted = cy.nodes().sort(function(a, b){
return a.data('sortVal') - b.data('sortVal');
});

expect( sorted.length ).to.equal(3);
expect( sorted[0].same(n2) ).to.be.true;
expect( sorted[1].same(n1) ).to.be.true;
expect( sorted[2].same(n3) ).to.be.true;
});

it('eles.map()', function(){
var ids = [];
var nodes = cy.nodes();
Expand Down
37 changes: 37 additions & 0 deletions test/collection-comparison.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var expect = require('chai').expect;
var cytoscape = require('../build/cytoscape.js', cytoscape);
var $$ = cytoscape;

describe('Collection comparison', function(){

Expand Down Expand Up @@ -61,4 +62,40 @@ describe('Collection comparison', function(){
expect( cy.$('#n1, #n1n2').allAre('node') ).to.be.false;
});

it('eles.some()', function(){
expect( cy.edges().some(function( ele, i, eles ){
expect( $$.is.elementOrCollection(ele) ).to.be.true;
expect( $$.is.elementOrCollection(eles) ).to.be.true;
expect( $$.is.number(i) ).to.be.true;

return ele.data('source') === 'n1';
}) ).to.be.true;

expect( cy.edges().some(function( ele, i, eles ){
expect( $$.is.elementOrCollection(ele) ).to.be.true;
expect( $$.is.elementOrCollection(eles) ).to.be.true;
expect( $$.is.number(i) ).to.be.true;

return ele.data('source') === 'no-way-this-id-exists';
}) ).to.be.false;
});

it('eles.every()', function(){
expect( cy.edges().every(function( ele, i, eles ){
expect( $$.is.elementOrCollection(ele) ).to.be.true;
expect( $$.is.elementOrCollection(eles) ).to.be.true;
expect( $$.is.number(i) ).to.be.true;

return ele.data('source') === 'n1';
}) ).to.be.false;

expect( cy.edges().every(function( ele, i, eles ){
expect( $$.is.elementOrCollection(ele) ).to.be.true;
expect( $$.is.elementOrCollection(eles) ).to.be.true;
expect( $$.is.number(i) ).to.be.true;

return ele.isEdge();
}) ).to.be.true;
});

});
7 changes: 7 additions & 0 deletions test/collection-compound-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ describe('Collection compound nodes', function(){
expect( ancestors[1].same( n1 ) ).to.be.true;
});

it('nodes.orphans()', function(){
expect( cy.elements().orphans().same( n1 ) ).to.be.true;
});

it('nodes.nonorphans()', function(){
expect( cy.elements().nonorphans().same( n2.add(n3).add(n4) ) ).to.be.true;
});
});
Loading

0 comments on commit 7682ea5

Please sign in to comment.