diff --git a/types/cytoscape/cytoscape-tests.ts b/types/cytoscape/cytoscape-tests.ts
index 71e815208c..39be1cd0e7 100644
--- a/types/cytoscape/cytoscape-tests.ts
+++ b/types/cytoscape/cytoscape-tests.ts
@@ -1,6 +1,26 @@
'use strict';
-import cytoscape = require('cytoscape');
+// TODO: document all aliases as aliases, not as duplicates!
+
+const assert = (tag: boolean) => { if (!tag) throw new Error(); };
+const aliases = (...obj: Array<{}>) => { if (obj.slice(1).some((alias) => alias !== obj[0])) throw new Error(); };
+const events = (obj: any) => {
+ aliases(obj.on, obj.bind, obj.listen, obj.addListener);
+ aliases(obj.promiseOn, obj.pon);
+ aliases(obj.off, obj.unbind, obj.unlisten, obj.removeListener);
+ aliases(obj.emit, obj.trigger);
+};
+
+// definitions
+function oneOf(a: A, b: B, c: C, d: D, e: E): A | B | C | D | E;
+function oneOf(a: A, b: B, c: C, d: D): A | B | C | D;
+function oneOf(a: A, b: B, c: C): A | B | C;
+function oneOf(a: A, b: B): A | B;
+function oneOf(...array: T[]): T {
+ return array[0];
+}
+
+import cytoscape = require('cytoscape');
const parentCSS = {
'padding-top': '10px',
'padding-left': '10px',
@@ -68,7 +88,7 @@ const cy = cytoscape({
{ data: { id: 'eb', source: 'e', target: 'b' } }
]
},
-
+
// initial viewport state:
zoom: 1,
pan: { x: 0, y: 0 },
@@ -96,7 +116,7 @@ const cy = cytoscape({
motionBlurOpacity: 0.2,
wheelSensitivity: 1,
pixelRatio: 'auto',
-
+
layout: {
name: 'preset',
padding: 5
@@ -108,6 +128,42 @@ cy.on('zoom', (event) => {
cy.nodes('$node > node').style('opacity', 0);
}
});
+cy.off('zoom');
+events(cy);
+
+cy.add({ data: { id: 'g' }, position: {x: 200, y: 150} });
+cy.add([
+ { data: { id: 'h' }, position: {x: 250, y: 100} }
+]);
+const nodesBeforeDelete = cy.nodes();
+const edgesBeforeDelete = cy.edges();
+
+const removed = cy.remove('#g #h');
+cy.add(removed);
+const diffNodes = nodesBeforeDelete.diff(cy.nodes());
+const diffEdges = edgesBeforeDelete.diff(cy.edges());
+assert(diffNodes.left.size() === 0 && diffNodes.right.size() === 0 && diffNodes.both.size() === cy.nodes().size());
+assert(nodesBeforeDelete.same(cy.nodes()));
+assert(edgesBeforeDelete.same(cy.edges()));
+
+const gh = cy.collection().add(cy.$id('g')).union(cy.getElementById('h'));
+const gh2 = cy.$('#g #h');
+const gh3 = cy.nodes('#g #h');
+assert(gh2.same(gh));
+assert(gh3.same(gh));
+assert(gh.same(removed));
+
+assert(cy.container() === null); // headless mode!
+
+cy.center();
+cy.center(gh);
+aliases(cy.center, cy.centre);
+
+cy.fit(cy.$('#a #b #h'));
+
+const {x1, y1, x2, y2, w, h} = cy.extent();
+
+aliases(cy.resize, cy.invalidateDimensions);
cy.animate({
fit: {
@@ -117,8 +173,323 @@ cy.animate({
duration: 500
});
-const node = cy.nodes()[0];
cy.animate({
- center: {eles: node},
+ center: {eles: cy.nodes()[0]},
duration: 500
});
+
+const anim = cy.animation({
+ zoom: {
+ level: 1,
+ position: {x: 0, y: 0}
+ },
+ pan: {x: 100, y: 100},
+ duration: 100,
+ easing: 'ease'
+});
+cy.stop(true, true);
+anim.play();
+assert(anim.playing());
+anim.progress(anim.progress() + 50);
+anim.time(anim.time() - 50);
+anim.stop();
+
+aliases(cy.layout, cy.createLayout, cy.makeLayout);
+
+// Preconfigured data for layouts (as it could be passed)
+const boundingBox = oneOf({x1: 0, x2: 100, y1: 0, y2: 100}, {x1: 0, w: 100, y1: 0, h: 100});
+const positions = oneOf({a: {x: 100, y: 100}}, (node: cytoscape.NodeCollection): cytoscape.Position => ({x: 100, y: 100}));
+
+// TODO: uncomment after we have the way to add layout options properties from extensions
+// const layouts = [
+// cy.layout({
+// name: 'null',
+// ready: () => {},
+// stop: () => {}
+// }),
+// cy.layout({
+// name: 'random',
+// fit: true,
+// padding: 30,
+// boundingBox,
+// animate: false,
+// animationDuration: 500,
+// animationEasing: 'ease-in',
+// animateFilter: (node, i) => true,
+// transform: (node, position) => position
+// }),
+// cy.layout({
+// name: 'preset',
+// positions,
+// zoom: 1,
+// pan: {x: 100, y: 100},
+// fit: false,
+// padding: 30,
+// animate: false,
+// animationDuration: 500,
+// animationEasing: 'ease-out',
+// animateFilter: (node, i) => true,
+// transform: (node, position) => position
+// }),
+// cy.layout({
+// name: 'grid',
+// fit: true,
+// padding: 30,
+// boundingBox,
+// avoidOverlap: true,
+// avoidOverlapPadding: 10,
+// nodeDimensionsIncludeLabels: false,
+// spacingFactor: oneOf(1, undefined),
+// condense: false,
+// rows: oneOf(10, undefined),
+// cols: oneOf(10, undefined),
+// position: (node) => ({ row: 1, col: 1 }),
+// sort: (a, b) => 1,
+// animate: false,
+// animationDuration: 500,
+// animationEasing: 'ease-in-out',
+// animateFilter: (node, i) => true,
+// transform: (node, position) => position
+// }),
+// cy.layout({
+// name: 'circle',
+// fit: true,
+// padding: 30,
+// boundingBox,
+// avoidOverlap: true,
+// nodeDimensionsIncludeLabels: false,
+// spacingFactor: oneOf(1, undefined),
+// radius: oneOf(1, undefined),
+// startAngle: 3 / 2 * Math.PI,
+// sweep: oneOf(6, undefined),
+// clockwise: true,
+// sort: (a, b) => 1,
+// animate: false,
+// animationDuration: 500,
+// animationEasing: 'ease-in-sine',
+// animateFilter: (node, i) => true,
+// transform: (node, position) => position
+// }),
+// cy.layout({
+// name: 'concentric',
+// fit: true,
+// padding: 30,
+// startAngle: 3 / 2 * Math.PI,
+// sweep: oneOf(6, undefined),
+// clockwise: true,
+// equidistant: false,
+// minNodeSpacing: 10,
+// boundingBox,
+// avoidOverlap: true,
+// nodeDimensionsIncludeLabels: false,
+// height: oneOf(500, undefined),
+// width: oneOf(500, undefined),
+// spacingFactor: oneOf(1, undefined),
+// concentric: (node) => 1,
+// levelWidth: (nodes) => 1,
+// animate: false,
+// animationDuration: 500,
+// animationEasing: 'ease-out-sine',
+// animateFilter: (node, i) => true,
+// transform: (node, position) => position
+// }),
+// cy.layout({
+// name: 'breadthfirst',
+// fit: true,
+// directed: false,
+// padding: 30,
+// circle: false,
+// spacingFactor: 1.75,
+// boundingBox,
+// avoidOverlap: true,
+// nodeDimensionsIncludeLabels: false,
+// maximalAdjustments: 0,
+// animate: false,
+// animationDuration: 500,
+// animationEasing: 'ease-in-out-sine',
+// animateFilter: (node, i) => true,
+// transform: (node, position) => position
+// }),
+// cy.layout({
+// name: 'cose',
+// ready: () => {},
+// stop: () => {},
+// animate: oneOf(true, false, 'end'),
+// animationEasing: oneOf('ease-in-quad', undefined),
+// animationDuration: oneOf(500, undefined),
+// animateFilter: function ( node, i ){ return true; },
+// animationThreshold: 250,
+// refresh: 20,
+// fit: true,
+// padding: 30,
+// boundingBox: undefined,
+// nodeDimensionsIncludeLabels: false,
+// randomize: false,
+// componentSpacing: 40,
+// nodeRepulsion: (node) => 2048,
+// nodeOverlap: 4,
+// idealEdgeLength: (edge) => 32,
+// edgeElasticity: (edge) => 32,
+// nestingFactor: 1.2,
+// gravity: 1,
+// numIter: 1000,
+// initialTemp: 1000,
+// coolingFactor: 0.99,
+// minTemp: 1.0,
+// weaver: false
+// })
+// ];
+// const lay = layouts[0];
+// aliases(lay.run, lay.start);
+// events(lay);
+// layouts.map(layout => {
+// layout.run();
+// layout.stop();
+// });
+
+// TODO: cy.style
+
+cy.png({
+ output: oneOf('base64uri', 'base64', 'blob', undefined),
+ bg: oneOf('#ffffff', undefined),
+ full: true,
+ scale: 2,
+ maxWidth: 100,
+ maxHeight: 100
+});
+aliases(cy.jpg, cy.jpeg);
+cy.jpg({
+ output: oneOf('base64uri', 'base64', 'blob', undefined),
+ bg: oneOf('#ffffff', undefined),
+ full: true,
+ scale: 2,
+ maxWidth: 100,
+ maxHeight: 100,
+ quality: 0.5
+});
+cy.json(cy.json());
+
+// Types possible to call methods
+const ele = oneOf(cy.nodes()[0], cy.edges()[0]);
+const eles = cy.elements();
+const node = cy.nodes()[0];
+const nodes = cy.nodes();
+const edge = cy.edges()[0];
+const edges = cy.edges();
+
+assert(ele.cy() === cy);
+eles.remove();
+assert(eles.removed());
+assert(!eles.inside());
+eles.restore();
+
+([ele, eles, node, nodes, edge, edges] as cytoscape.CollectionReturnValue[]).forEach((elem) => {
+ aliases(elem.clone, elem.copy);
+ events(elem);
+ aliases(elem.data, elem.attr);
+ aliases(elem.removeData, elem.removeAttr);
+});
+// TODO: tests for data flow
+
+const loops = oneOf(true, false);
+node.degree(loops); node.indegree(loops); node.outdegree(loops);
+nodes.totalDegree(loops); nodes.minDegree(loops); nodes.maxDegree(loops);
+nodes.minIndegree(loops); nodes.maxIndegree(loops); nodes.minOutdegree(loops); nodes.maxOutdegree(loops);
+
+// tslint:disable-next-line:ban-types
+const getsetPos = (func: T): T => {
+ func('x', func('x'));
+ func(func());
+ func({x: 100, y: 100});
+ return func;
+};
+
+aliases(node.modelPosition, node.point, node.position);
+getsetPos(node.position);
+
+nodes.shift('x', 100);
+nodes.shift({x: -100, y: 0});
+
+aliases(nodes.modelPositions, nodes.positions, nodes.points);
+nodes.positions((node, i) => Object.assign(node.position(), {x: node.position('x') + i}));
+
+aliases(node.renderedPosition, node.renderedPoint);
+getsetPos(node.renderedPoint);
+
+// TODO: tests for compound nodes (relativePosition, in particular)
+
+const sizes: number[] = [
+ ele.width(), ele.outerWidth(), ele.renderedWidth(), ele.renderedOuterWidth(),
+ ele.height(), ele.outerHeight(), ele.renderedHeight(), ele.renderedOuterHeight()
+];
+
+aliases(eles.boundingBox, eles.boundingbox);
+aliases(eles.renderedBoundingBox, eles.renderedBoundingbox);
+
+const flags: boolean[] = [
+ node.grabbed(), node.grabbable(), node.locked(), ele.active(),
+];
+
+const edgePoints: cytoscape.Position[] = [
+ ...edge.controlPoints(), ...edge.segmentPoints(), edge.sourceEndpoint(), edge.targetEndpoint(), edge.midpoint()
+];
+
+aliases(eles.layout, eles.createLayout, eles.makeLayout);
+const layout = eles.layout({name: 'random'}).run();
+
+eles.select();
+assert(ele.selected()); // as we selected all, and this too
+aliases(eles.unselect, eles.deselect);
+eles.selectify();
+assert(ele.selectable());
+eles.unselectify();
+
+eles.addClass('test');
+eles.toggleClass('test', oneOf(true, false, undefined));
+eles.removeClass('test');
+eles.classes(oneOf('test', undefined));
+eles.flashClass('test flash', oneOf(1000, undefined));
+assert(ele.hasClass('test'));
+
+eles.style('background-color', 'green');
+Object.keys(eles.style()).map(key => eles.style(key));
+eles.style(eles.style());
+aliases(eles.style, eles.css);
+aliases(ele.renderedCss, ele.renderedStyle);
+
+eles.anySame(nodes);
+aliases(eles.contains, eles.has);
+aliases(eles.allAreNeighbors, eles.allAreNeighbours);
+eles.is('#g');
+eles.allAre('#g');
+eles.some((el, i, els) => true);
+eles.every((el, i, els) => true);
+
+aliases(eles.forEach, eles.each);
+const selected: cytoscape.SingularElementArgument[] = [eles.eq(0), eles.first(), eles.last()];
+const collSel = cy.collection(selected);
+const selectedNodes: cytoscape.NodeSingular[] = [nodes.eq(0), nodes.first(), nodes.last()];
+const collNodes = cy.collection(selectedNodes);
+const selectedEdges: cytoscape.EdgeSingular[] = [edges.eq(0), edges.first(), edges.last()];
+eles.slice(0, -1);
+eles.toArray();
+
+aliases(eles.getElementById, eles.$id);
+aliases(eles.union, eles.add, eles.or, eles.u, eles['+'], eles['|']);
+aliases(eles.difference, eles.not, eles.subtract, eles.relativeComplement, eles['\\'], eles['!'], eles['-']);
+aliases(eles.absoluteComplement, eles.abscomp, eles.complement);
+aliases(eles.intersection, eles.intersect, eles.and, eles.n, eles['&'], eles['.']);
+aliases(eles.symmetricDifference, eles.symdiff, eles.xor, eles['^'], eles['(+)'], eles['(-)']);
+cy.collection([nodes[0]]).union(nodes[1]).union(eles.$id('g'));
+eles.difference(collNodes).abscomp().intersection(collSel).symdiff(collNodes);
+const diff = collSel.diff(collNodes);
+cy.collection().merge(diff.left).merge(diff.right).merge(diff.both).unmerge(collSel).filter((ele, i, eles) => true);
+
+eles.sort((a, b) => 1).map((ele, i, eles) => [i, ele]);
+eles.reduce((prev, ele, i, eles) => [...prev, [ele, i]], []).concat(['finish']);
+const min = eles.min((ele, i, eles) => ele.id.length + i); min.ele.scratch('min', min.value);
+const max = eles.max((ele, i, eles) => ele.id.length + i); max.ele.scratch('max', max.value);
+
+// TODO: traversing (need to actively check the nodes/edeges distinction)
+// TODO: algorithms
+// TODO: compound nodes (there aren't any in current test case)
diff --git a/types/cytoscape/index.d.ts b/types/cytoscape/index.d.ts
index e85041861a..95573226b1 100644
--- a/types/cytoscape/index.d.ts
+++ b/types/cytoscape/index.d.ts
@@ -1,4 +1,4 @@
-// Type definitions for Cytoscape.js 3.1
+// Type definitions for Cytoscape.js 3.2
// Project: http://js.cytoscape.org/
// Definitions by: Fabian Schmidt and Fred Eisele
// Shenghan Gao
@@ -9,7 +9,7 @@
//
// Translation from Objects in help to Typescript interface.
// http://js.cytoscape.org/#notation/functions
-// TypeScript Version: 2.2
+// TypeScript Version: 2.3
/**
* cy --> Cy.Core
@@ -361,7 +361,7 @@ declare namespace cytoscape {
*
* The default value is 1.
*/
- pixelRatio?: number;
+ pixelRatio?: number | 'auto';
}
/**
@@ -386,35 +386,42 @@ declare namespace cytoscape {
/**
* Add elements to the graph and return them.
*/
- add(eles: ElementDefinition | ElementDefinition[] | Collection): CollectionElements;
+ add(eles: ElementDefinition | ElementDefinition[] | CollectionArgument): CollectionReturnValue;
/**
* Remove elements in collecion or match the selector from the graph and return them.
*/
- remove(eles: Collection | Selector): CollectionElements;
+ remove(eles: CollectionArgument | Selector): CollectionReturnValue;
/**
* Get a collection from elements in the graph matching the specified selector or from an array of elements.
* If no parameter specified, an empty collection will be returned
*/
- collection(eles?: Selector | CollectionElements[]): CollectionElements;
+ collection(eles?: Selector | CollectionArgument[]): CollectionReturnValue;
/**
* Get an element from its ID in a very performant way.
+ * http://js.cytoscape.org/#cy.getElementById
*/
- getElementById(id: string): CollectionElements;
+ getElementById(id: string): CollectionReturnValue;
+
+ /**
+ * Get an element from its ID in a very performant way.
+ * http://js.cytoscape.org/#cy.getElementById
+ */
+ $id(id: string): CollectionReturnValue;
/**
* Get elements in the graph matching the specified selector.
* http://js.cytoscape.org/#cy.$
*/
- $(selector: Selector): CollectionElements;
+ $(selector: Selector): CollectionReturnValue;
/**
* Get elements in the graph matching the specified selector.
* http://js.cytoscape.org/#cy.$
*/
- elements(selector?: Selector): CollectionElements;
+ elements(selector?: Selector): CollectionReturnValue;
/**
* Get nodes in the graph matching the specified selector.
@@ -428,7 +435,7 @@ declare namespace cytoscape {
/**
* Get elements in the graph matching the specified selector or filter function.
*/
- filter(selector: Selector | ((ele: Singular, i: number, eles: CollectionElements) => boolean)): CollectionElements;
+ filter(selector: Selector | ((ele: Singular, i: number, eles: CollectionArgument) => boolean)): CollectionReturnValue;
/**
* Allow for manipulation of elements without triggering multiple style calculations or multiple redraws.
@@ -599,14 +606,20 @@ declare namespace cytoscape {
ready(fn: EventHandler): void;
}
- interface ZoomOptions {
- /** The zoom level to set. */
- level: number;
+ interface ZoomOptionsModel {
/** The position about which to zoom. */
position: Position;
+ }
+ interface ZoomOptionsRendered {
/** The rendered position about which to zoom. */
renderedPosition: Position;
}
+ interface ZoomOptionsLevel {
+ /** The zoom level to set. */
+ level: number;
+ }
+ type ZoomOptions = ZoomOptionsLevel & (ZoomOptionsModel | ZoomOptionsRendered);
+
/**
* http://js.cytoscape.org/#core/viewport-manipulation
*/
@@ -615,14 +628,21 @@ declare namespace cytoscape {
* Get the HTML DOM element in which the graph is visualised.
* A null value is returned if the Core is headless.
*/
- container(): any;
+ container(): Element | null;
/**
* Pan the graph to the centre of a collection.
*
* @param eles The collection to centre upon.
*/
- center(eles?: Collection): CollectionElements;
+ center(eles?: CollectionArgument): this;
+
+ /**
+ * Pan the graph to the centre of a collection.
+ *
+ * @param eles The collection to centre upon.
+ */
+ centre(eles?: CollectionArgument): this;
/**
* Pan and zooms the graph to fit to a collection.
@@ -631,13 +651,13 @@ declare namespace cytoscape {
* @param eles [optional] The collection to fit to.
* @param padding [optional] An amount of padding (in pixels) to have around the graph
*/
- fit(eles?: Collection, padding?: number): CollectionElements;
+ fit(eles?: CollectionArgument, padding?: number): this;
/**
* Reset the graph to the default zoom level and panning position.
* http://js.cytoscape.org/#cy.reset
*/
- reset(): CollectionElements;
+ reset(): this;
/**
* Get the panning position of the graph.
@@ -651,7 +671,7 @@ declare namespace cytoscape {
*
* @param renderedPosition The rendered position to pan the graph to.
*/
- pan(renderedPosition?: Position): void;
+ pan(renderedPosition?: Position): this;
/**
* Relatively pan the graph by a specified rendered position vector.
@@ -659,7 +679,7 @@ declare namespace cytoscape {
*
* @param renderedPosition The rendered position vector to pan the graph by.
*/
- panBy(renderedPosition: Position): void;
+ panBy(renderedPosition: Position): this;
/**
* Get whether panning is enabled.
@@ -867,7 +887,8 @@ declare namespace cytoscape {
* there is no resize or style event for arbitrary DOM elements.
* http://js.cytoscape.org/#cy.resize
*/
- resize(): CollectionElements;
+ resize(): this;
+ invalidateDimensions(): this;
}
/**
@@ -875,15 +896,15 @@ declare namespace cytoscape {
*
*/
interface AnimationFitOptions {
- eles: CollectionElements | Selector; // to which the viewport will be fitted.
+ eles: CollectionArgument | Selector; // to which the viewport will be fitted.
padding: number; // Padding to use with the fitting.
}
interface CenterOptions {
- eles: CollectionElements | Selector; // to which the viewport will be selected.
+ eles: CollectionArgument | Selector; // to which the viewport will be selected.
}
- interface AnimateOptionsCommon {
+ interface AnimationOptions {
/** A zoom level to which the graph will be animated. */
- zoom?: number;
+ zoom?: ZoomOptions;
/** A panning position to which the graph will be animated. */
pan?: Position;
/** A relative panning position to which the graph will be animated. */
@@ -892,11 +913,13 @@ declare namespace cytoscape {
fit?: AnimationFitOptions;
/** An object containing centring options from which the graph will be animated. */
center?: CenterOptions;
+ /** easing - A transition-timing-function easing style string that shapes the animation progress curve. */
+ easing?: string; // TODO: explicit type
/** duration - The duration of the animation in milliseconds. */
duration?: number;
}
- interface AnimateOptions extends AnimateOptionsCommon {
+ interface AnimateOptions extends AnimationOptions {
/** queue - A boolean indicating whether to queue the animation. */
queue?: boolean;
/** complete - A function to call when the animation is done. */
@@ -904,14 +927,6 @@ declare namespace cytoscape {
/** step - A function to call each time the animation steps. */
step?(): void;
}
- interface AnimationOptions extends AnimateOptionsCommon {
- /** queue - A transition-timing-function easing style string that shapes the animation progress curve. */
- easing?: boolean;
- /** complete - A function to call when the animation is done. */
- complete?(): void;
- /** step - A function to call each time the animation steps. */
- step?(): void;
- }
interface CoreAnimation {
/**
@@ -993,6 +1008,7 @@ declare namespace cytoscape {
* An analogue to make a layout on a subset of the graph exists as eles.makeLayout().
*/
makeLayout(options: LayoutOptions): LayoutManipulation;
+ createLayout(options: LayoutOptions): LayoutManipulation;
}
/**
@@ -1080,17 +1096,18 @@ declare namespace cytoscape {
/**
* Export the current graph view as a JPG image in Base64 representation.
*/
- jpg(options?: ExportOptions): string;
+ jpg(options?: ExportJpgOptions): string;
/**
* Export the current graph view as a JPG image in Base64 representation.
*/
- jpeg(options?: ExportOptions): string;
+ jpeg(options?: ExportJpgOptions): string;
/**
* Export the graph as JSON, the same format used at initialisation.
*/
- json(): string;
+ json(): object;
+ json(json: object): this;
}
/**
@@ -1100,13 +1117,14 @@ declare namespace cytoscape {
* The input can be any element (node and edge) collection.
* http://js.cytoscape.org/#collection
*/
- interface Collection extends Singular,
+ interface Collection
+ extends Singular,
CollectionGraphManipulation, CollectionEvents,
CollectionData, CollectionPosition,
CollectionLayout,
CollectionSelection, CollectionStyle, CollectionAnimation,
- CollectionComparision, CollectionIteration,
- CollectionBuildingUnion, CollectionAlgorithms { }
+ CollectionComparision, CollectionIteration,
+ CollectionBuildingFiltering, CollectionAlgorithms { }
/**
* ele --> Cy.Singular
@@ -1127,7 +1145,8 @@ declare namespace cytoscape {
/**
* The output is a collection of node and edge elements OR single element.
*/
- type CollectionElements = EdgeCollection | NodeCollection | SingularElement;
+ type CollectionArgument = EdgeCollection | NodeCollection | SingularElementArgument;
+ type CollectionReturnValue = EdgeCollection & NodeCollection & SingularElementReturnValue;
/**
* edges -> Cy.EdgeCollection
@@ -1135,7 +1154,7 @@ declare namespace cytoscape {
*
* The output is a collection of edge elements OR single edge.
*/
- interface EdgeCollection extends Collection, EdgeSingular,
+ interface EdgeCollection extends Collection, EdgeSingular,
EdgeCollectionTraversing { }
/**
* nodes -> Cy.NodeCollection
@@ -1143,19 +1162,18 @@ declare namespace cytoscape {
*
* The output is a collection of node elements OR single node.
*/
- interface NodeCollection extends Collection, NodeSingular,
+ interface NodeCollection extends Collection, NodeSingular,
NodeCollectionMetadata, NodeCollectionPosition, NodeCollectionTraversing,
NodeCollectionCompound { }
- interface SingularElement extends EdgeSingular, NodeSingular {
- // Intentionally empty.
- }
+ type SingularElementArgument = EdgeSingular | NodeSingular;
+ type SingularElementReturnValue = EdgeSingular & NodeSingular;
/**
* edge --> Cy.EdgeSingular
* a collection of a single edge
*/
interface EdgeSingular extends Singular,
- EdgeSingularData, EdgeSingularTraversing { }
+ EdgeSingularData, EdgeSingularPoints, EdgeSingularTraversing { }
/**
* node --> Cy.NodeSingular
@@ -1172,24 +1190,24 @@ declare namespace cytoscape {
* Remove the elements from the graph.
* http://js.cytoscape.org/#eles.remove
*/
- remove(): CollectionElements;
+ remove(): CollectionReturnValue;
/**
* Put removed elements back into the graph.
* http://js.cytoscape.org/#eles.restore
*/
- restore(): CollectionElements;
+ restore(): CollectionReturnValue;
/**
* Get a new collection containing clones (i.e. copies) of the elements in the calling collection.
* http://js.cytoscape.org/#eles.clone
*/
- clone(): CollectionElements;
+ clone(): CollectionReturnValue;
/**
* Get a new collection containing clones (i.e. copies) of the elements in the calling collection.
* http://js.cytoscape.org/#eles.clone
*/
- copy(): CollectionElements;
+ copy(): CollectionReturnValue;
/**
* Effectively move edges to different nodes. The modified (actually new) elements are returned.
@@ -1207,6 +1225,10 @@ declare namespace cytoscape {
* http://js.cytoscape.org/#collection/graph-manipulation
*/
interface SingularGraphManipulation {
+ /**
+ * Get the core instance that owns the element.
+ */
+ cy(): Core;
/**
* Get whether the element has been removed from the graph.
* http://js.cytoscape.org/#ele.removed
@@ -1279,8 +1301,8 @@ declare namespace cytoscape {
* http://js.cytoscape.org/#eles.removeData
* @param names A space-separated list of fields to delete.
*/
- removeData(names?: string): CollectionElements;
- removeAttr(names?: string): CollectionElements;
+ removeData(names?: string): CollectionReturnValue;
+ removeAttr(names?: string): CollectionReturnValue;
/**
* Get an array of the plain JavaScript object
@@ -1313,6 +1335,22 @@ declare namespace cytoscape {
* @param obj The object containing name- value pairs to update data fields.
*/
data(obj: any): void;
+ /**
+ * Get a particular data field for the element.
+ * @param name The name of the field to get.
+ */
+ attr(name?: string): any;
+ /**
+ * Set a particular data field for the element.
+ * @param name The name of the field to set.
+ * @param value The value to set for the field.
+ */
+ attr(name: string, value: any): void;
+ /**
+ * Update multiple data fields at once via an object.
+ * @param obj The object containing name- value pairs to update data fields.
+ */
+ attr(obj: any): void;
/**
* Get or set the scratchpad at a particular namespace,
@@ -1461,17 +1499,77 @@ declare namespace cytoscape {
* Get the (model) position of a node.
*/
position(): Position;
+ /**
+ * Get the value of a specified position dimension.
+ * @param dimension The position dimension to set.
+ * @param value The value to set to the dimension.
+ */
+ position(dimension: PositionDimension): number;
/**
* Set the value of a specified position dimension.
* @param dimension The position dimension to set.
* @param value The value to set to the dimension.
*/
- position(dimension: PositionDimension, value?: Position): void;
+ position(dimension: PositionDimension, value: number): this;
/**
* Set the position using name-value pairs in the specified object.
* @param pos An object specifying name-value pairs representing dimensions to set.
*/
- position(pos: Position): void;
+ position(pos: Position): this;
+ /**
+ * Get the (model) position of a node.
+ */
+ modelPosition(): Position;
+ /**
+ * Get the value of a specified position dimension.
+ * @param dimension The position dimension to set.
+ * @param value The value to set to the dimension.
+ */
+ modelPosition(dimension: PositionDimension): number;
+ /**
+ * Set the value of a specified position dimension.
+ * @param dimension The position dimension to set.
+ * @param value The value to set to the dimension.
+ */
+ modelPosition(dimension: PositionDimension, value: number): this;
+ /**
+ * Set the position using name-value pairs in the specified object.
+ * @param pos An object specifying name-value pairs representing dimensions to set.
+ */
+ modelPosition(pos: Position): this;
+ /**
+ * Get the (model) position of a node.
+ */
+ point(): Position;
+ /**
+ * Get the value of a specified position dimension.
+ * @param dimension The position dimension to set.
+ * @param value The value to set to the dimension.
+ */
+ point(dimension: PositionDimension): number;
+ /**
+ * Set the value of a specified position dimension.
+ * @param dimension The position dimension to set.
+ * @param value The value to set to the dimension.
+ */
+ point(dimension: PositionDimension, value: number): this;
+ /**
+ * Set the position using name-value pairs in the specified object.
+ * @param pos An object specifying name-value pairs representing dimensions to set.
+ */
+ point(pos: Position): this;
+
+ /**
+ * Shift the positions of the nodes by a given model position vector.
+ * @param dimension The position dimension to shift.
+ * @param value The value to shift the dimension.
+ */
+ shift(dimension: PositionDimension, value?: number): this;
+ /**
+ * Shift the positions of the nodes by a given model position vector.
+ * @param pos An object specifying name-value pairs representing dimensions to shift.
+ */
+ shift(pos: Position): this;
/**
* Get or set the rendered (on-screen) position of a node.
@@ -1542,8 +1640,8 @@ declare namespace cytoscape {
* @param ele The element being iterated over for which the function should return a position to set.
* @param ix The index of the element when iterating over the elements in the collection.
*/
- type ElementPositionFunction = (ele: CollectionElements, ix: number) => void;
- type ElementCollectionFunction = (ele: CollectionElements, ix: number, eles: CollectionElements) => void;
+ type ElementPositionFunction = (ele: NodeSingular, ix: number) => void;
+ type ElementCollectionFunction = (ele: NodeSingular, ix: number, eles: CollectionArgument) => void;
/**
* http://js.cytoscape.org/#collection/position--dimensions
@@ -1556,9 +1654,7 @@ declare namespace cytoscape {
* http://js.cytoscape.org/#nodes.positions
*/
positions(handler: ElementPositionFunction | Position): void;
-
modelPositions(handler: ElementPositionFunction | Position): void;
-
points(handler: ElementPositionFunction | Position): void;
/**
@@ -1647,11 +1743,13 @@ declare namespace cytoscape {
* http://js.cytoscape.org/#eles.boundingBox
*/
boundingBox(options: BoundingBoxOptions): BoundingBox12 | BoundingBoxWH;
+ boundingbox(options: BoundingBoxOptions): BoundingBox12 | BoundingBoxWH;
/**
* Get the bounding box of the elements in rendered coordinates.
* @param options An object containing options for the function.
*/
renderedBoundingBox(options: BoundingBoxOptions): BoundingBox12 | BoundingBoxWH;
+ renderedBoundingbox(options: BoundingBoxOptions): BoundingBox12 | BoundingBoxWH;
}
/**
@@ -1668,9 +1766,9 @@ declare namespace cytoscape {
*
* @param options The layout options.
*/
- layout(options: LayoutOptions): CollectionElements;
- makeLayout(options: LayoutOptions): CoreLayout;
- createLayout(options: LayoutOptions): CoreLayout;
+ layout(options: LayoutOptions): LayoutManipulation;
+ makeLayout(options: LayoutOptions): LayoutManipulation;
+ createLayout(options: LayoutOptions): LayoutManipulation;
}
/**
@@ -1684,7 +1782,7 @@ declare namespace cytoscape {
// easing of animation, if enabled
animationEasing?: number;
// collection of elements involved in the layout; set by cy.layout() or eles.layout()
- eles: CollectionElements;
+ eles: CollectionArgument;
// whether to fit the viewport to the graph
fit?: boolean;
// padding to leave between graph and viewport
@@ -1811,11 +1909,50 @@ declare namespace cytoscape {
flashClass(classes: ClassNames, duration?: number): void;
/**
- * Get or set a particular style property value.
- * @param name The name of the visual style property to get.
+ * Set a particular style property value.
+ * @param name The name of the visual style property to set.
* @param value The value to which the property is set.
*/
- style(name?: string, value?: any): any;
+ style(name: string, value: any): this;
+ /**
+ * Get a particular style property value.
+ * @param name The name of the visual style property to get.
+ */
+ style(name: string): any;
+ /**
+ * Set several particular style property values.
+ * @param obj An object of style property name-value pairs to set.
+ */
+ style(obj: object): this;
+ /**
+ * Get a name-value pair object containing visual style properties and their values for the element.
+ */
+ style(): {[index: string]: any};
+ /**
+ * Set a particular style property value.
+ * @param name The name of the visual style property to set.
+ * @param value The value to which the property is set.
+ */
+ css(name: string, value: any): this;
+ /**
+ * Get a particular style property value.
+ * @param name The name of the visual style property to get.
+ */
+ css(name: string): any;
+ /**
+ * Set several particular style property values.
+ * @param obj An object of style property name-value pairs to set.
+ */
+ css(obj: object): this;
+ /**
+ * Get a name-value pair object containing visual style properties and their values for the element.
+ */
+ css(): {[index: string]: any};
+ /**
+ * Remove all or specific style overrides.
+ * @param names A space-separated list of property names to remove overrides
+ */
+ removeStyle(names?: string): this;
}
/**
@@ -1977,27 +2114,36 @@ declare namespace cytoscape {
*
* @param eles The other elements to compare to.
*/
- same(eles: Collection): boolean;
+ same(eles: CollectionArgument): boolean;
/**
* Determine whether this collection contains any of the same elements as another collection.
*
* @param eles The other elements to compare to.
*/
- anySame(eles: Collection): boolean;
+ anySame(eles: CollectionArgument): boolean;
+
+ /**
+ * Determine whether this collection contains all of the elements of another collection.
+ */
+ contains(eles: CollectionArgument): boolean;
+ /**
+ * Determine whether this collection contains all of the elements of another collection.
+ */
+ has(eles: CollectionArgument): boolean;
/**
* Determine whether all elements in the specified collection are in the neighbourhood of the calling collection.
*
* @param eles The other elements to compare to.
*/
- allAreNeighbors(eles: Collection): boolean;
+ allAreNeighbors(eles: CollectionArgument): boolean;
/**
* Determine whether all elements in the specified collection are in the neighbourhood of the calling collection.
*
* @param eles The other elements to compare to.
*/
- allAreNeighbours(eles: Collection): boolean;
+ allAreNeighbours(eles: CollectionArgument): boolean;
/**
* Determine whether any element in this collection matches a selector.
@@ -2021,7 +2167,7 @@ declare namespace cytoscape {
* eles - The collection of elements being tested.
* @param thisArg [optional] The value for this within the test function.
*/
- some(test: (ele: CollectionElements, i: number, eles: CollectionElements) => boolean, thisArg?: any): boolean;
+ some(test: (ele: CollectionArgument, i: number, eles: CollectionArgument) => boolean, thisArg?: any): boolean;
/**
* Determine whether all elements in this collection satisfy the specified test function.
@@ -2032,13 +2178,13 @@ declare namespace cytoscape {
* eles - The collection of elements being tested.
* @param thisArg [optional] The value for this within the test function.
*/
- every(test: (ele: CollectionElements, i: number, eles: CollectionElements) => boolean, thisArg?: any): boolean;
+ every(test: (ele: CollectionArgument, i: number, eles: CollectionArgument) => boolean, thisArg?: any): boolean;
}
/**
* http://js.cytoscape.org/#collection/iteration
*/
- interface CollectionIteration {
+ interface CollectionIteration {
/**
* Get the number of elements in the collection.
*/
@@ -2070,8 +2216,8 @@ declare namespace cytoscape {
* eles - The collection of elements being iterated.
* @param thisArg [optional] The value for this within the iterating function.
*/
- each(each: (ele: CollectionElements, i: number, eles: CollectionElements) => void | boolean, thisArg?: any): void;
- forEach(each: (ele: CollectionElements, i: number, eles: CollectionElements) => void | boolean, thisArg?: any): void;
+ each(each: (ele: TIn, i: number, eles: this) => void | boolean, thisArg?: any): void;
+ forEach(each: (ele: TIn, i: number, eles: this) => void | boolean, thisArg?: any): void;
/**
* Get an element at a particular index in the collection.
@@ -2080,21 +2226,21 @@ declare namespace cytoscape {
*
* @param index The index of the element to get.
*/
- eq(index: number): CollectionElements;
+ eq(index: number): TOut;
/**
* Get an element at a particular index in the collection.
*
* @param index The index of the element to get.
*/
- [index: number]: CollectionElements;
+ [index: number]: TOut;
/**
* Get the first element in the collection.
*/
- first(): CollectionElements;
+ first(): TOut;
/**
* Get the last element in the collection.
*/
- last(): CollectionElements;
+ last(): TOut;
/**
* Get a subset of the elements in the collection based on specified indices.
@@ -2106,7 +2252,12 @@ declare namespace cytoscape {
* If omitted, all elements from the start position and to the end of the array will be selected.
* Use negative numbers to select from the end of an array.
*/
- slice(start?: number, end?: number): CollectionElements;
+ slice(start?: number, end?: number): this;
+
+ /**
+ * Get the collection as an array, maintaining the order of the elements.
+ */
+ toArray(): SingularElementReturnValue[];
}
/**
@@ -2118,7 +2269,7 @@ declare namespace cytoscape {
* @param eles The elements or array of elements to add or elements in the graph matching the selector.
* http://js.cytoscape.org/#eles.union
*/
- type CollectionBuildingUnionFunc = (eles: Collection | Collection[] | Selector) => CollectionElements;
+ type CollectionBuildingUnionFunc = (eles: CollectionArgument | CollectionArgument[] | Selector) => CollectionReturnValue;
/**
* Get a new collection, resulting from the collection without some specified elements.
@@ -2126,7 +2277,7 @@ declare namespace cytoscape {
* @param eles The elements that will not be in the resultant collection.
* Elements from the calling collection matching this selector will not be in the resultant collection.
*/
- type CollectionBuildingDifferenceFunc = (eles: Collection | Selector) => CollectionElements;
+ type CollectionBuildingDifferenceFunc = (eles: CollectionArgument | Selector) => CollectionReturnValue;
/**
* Get the elements in both this collection and another specified collection.
@@ -2135,7 +2286,7 @@ declare namespace cytoscape {
* A selector representing the elements to intersect with.
* All elements in the graph matching the selector are used as the passed collection.
*/
- type CollectionBuildingIntersectionFunc = (eles: Collection | Selector) => CollectionElements;
+ type CollectionBuildingIntersectionFunc = (eles: CollectionArgument | Selector) => CollectionReturnValue;
/**
* Get the elements that are in the calling collection or the passed collection but not in both.
@@ -2144,40 +2295,52 @@ declare namespace cytoscape {
* A selector representing the elements to apply the symmetric difference with.
* All elements in the graph matching the selector are used as the passed collection.
*/
- type CollectionSymmetricDifferenceFunc = (eles: Collection | Selector) => CollectionElements;
+ type CollectionSymmetricDifferenceFunc = (eles: CollectionArgument | Selector) => CollectionReturnValue;
/**
* http://js.cytoscape.org/#collection/building--filtering
*/
- interface CollectionBuildingUnion {
+ interface CollectionBuildingFiltering {
+ /**
+ * Get an element in the collection from its ID in a very performant way.
+ * @param id The ID of the element to get.
+ */
+ getElementById(id: string): TOut;
+ /**
+ * Get an element in the collection from its ID in a very performant way.
+ * @param id The ID of the element to get.
+ */
+ $id(id: string): TOut;
+
/**
* Get a new collection, resulting from adding the collection with another one
* http://js.cytoscape.org/#eles.union
*/
union: CollectionBuildingUnionFunc;
- // [index: "u"]: CollectionBuildingUnionFunc;
+ u: CollectionBuildingUnionFunc;
add: CollectionBuildingUnionFunc;
- // [index: "+"]: CollectionBuildingUnionFunc;
+ '+': CollectionBuildingUnionFunc;
or: CollectionBuildingUnionFunc;
- // [index: "|"]: CollectionBuildingUnionFunc;
+ '|': CollectionBuildingUnionFunc;
/**
* Get a new collection, resulting from the collection without some specified elements.
* http://js.cytoscape.org/#eles.difference
*/
difference: CollectionBuildingDifferenceFunc;
- // [index: "\\"]: CollectionBuildingDifferenceFunc;
+ subtract: CollectionBuildingDifferenceFunc;
+ '\\': CollectionBuildingDifferenceFunc;
not: CollectionBuildingDifferenceFunc;
- // [index: "!"]: CollectionBuildingDifferenceFunc;
+ '!': CollectionBuildingDifferenceFunc;
relativeComplement: CollectionBuildingDifferenceFunc;
- // [index: "-"]: CollectionBuildingDifferenceFunc;
+ '-': CollectionBuildingDifferenceFunc;
/**
* Get all elements in the graph that are not in the calling collection.
* http://js.cytoscape.org/#eles.absoluteComplement
*/
- absoluteComplement(): CollectionElements;
- abscomp(): CollectionElements;
- complement(): CollectionElements;
+ absoluteComplement(): CollectionReturnValue;
+ abscomp(): CollectionReturnValue;
+ complement(): CollectionReturnValue;
/**
* Get the elements in both this collection and another specified collection.
@@ -2186,9 +2349,9 @@ declare namespace cytoscape {
intersection: CollectionSymmetricDifferenceFunc;
intersect: CollectionSymmetricDifferenceFunc;
and: CollectionSymmetricDifferenceFunc;
- // [index: "n"]: CollectionSymmetricDifferenceFunc;
- // [index: "&"]: CollectionSymmetricDifferenceFunc;
- // [index: "."]: CollectionSymmetricDifferenceFunc;
+ n: CollectionSymmetricDifferenceFunc;
+ '&': CollectionSymmetricDifferenceFunc;
+ '.': CollectionSymmetricDifferenceFunc;
/**
* Get the elements that are in the calling collection
@@ -2198,11 +2361,9 @@ declare namespace cytoscape {
symmetricDifference: CollectionSymmetricDifferenceFunc;
symdiff: CollectionSymmetricDifferenceFunc;
xor: CollectionSymmetricDifferenceFunc;
- // [index: "^"]: CollectionSymmetricDifferenceFunc;
- // [index: "(+)"]: CollectionSymmetricDifferenceFunc;
- // [index: "(-)"]: CollectionSymmetricDifferenceFunc;
-
- // [index: string]: CollectionBuildingDifferenceFunc |CollectionBuildingUnionFunc | CollectionBuildingDifferenceFunc | CollectionSymmetricDifferenceFunc;
+ '^': CollectionSymmetricDifferenceFunc;
+ '(+)': CollectionSymmetricDifferenceFunc;
+ '(-)': CollectionSymmetricDifferenceFunc;
/**
* Perform a traditional left/right diff on the two collections.
@@ -2216,12 +2377,62 @@ declare namespace cytoscape {
* both - is the set of elements in both collections.
* http://js.cytoscape.org/#eles.diff
*/
- diff(selector: Selector | Collection): {
- left: CollectionElements,
- right: CollectionElements,
- both: CollectionElements
+ diff(selector: Selector | CollectionArgument): {
+ left: CollectionReturnValue,
+ right: CollectionReturnValue,
+ both: CollectionReturnValue
};
+ /**
+ * Perform a in-place merge of the given elements into the calling collection.
+ * @param eles The elements to merge in-place or a selector representing the elements to merge.
+ * All elements in the graph matching the selector are used as the passed collection.
+ *
+ * This function modifies the calling collection instead of returning a new one.
+ * Use of this function should be considered for performance in some cases, but otherwise should be avoided. Consider using eles.union() instead.
+ * Use this function only on new collections that you create yourself, using cy.collection().
+ * This ensures that you do not unintentionally modify another collection.
+ *
+ * Examples
+ * With a collection:
+ * @example
+ * var col = cy.collection(); // new, empty collection
+ * var j = cy.$('#j');
+ * var e = cy.$('#e');
+ * col.merge( j ).merge( e );
+ *
+ * With a selector:
+ * @example
+ * var col = cy.collection(); // new, empty collection
+ * col.merge('#j').merge('#e');
+ */
+ merge(eles: CollectionArgument | string): this;
+ /**
+ * Perform an in-place operation on the calling collection to remove the given elements.
+ * @param eles The elements to remove in-place or a selector representing the elements to remove .
+ * All elements in the graph matching the selector are used as the passed collection.
+ *
+ * This function modifies the calling collection instead of returning a new one.
+ * Use of this function should be considered for performance in some cases, but otherwise should be avoided. Consider using eles.filter() or eles.remove() instead.
+ * Use this function only on new collections that you create yourself, using cy.collection().
+ * This ensures that you do not unintentionally modify another collection.
+ *
+ * Examples
+ * With a collection:
+ * @example
+ * var col = cy.collection(); // new, empty collection
+ * var e = cy.$('#e');
+ * col.merge( cy.nodes() );
+ * col.unmerge( e );
+ *
+ * With a selector:
+ * @example
+ * var col = cy.collection(); // new, empty collection
+ * col.merge( cy.nodes() );
+ * col.unmerge('#e');
+ */
+ unmerge(eles: CollectionArgument | string): this;
+
/**
* Get a new collection containing elements that are accepted by the specified filter.
*
@@ -2231,7 +2442,7 @@ declare namespace cytoscape {
* ele - The element being considered.
* http://js.cytoscape.org/#eles.filter
*/
- filter(selector: Selector | ((ele: Singular, i: number, eles: CollectionElements) => boolean)): CollectionElements;
+ filter(selector: Selector | ((ele: TOut, i: number, eles: CollectionArgument) => boolean)): CollectionReturnValue;
/**
* Get the nodes that match the specified selector.
*
@@ -2257,7 +2468,7 @@ declare namespace cytoscape {
*
* http://js.cytoscape.org/#eles.sort
*/
- sort(sort: (ele1: CollectionElements, ele2: CollectionElements) => number): CollectionElements;
+ sort(sort: (ele1: CollectionArgument, ele2: CollectionArgument) => number): CollectionReturnValue;
/**
* Get an array containing values mapped from the collection.
@@ -2270,7 +2481,7 @@ declare namespace cytoscape {
*
* http://js.cytoscape.org/#eles.map
*/
- map(fn: (ele: CollectionElements, i: number, eles: CollectionElements) => any, thisArg?: any): any[];
+ map(fn: (ele: CollectionArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): any[];
/**
* Reduce a single value by applying a
@@ -2282,11 +2493,13 @@ declare namespace cytoscape {
* ele The current element.
* ix The index of the current element.
* eles The collection of elements being reduced.
- *
+ * @param initialValue The initial value for reducing
+ * It is used also for type inference of output, but the type can be
+ * also stated explicitly as generic
* http://js.cytoscape.org/#eles.reduce
*/
- reduce(fn: (prevVal: any, ele: CollectionElements,
- ix: number, eles: CollectionElements) => any): number[];
+ reduce(fn: (prevVal: T, ele: SingularElementReturnValue,
+ ix: number, eles: CollectionReturnValue) => T, initialValue: T): T;
/**
* Find a minimum value in a collection.
@@ -2299,7 +2512,7 @@ declare namespace cytoscape {
*
* http://js.cytoscape.org/#eles.min
*/
- min(fn: (ele: CollectionElements, i: number, eles: CollectionElements) => any, thisArg?: any): {
+ min(fn: (ele: CollectionArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): {
/**
* The minimum value found.
*/
@@ -2307,7 +2520,7 @@ declare namespace cytoscape {
/**
* The element that corresponds to the minimum value.
*/
- ele: CollectionElements
+ ele: CollectionArgument
};
/**
@@ -2321,7 +2534,7 @@ declare namespace cytoscape {
*
* http://js.cytoscape.org/#eles.max
*/
- max(fn: (ele: CollectionElements, i: number, eles: CollectionElements) => any, thisArg?: any): {
+ max(fn: (ele: CollectionArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): {
/**
* The maximum value found.
*/
@@ -2329,7 +2542,7 @@ declare namespace cytoscape {
/**
* The element that corresponds to the maximum value.
*/
- ele: CollectionElements
+ ele: CollectionArgument
};
}
@@ -2351,7 +2564,7 @@ declare namespace cytoscape {
*
* @param selector [optional] An optional selector that is used to filter the resultant collection.
*/
- neighborhood(selector?: Selector): CollectionElements;
+ neighborhood(selector?: Selector): CollectionReturnValue;
/**
* Get the open neighbourhood of the elements.
@@ -2362,7 +2575,7 @@ declare namespace cytoscape {
*
* @param selector [optional] An optional selector that is used to filter the resultant collection.
*/
- openNeighborhood(selector?: Selector): CollectionElements;
+ openNeighborhood(selector?: Selector): CollectionReturnValue;
/**
* Get the closed neighbourhood of the elements.
*
@@ -2372,13 +2585,54 @@ declare namespace cytoscape {
*
* @param selector [optional] An optional selector that is used to filter the resultant collection.
*/
- closedNeighborhood(selector?: Selector): CollectionElements;
+ closedNeighborhood(selector?: Selector): CollectionReturnValue;
/**
* Get the connected components, considering only the elements in the calling collection.
* An array of collections is returned, with each collection representing a component.
*/
- components(): Collection;
+ components(): CollectionReturnValue[];
+ }
+ /**
+ * http://js.cytoscape.org/#collection/edge-points
+ */
+ interface EdgeSingularPoints {
+ /**
+ * Get an array of control point model positions for a {@code curve-style: bezier) or {@code curve-style: unbundled-bezier} edge.
+ *
+ * While the control points may be specified relatively in the CSS,
+ * this function returns the absolute model positions of the control points.
+ * The points are specified in the order of source-to-target direction.
+ * This function works for bundled beziers, but it is not applicable to the middle, straight-line edge in the bundle.
+ */
+ controlPoints(): Position[];
+ /**
+ * Get an array of segment point model positions (i.e. bend points) for a {@code curve-style: segments} edge.
+ *
+ * While the segment points may be specified relatively in the stylesheet,
+ * this function returns the absolute model positions of the segment points.
+ * The points are specified in the order of source-to-target direction.
+ */
+ segmentPoints(): Position[];
+ /**
+ * Get the model position of where the edge ends, towards the source node.
+ */
+ sourceEndpoint(): Position;
+ /**
+ * Get the model position of where the edge ends, towards the target node.
+ */
+ targetEndpoint(): Position;
+ /**
+ * Get the model position of the midpoint of the edge.
+ *
+ * The midpoint is, by default, where the edge’s label is centred. It is also the position towards which mid arrows point.
+ * For curve-style: unbundled-bezier edges, the midpoint is the middle extremum if the number of control points is odd.
+ * For an even number of control points, the midpoint is where the two middle-most control points meet.
+ * This is the middle inflection point for bilaterally symmetric or skew symmetric edges, for example.
+ * For curve-style: segments edges, the midpoint is the middle segment point if the number of segment points is odd.
+ * For an even number of segment points, the overall midpoint is the midpoint of the middle-most line segment (i.e. the mean of the middle two segment points).
+ */
+ midpoint(): Position;
}
interface EdgeSingularTraversing {
/**
@@ -2457,7 +2711,7 @@ declare namespace cytoscape {
* @param eles The other collection.
* @param selector The other collection, specified as a selector which is matched against all elements in the graph.
*/
- edgesWith(eles: Collection | Selector): EdgeCollection;
+ edgesWith(eles: CollectionArgument | Selector): EdgeCollection;
/**
* Get the edges coming from the collection (i.e. the source) going to another collection (i.e. the target).
@@ -2465,7 +2719,7 @@ declare namespace cytoscape {
* @param eles The other collection.
* @param selector The other collection, specified as a selector which is matched against all elements in the graph.
*/
- edgesTo(eles: Collection | Selector): EdgeCollection;
+ edgesTo(eles: CollectionArgument | Selector): EdgeCollection;
/**
* Get the edges connected to the nodes in the collection.
@@ -2537,7 +2791,7 @@ declare namespace cytoscape {
/**
* The root nodes (selector or collection) to start the search from.
*/
- roots: Selector | Collection;
+ roots: Selector | CollectionArgument;
/**
* A handler function that is called when a node is visited in the search.
*/
@@ -2552,7 +2806,7 @@ declare namespace cytoscape {
* The path of the search.
* - The path returned includes edges such that if path[i] is a node, then path[i - 1] is the edge used to get to that node.
*/
- path: CollectionElements;
+ path: CollectionArgument;
/**
* The node found by the search
* - If no node was found, then found is empty.
@@ -2568,7 +2822,7 @@ declare namespace cytoscape {
/**
* The root node (selector or collection) where the algorithm starts.
*/
- root: Selector | Collection;
+ root: Selector | CollectionArgument;
/**
* A function that returns the positive numeric weight for this edge.
@@ -2596,14 +2850,14 @@ declare namespace cytoscape {
* The path starts with the source node and includes the edges between the nodes in the path such that if pathTo(node)[i] is an edge,
* then pathTo(node)[i-1] is the previous node in the path and pathTo(node)[i+1] is the next node in the path.
*/
- pathTo(node: NodeSingular): Collection;
+ pathTo(node: NodeSingular): CollectionReturnValue;
}
/**
* http://js.cytoscape.org/#eles.aStar
*/
interface SearchAStarOptions {
- root: Selector | Collection;
- goal: Selector | Collection;
+ root: Selector | CollectionArgument;
+ goal: Selector | CollectionArgument;
weight?: WeightFn;
heuristic?(node: NodeCollection): number;
directed?: boolean;
@@ -2614,7 +2868,7 @@ declare namespace cytoscape {
interface SearchAStarResult {
found: boolean;
distance: number;
- path: Collection;
+ path: CollectionReturnValue;
}
/**
@@ -2641,7 +2895,7 @@ declare namespace cytoscape {
* then pathTo(node)[i-1] is the previous node in the path and pathTo(node)[i+1]
* is the next node in the path.
*/
- path(fromNode: NodeSingular | CollectionSelection, toNode: NodeSingular | Selector): Collection;
+ path(fromNode: NodeSingular | CollectionSelection, toNode: NodeSingular | Selector): CollectionReturnValue;
}
/**
@@ -2670,7 +2924,7 @@ declare namespace cytoscape {
* function that computes the shortest path from root node to the argument node
* (either objects or selector string)
*/
- pathTo(node: NodeSingular | Selector): Collection;
+ pathTo(node: NodeSingular | Selector): CollectionReturnValue;
/**
* function that computes the shortest distance from root node to argument node
@@ -4368,13 +4622,13 @@ declare namespace cytoscape {
* Start running the layout
* http://js.cytoscape.org/#layout.run
*/
- run(): void;
- start(): void;
+ run(): this;
+ start(): this;
/**
* Stop running the (asynchronous/discrete) layout
* http://js.cytoscape.org/#layout.stop
*/
- stop(): void;
+ stop(): this;
}
interface LayoutEvents {
/**