diff --git a/types/cytoscape/cytoscape-tests.ts b/types/cytoscape/cytoscape-tests.ts index 17eba79fd5..3d80506185 100644 --- a/types/cytoscape/cytoscape-tests.ts +++ b/types/cytoscape/cytoscape-tests.ts @@ -410,9 +410,15 @@ eles.restore(); ]).forEach((elemType) => { aliases(elemType.clone, elemType.copy); // events(elemType); - TODO - aliases(elemType.data, elemType.attr); aliases(elemType.removeData, elemType.removeAttr); }); +([ele, node, edge] as [ + cytoscape.SingularElementReturnValue, + cytoscape.NodeSingular, + cytoscape.EdgeSingular +]).forEach((elemType) => { + aliases(elemType.data, elemType.attr); +}); // TODO: tests for data flow const loops = oneOf(true, false); @@ -453,6 +459,8 @@ aliases(eles.renderedBoundingBox, eles.renderedBoundingbox); const flags: boolean[] = [ node.grabbed(), node.grabbable(), node.locked(), ele.active(), ]; +nodes.lock(); node.lock(); +nodes.unlock(); node.unlock(); const edgePoints: cytoscape.Position[] = [ ...edge.controlPoints(), ...edge.segmentPoints(), edge.sourceEndpoint(), edge.targetEndpoint(), edge.midpoint() @@ -511,7 +519,7 @@ cy.collection().merge(diff.left).merge(diff.right).merge(diff.both).unmerge(coll 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 min = eles.min((ele, i, eles) => ele.id.length + i); min.ele.scratch('min', min.value).scratch('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/edges distinction) diff --git a/types/cytoscape/index.d.ts b/types/cytoscape/index.d.ts index 282a90c7a4..13b0b38ba8 100644 --- a/types/cytoscape/index.d.ts +++ b/types/cytoscape/index.d.ts @@ -482,7 +482,8 @@ declare namespace cytoscape { * @param namespace A namespace string. * @param value The value to set at the specified namespace. */ - scratch(namespace?: string, value?: any): Scratchpad; + scratch(namespace?: string): Scratchpad; + scratch(namespace: string, value: any): this; /** * Remove scratchpad data. You should remove scratchpad data only at your own namespaces. @@ -490,7 +491,7 @@ declare namespace cytoscape { * * @param namespace A namespace string. */ - removeScratch(namespace: string): void; + removeScratch(namespace: string): this; } /** @@ -508,25 +509,25 @@ declare namespace cytoscape { * @param eventsMap A map of event names to handler functions. */ - on(events: EventNames, handler: EventHandler): void; - on(events: EventNames, selector: Selector, handler: EventHandler): void; - on(events: EventNames, selector: Selector, data: any, handler: EventHandler): void; - on(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): void; + on(events: EventNames, handler: EventHandler): this; + on(events: EventNames, selector: Selector, handler: EventHandler): this; + on(events: EventNames, selector: Selector, data: any, handler: EventHandler): this; + on(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): this; - bind(events: EventNames, handler: EventHandler): void; - bind(events: EventNames, selector: Selector, handler: EventHandler): void; - bind(events: EventNames, selector: Selector, data: any, handler: EventHandler): void; - bind(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): void; + bind(events: EventNames, handler: EventHandler): this; + bind(events: EventNames, selector: Selector, handler: EventHandler): this; + bind(events: EventNames, selector: Selector, data: any, handler: EventHandler): this; + bind(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): this; - listen(events: EventNames, handler: EventHandler): void; - listen(events: EventNames, selector: Selector, handler: EventHandler): void; - listen(events: EventNames, selector: Selector, data: any, handler: EventHandler): void; - listen(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): void; + listen(events: EventNames, handler: EventHandler): this; + listen(events: EventNames, selector: Selector, handler: EventHandler): this; + listen(events: EventNames, selector: Selector, data: any, handler: EventHandler): this; + listen(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): this; - addListener(events: EventNames, handler: EventHandler): void; - addListener(events: EventNames, selector: Selector, handler: EventHandler): void; - addListener(events: EventNames, selector: Selector, data: any, handler: EventHandler): void; - addListener(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): void; + addListener(events: EventNames, handler: EventHandler): this; + addListener(events: EventNames, selector: Selector, handler: EventHandler): this; + addListener(events: EventNames, selector: Selector, data: any, handler: EventHandler): this; + addListener(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): this; /** * Get a promise that is resolved with the first @@ -542,7 +543,7 @@ declare namespace cytoscape { * @param events A space separated list of event names. * @param handler The handler function that is called when one of the specified events occurs. */ - one(events: EventNames, handler: EventHandler): void; + one(events: EventNames, handler: EventHandler): this; /** * Bind to events that occur in the graph, and trigger the handler only once. * @@ -550,7 +551,7 @@ declare namespace cytoscape { * @param handler The handler function that is called when one of the specified events occurs. * @param selector A selector to specify elements for which the handler is triggered. */ - one(events: EventNames, selector: Selector, handler: EventHandler): void; + one(events: EventNames, selector: Selector, handler: EventHandler): this; /** * Bind to events that occur in the graph, and trigger the handler only once. * @@ -559,7 +560,7 @@ declare namespace cytoscape { * @param selector A selector to specify elements for which the handler is triggered. * @param data A plain object which is passed to the handler in the event object argument. */ - one(events: EventNames, selector: Selector, data: any, handler: EventHandler): void; + one(events: EventNames, selector: Selector, data: any, handler: EventHandler): this; /** * Bind to events that occur in the graph, and trigger the handler only once. * @@ -567,7 +568,7 @@ declare namespace cytoscape { * @param selector A selector to specify elements for which the handler is triggered. * @param data A plain object which is passed to the handler in the event object argument. */ - one(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): void; + one(eventsMap: { [value: string]: EventHandler }, selector?: Selector, data?: any): this; /** * Remove event handlers. @@ -578,17 +579,17 @@ declare namespace cytoscape { * @param handler [optional] A reference to the handler function to remove. * @param eventsMap A map of event names to handler functions to remove. */ - off(events: EventNames, selector?: Selector, handler?: EventHandler): void; - off(eventsMap: { [value: string]: EventHandler }, selector?: Selector): void; + off(events: EventNames, selector?: Selector, handler?: EventHandler): this; + off(eventsMap: { [value: string]: EventHandler }, selector?: Selector): this; - unbind(events: EventNames, selector?: Selector, handler?: EventHandler): void; - unbind(eventsMap: { [value: string]: EventHandler }, selector?: Selector): void; + unbind(events: EventNames, selector?: Selector, handler?: EventHandler): this; + unbind(eventsMap: { [value: string]: EventHandler }, selector?: Selector): this; - unlisten(events: EventNames, selector?: Selector, handler?: EventHandler): void; - unlisten(eventsMap: { [value: string]: EventHandler }, selector?: Selector): void; + unlisten(events: EventNames, selector?: Selector, handler?: EventHandler): this; + unlisten(eventsMap: { [value: string]: EventHandler }, selector?: Selector): this; - removeListener(events: EventNames, selector?: Selector, handler?: EventHandler): void; - removeListener(eventsMap: { [value: string]: EventHandler }, selector?: Selector): void; + removeListener(events: EventNames, selector?: Selector, handler?: EventHandler): this; + removeListener(eventsMap: { [value: string]: EventHandler }, selector?: Selector): this; /** * Trigger one or more events. @@ -596,14 +597,14 @@ declare namespace cytoscape { * @param events A space separated list of event names to trigger. * @param extraParams [optional] An array of additional parameters to pass to the handler. */ - trigger(events: EventNames, extraParams?: any[]): void; - emit(events: EventNames, extraParams?: any[]): void; + trigger(events: EventNames, extraParams?: any[]): this; + emit(events: EventNames, extraParams?: any[]): this; /** * Run a callback as soon as the graph becomes ready. If the graph is already ready, then the callback is called immediately. * @param fn The callback run as soon as the graph is ready, inside which this refers to the core (cy). */ - ready(fn: EventHandler): void; + ready(fn: EventHandler): this; } interface ZoomOptionsModel { @@ -695,7 +696,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables panning; a falsey value disables it. */ - panningEnabled(bool: boolean): void; + panningEnabled(bool: boolean): this; /** * Get whether panning by user events (e.g. dragging the graph background) is enabled. If cy.boxSelectionEnabled() === true, then the user must taphold to initiate panning. @@ -709,7 +710,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables user panning; a falsey value disables it. */ - userPanningEnabled(bool: boolean): void; + userPanningEnabled(bool: boolean): this; /** * Get the zoom level. * http://js.cytoscape.org/#cy.zoom @@ -722,7 +723,7 @@ declare namespace cytoscape { * @param level The zoom level to set. * @param options The options for zooming. */ - zoom(level?: number | ZoomOptions): void; + zoom(level?: number | ZoomOptions): this; /** * Set or get whether zooming is enabled. Get if no parameter provided. @@ -730,7 +731,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables zooming; a falsey value disables it. */ - zoomingEnabled(bool?: boolean): void; + zoomingEnabled(bool?: boolean): this; /** * Get whether zooming by user events (e.g. mouse wheel, pinch-to-zoom) @@ -745,7 +746,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables user zooming; a falsey value disables it. */ - userZoomingEnabled(bool?: boolean): void; + userZoomingEnabled(bool?: boolean): this; /** * Get the minimum zoom level. @@ -758,7 +759,7 @@ declare namespace cytoscape { * * @param zoom The new minimum zoom level to use. */ - minZoom(zoom: number): void; + minZoom(zoom: number): this; /** * Get the maximum zoom level. @@ -771,7 +772,7 @@ declare namespace cytoscape { * * @param zoom The new maximum zoom level to use. */ - maxZoom(zoom: number): void; + maxZoom(zoom: number): this; /** * Set the viewport state (pan & zoom) in one call. @@ -780,7 +781,7 @@ declare namespace cytoscape { * @param zoom The zoom level to set. * @param pan The pan to set (a rendered position). */ - viewport(zoom: number, pan: Position): void; + viewport(zoom: number, pan: Position): this; /** * Get whether box selection is enabled. @@ -795,7 +796,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables box selection; a falsey value disables it. */ - boxSelectionEnabled(bool: boolean): void; + boxSelectionEnabled(bool: boolean): this; /** * Get the on-screen width of the viewport in pixels. @@ -832,7 +833,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables autolocking; a falsey value disables it. */ - autolock(bool: boolean): void; + autolock(bool: boolean): this; /** * Get whether nodes are automatically ungrabified @@ -847,7 +848,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables autolocking; a falsey value disables it. */ - autoungrabify(bool: boolean): void; + autoungrabify(bool: boolean): this; /** * Get whether nodes are automatically unselectified @@ -862,7 +863,7 @@ declare namespace cytoscape { * * @param bool A truthy value enables autolocking; a falsey value disables it. */ - autounselectify(bool: boolean): void; + autounselectify(bool: boolean): this; /** * Force the renderer to redraw (i.e. draw a new frame). @@ -872,7 +873,7 @@ declare namespace cytoscape { * but it should not be needed for most developers. * http://js.cytoscape.org/#cy.forceRender */ - forceRender(): void; + forceRender(): this; /** * Force the renderer to recalculate the viewport bounds. @@ -949,7 +950,7 @@ declare namespace cytoscape { * Get an animation of the viewport. * http://js.cytoscape.org/#cy.animation */ - animation(options: AnimationOptions): any; + animation(options: AnimationOptions): AnimationManipulation; /** * Add a delay between animations for the viewport. @@ -963,7 +964,7 @@ declare namespace cytoscape { * Get a delay animation of the viewport. * http://js.cytoscape.org/#cy.delayAnimation */ - delayAnimation(duration: number): void; + delayAnimation(duration: number): AnimationManipulation; /** * Stop all viewport animations that are currently running. @@ -1171,7 +1172,7 @@ declare namespace cytoscape { * * The output is a collection of edge elements OR single edge. */ - interface EdgeCollection extends EdgeSingular, + interface EdgeCollection extends Collection, EdgeCollectionTraversing { } /** * nodes -> Cy.NodeCollection @@ -1179,7 +1180,7 @@ declare namespace cytoscape { * * The output is a collection of node elements OR single node. */ - interface NodeCollection extends NodeSingular, + interface NodeCollection extends Collection, NodeCollectionMetadata, NodeCollectionPosition, NodeCollectionTraversing, NodeCollectionCompound { } @@ -1189,14 +1190,14 @@ declare namespace cytoscape { * edge --> Cy.EdgeSingular * a collection of a single edge */ - interface EdgeSingular extends Singular, + interface EdgeSingular extends Singular, EdgeCollection, EdgeSingularData, EdgeSingularPoints, EdgeSingularTraversing { } /** * node --> Cy.NodeSingular * a collection of a single node */ - interface NodeSingular extends Singular, + interface NodeSingular extends Singular, NodeCollection, NodeSingularMetadata, NodeSingularPosition, NodeSingularCompound { } /** @@ -1265,18 +1266,18 @@ declare namespace cytoscape { /** * http://js.cytoscape.org/#eles.on */ - on(events: EventNames, selector: string, data: any, handler: EventHandler): void; - on(events: EventNames, selector: string, handler: EventHandler): void; - on(events: EventNames, handler: EventHandler): void; - bind(events: EventNames, selector: string, data: any, handler: EventHandler): void; - bind(events: EventNames, selector: string, handler: EventHandler): void; - bind(events: EventNames, handler: EventHandler): void; - listen(events: EventNames, selector: string, data: any, handler: EventHandler): void; - listen(events: EventNames, selector: string, handler: EventHandler): void; - listen(events: EventNames, handler: EventHandler): void; - addListener(events: EventNames, selector: string, data: any, handler: EventHandler): void; - addListener(events: EventNames, selector: string, handler: EventHandler): void; - addListener(events: EventNames, handler: EventHandler): void; + on(events: EventNames, selector: string, data: any, handler: EventHandler): this; + on(events: EventNames, selector: string, handler: EventHandler): this; + on(events: EventNames, handler: EventHandler): this; + bind(events: EventNames, selector: string, data: any, handler: EventHandler): this; + bind(events: EventNames, selector: string, handler: EventHandler): this; + bind(events: EventNames, handler: EventHandler): this; + listen(events: EventNames, selector: string, data: any, handler: EventHandler): this; + listen(events: EventNames, selector: string, handler: EventHandler): this; + listen(events: EventNames, handler: EventHandler): this; + addListener(events: EventNames, selector: string, data: any, handler: EventHandler): this; + addListener(events: EventNames, selector: string, handler: EventHandler): this; + addListener(events: EventNames, handler: EventHandler): this; /** * http://js.cytoscape.org/#eles.promiseOn * alias: pon @@ -1292,29 +1293,29 @@ declare namespace cytoscape { * @param event The event object. * http://js.cytoscape.org/#eles.one */ - one(events: EventNames, selector: string, data: any, handler: EventHandler): void; - one(events: EventNames, selector: string, handler: EventHandler): void; - one(events: EventNames, handler: EventHandler): void; + one(events: EventNames, selector: string, data: any, handler: EventHandler): this; + one(events: EventNames, selector: string, handler: EventHandler): this; + one(events: EventNames, handler: EventHandler): this; /** * http://js.cytoscape.org/#eles.once */ - once(events: EventNames, selector: string, data: any, handler: EventHandler): void; - once(events: EventNames, selector: string, handler: EventHandler): void; - once(events: EventNames, handler: EventHandler): void; + once(events: EventNames, selector: string, data: any, handler: EventHandler): this; + once(events: EventNames, selector: string, handler: EventHandler): this; + once(events: EventNames, handler: EventHandler): this; /** * http://js.cytoscape.org/#eles.off * alias unbind, unlisten, removeListener */ - off(events: EventNames, selector?: string, handler?: EventHandler): void; - unbind(events: EventNames, selector?: string, handler?: EventHandler): void; - unlisten(events: EventNames, selector?: string, handler?: EventHandler): void; - removeListener(events: EventNames, selector?: string, handler?: EventHandler): void; + off(events: EventNames, selector?: string, handler?: EventHandler): this; + unbind(events: EventNames, selector?: string, handler?: EventHandler): this; + unlisten(events: EventNames, selector?: string, handler?: EventHandler): this; + removeListener(events: EventNames, selector?: string, handler?: EventHandler): this; /** * http://js.cytoscape.org/#eles.trigger * alias: emit */ - trigger(events: EventNames, extra?: string[]): void; - emit(events: EventNames, extra?: string[]): void; + trigger(events: EventNames, extra?: string[]): this; + emit(events: EventNames, extra?: string[]): this; } /** @@ -1359,12 +1360,12 @@ declare namespace cytoscape { * @param name The name of the field to set. * @param value The value to set for the field. */ - data(name: string, value: any): void; + data(name: string, value: any): this; /** * Update multiple data fields at once via an object. * @param obj The object containing name- value pairs to update data fields. */ - data(obj: any): void; + data(obj: any): this; /** * Get a particular data field for the element. * @param name The name of the field to get. @@ -1375,12 +1376,12 @@ declare namespace cytoscape { * @param name The name of the field to set. * @param value The value to set for the field. */ - attr(name: string, value: any): void; + attr(name: string, value: any): this; /** * 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; + attr(obj: any): this; /** * Get or set the scratchpad at a particular namespace, @@ -1392,7 +1393,8 @@ declare namespace cytoscape { * @param namespace A namespace string. * @param value The value to set at the specified namespace. */ - scratch(namespace?: string, value?: any): Scratchpad; + scratch(namespace?: string): Scratchpad; + scratch(namespace: string, value: any): this; /** * Remove scratchpad data. @@ -1400,7 +1402,7 @@ declare namespace cytoscape { * http://js.cytoscape.org/#ele.removeScratch * @param namespace A namespace string. */ - removeScratch(namespace: string): void; + removeScratch(namespace: string): this; /** * A shortcut to get the ID of an element. @@ -1589,18 +1591,6 @@ declare namespace cytoscape { */ 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. * http://js.cytoscape.org/#node.renderedPosition @@ -1612,8 +1602,8 @@ declare namespace cytoscape { * @param pos An object specifying name-value pairs representing dimensions to set. */ renderedPosition(dimension?: PositionDimension): Position; - renderedPosition(dimension: PositionDimension, value: Position): void; - renderedPosition(pos: { [name: string]: number }): void; + renderedPosition(dimension: PositionDimension, value: Position): this; + renderedPosition(pos: { [name: string]: number }): this; /** * Set the value of a specified rendered position dimension. @@ -1622,8 +1612,8 @@ declare namespace cytoscape { * @param pos An object specifying name-value pairs representing dimensions to set. */ renderedPoint(dimension?: PositionDimension): Position; - renderedPoint(dimension: PositionDimension, value: Position): void; - renderedPoint(pos: { [name: string]: number }): void; + renderedPoint(dimension: PositionDimension, value: Position): this; + renderedPoint(pos: { [name: string]: number }): this; /** * @@ -1636,8 +1626,8 @@ declare namespace cytoscape { * @param pos An object specifying name-value pairs representing dimensions to set. */ relativePosition(dimension?: PositionDimension): Position; - relativePosition(dimension: PositionDimension, value: Position): void; - relativePosition(pos: { [name: string]: number }): void; + relativePosition(dimension: PositionDimension, value: Position): this; + relativePosition(pos: { [name: string]: number }): this; /** * Get the value of a specified relative position dimension. @@ -1646,8 +1636,8 @@ declare namespace cytoscape { * @param pos An object specifying name-value pairs representing dimensions to set. */ relativePoint(dimension?: PositionDimension): Position; - relativePoint(dimension: PositionDimension, value: Position): void; - relativePoint(pos: { [name: string]: number }): void; + relativePoint(dimension: PositionDimension, value: Position): this; + relativePoint(pos: { [name: string]: number }): this; /** * Get whether a node is currently grabbed, meaning the user has hold of the node. @@ -1670,43 +1660,55 @@ 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: NodeSingular, ix: number) => void; - type ElementCollectionFunction = (ele: NodeSingular, ix: number, eles: CollectionArgument) => void; + type ElementPositionFunction = (ele: NodeSingular, ix: number) => Position; + type ElementCollectionFunction = (ele: NodeSingular, ix: number, eles: CollectionArgument) => Position; /** * http://js.cytoscape.org/#collection/position--dimensions */ interface NodeCollectionPosition { + /** + * 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; + /** * Set the positions via a function. * @param handler A callback function that returns the position to set for each element. * @param pos An object specifying name-value pairs representing dimensions to set. * http://js.cytoscape.org/#nodes.positions */ - positions(handler: ElementPositionFunction | Position): void; - modelPositions(handler: ElementPositionFunction | Position): void; - points(handler: ElementPositionFunction | Position): void; + positions(handler: ElementPositionFunction | Position): this; + modelPositions(handler: ElementPositionFunction | Position): this; + points(handler: ElementPositionFunction | Position): this; /** * Allow the user to grab the nodes. * http://js.cytoscape.org/#nodes.grabify */ - grabify(): void; + grabify(): this; /** * Disallow the user to grab the nodes. * http://js.cytoscape.org/#nodes.ungrabify */ - ungrabify(): void; + ungrabify(): this; /** * Lock the nodes such that their positions can not be changed. * http://js.cytoscape.org/#nodes.lock */ - lock(): void; + lock(): this; /** * Unlock the nodes such that their positions can be changed. * http://js.cytoscape.org/#nodes.unlock */ - unlock(): void; + unlock(): this; } /** * http://js.cytoscape.org/#collection/position--dimensions @@ -1877,23 +1879,23 @@ declare namespace cytoscape { * Make the elements selected (NB other elements outside the collection are not affected). * http://js.cytoscape.org/#eles.select */ - select(): void; + select(): this; /** * Make the elements not selected (NB other elements outside the collection are not affected). * http://js.cytoscape.org/#eles.unselect */ - unselect(): void; - deselect(): void; + unselect(): this; + deselect(): this; /** * Make the selection states of the elements mutable. * http://js.cytoscape.org/#eles.selectify */ - selectify(): void; + selectify(): this; /** * Make the selection states of the elements immutable. * http://js.cytoscape.org/#eles.unselectify */ - unselectify(): void; + unselectify(): this; } /** @@ -1909,34 +1911,34 @@ declare namespace cytoscape { * http://js.cytoscape.org/#eles.addClass * @param classes A space-separated list of class names to add to the elements. */ - addClass(classes: ClassNames): void; + addClass(classes: ClassNames): this; /** * Remove classes from elements. * @param classes A space-separated list of class names to remove from the elements. * http://js.cytoscape.org/#eles.removeClass */ - removeClass(classes: ClassNames): void; + removeClass(classes: ClassNames): this; /** * Toggle whether the elements have the specified classes. * @param classes A space-separated list of class names to toggle on the elements. * @param toggle [optional] Instead of automatically toggling, adds the classes on truthy values or removes them on falsey values. * http://js.cytoscape.org/#eles.toggleClass */ - toggleClass(classes: ClassNames, toggle?: boolean): void; + toggleClass(classes: ClassNames, toggle?: boolean): this; /** * Replace the current list of classes on the elements with the specified list. * @param classes A space-separated list of class names that replaces the current class list. * http://js.cytoscape.org/#eles.classes * Note: can be used to clear all classes (no arguments). */ - classes(classes?: ClassNames): void; + classes(classes?: ClassNames): this; /** * Add classes to the elements, and then remove the classes after a specified duration. * @param classes A space-separated list of class names to flash on the elements. * @param duration [optional] The duration in milliseconds that the classes should be added on the elements. After the duration, the classes are removed. * http://js.cytoscape.org/#eles.flashClass */ - flashClass(classes: ClassNames, duration?: number): void; + flashClass(classes: ClassNames, duration?: number): this; /** * Set a particular style property value. @@ -2081,26 +2083,26 @@ declare namespace cytoscape { * @param options An object containing the details of the animation. * http://js.cytoscape.org/#eles.animate */ - animate(options: ElementAnimateOptionPos | ElementAnimateOptionRen): void; + animate(options: ElementAnimateOptionPos | ElementAnimateOptionRen): this; /** * Add a delay between animations for the elements. * @param duration How long the delay should be in milliseconds. * @param complete A function to call when the delay is complete. * http://js.cytoscape.org/#eles.delay */ - delay(duration: number, complete: () => void): void; + delay(duration: number, complete: () => void): this; /** * Stop all animations that are currently running. * @param clearQueue A boolean, indicating whether the queue of animations should be emptied. * @param jumpToEnd A boolean, indicating whether the currently-running animations should jump to their ends rather than just stopping midway. * http://js.cytoscape.org/#eles.stop */ - stop(clearQueue: boolean, jumpToEnd: boolean): void; + stop(clearQueue: boolean, jumpToEnd: boolean): this; /** * Remove all queued animations for the elements. * http://js.cytoscape.org/#eles.clearQueue */ - clearQueue(): void; + clearQueue(): this; } interface SingularAnimationOptions { /** A position to which the elements will be animated. */ @@ -2123,14 +2125,14 @@ declare namespace cytoscape { * Get an animation for the element. * @param options An object containing the details of the animation. */ - animation(options: SingularAnimationOptions): void; + animation(options: SingularAnimationOptions): AnimationManipulation; /** * Get a delay animation for the element. * @param duration How long the delay should be in milliseconds. * http://js.cytoscape.org/#ele.delayAnimation */ - delayAnimation(duration: number): void; + delayAnimation(duration: number): AnimationManipulation; } /** @@ -2246,8 +2248,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: TIn, i: number, eles: this) => void | boolean, thisArg?: any): void; - forEach(each: (ele: TIn, i: number, eles: this) => void | boolean, thisArg?: any): void; + each(each: (ele: TIn, i: number, eles: this) => void | boolean, thisArg?: any): this; + forEach(each: (ele: TIn, i: number, eles: this) => void | boolean, thisArg?: any): this; /** * Get an element at a particular index in the collection. @@ -2287,7 +2289,7 @@ declare namespace cytoscape { /** * Get the collection as an array, maintaining the order of the elements. */ - toArray(): SingularElementReturnValue[]; + toArray(): TOut[]; } /** @@ -2542,7 +2544,7 @@ declare namespace cytoscape { * * http://js.cytoscape.org/#eles.min */ - min(fn: (ele: CollectionArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): { + min(fn: (ele: SingularElementArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): { /** * The minimum value found. */ @@ -2550,7 +2552,7 @@ declare namespace cytoscape { /** * The element that corresponds to the minimum value. */ - ele: CollectionArgument + ele: SingularElementReturnValue }; /** @@ -2564,15 +2566,15 @@ declare namespace cytoscape { * * http://js.cytoscape.org/#eles.max */ - max(fn: (ele: CollectionArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): { + max(fn: (ele: SingularElementArgument, i: number, eles: CollectionArgument) => any, thisArg?: any): { /** - * The maximum value found. + * The minimum value found. */ value: any, /** - * The element that corresponds to the maximum value. + * The element that corresponds to the minimum value. */ - ele: CollectionArgument + ele: SingularElementReturnValue }; } @@ -2988,7 +2990,7 @@ declare namespace cytoscape { */ interface SearchPageRankResult { /** function that computes the rank of a given node (either object or selector string) */ - rank(node: NodeCollection): void; + rank(node: NodeCollection): number; } /** @@ -3198,7 +3200,7 @@ declare namespace cytoscape { * returning the minimum spanning tree, assuming undirected edges. * http://js.cytoscape.org/#eles.kruskal */ - kruskal(handler: (edge: EdgeCollection) => number): void; + kruskal(handler: (edge: EdgeCollection) => number): CollectionReturnValue; /** * Finds the minimum cut in a graph using the Karger-Stein algorithm. * The optimal result is found with a high probability, but without guarantee. @@ -4671,10 +4673,10 @@ declare namespace cytoscape { * @param handler The handler function that is called * when one of the specified events occurs. */ - on(events: EventNames, data: any, handler: EventHandler): void; - bind(events: EventNames, data: any, handler: EventHandler): void; - listen(events: EventNames, data: any, handler: EventHandler): void; - addListener(events: EventNames, data: any, handler: EventHandler): void; + on(events: EventNames, data: any, handler: EventHandler): this; + bind(events: EventNames, data: any, handler: EventHandler): this; + listen(events: EventNames, data: any, handler: EventHandler): this; + addListener(events: EventNames, data: any, handler: EventHandler): this; /** * Get a promise that is resolved with the first of any of @@ -4690,8 +4692,8 @@ declare namespace cytoscape { * @param data [optional] A plain object which is passed to the handler in the event object argument. * @param handler The handler function that is called when one of the specified events occurs. */ - one(events: EventNames, handler: EventHandler): void; - one(events: EventNames, data: any, handler: EventHandler): void; + one(events: EventNames, handler: EventHandler): this; + one(events: EventNames, data: any, handler: EventHandler): this; /** * Remove event handlers on the layout. @@ -4700,10 +4702,10 @@ declare namespace cytoscape { * @param events A space separated list of event names. * @param handler [optional] A reference to the handler function to remove. */ - off(events: EventNames, handler?: EventHandler): void; - unbind(events: EventNames, handler?: EventHandler): void; - unlisten(events: EventNames, handler?: EventHandler): void; - removeListener(events: EventNames, handler?: EventHandler): void; + off(events: EventNames, handler?: EventHandler): this; + unbind(events: EventNames, handler?: EventHandler): this; + unlisten(events: EventNames, handler?: EventHandler): this; + removeListener(events: EventNames, handler?: EventHandler): this; /** * Trigger one or more events on the layout. @@ -4711,7 +4713,7 @@ declare namespace cytoscape { * @param events A space separated list of event names to trigger. * @param extraParams [optional] An array of additional parameters to pass to the handler. */ - trigger(events: EventNames, extraParams?: any[]): void; + trigger(events: EventNames, extraParams?: any[]): this; } /** @@ -4732,7 +4734,7 @@ declare namespace cytoscape { * If the animation is complete, it restarts from the beginning. * http://js.cytoscape.org/#ani.play */ - play(): void; + play(): this; /** * Get whether the animation is currently playing. * http://js.cytoscape.org/#ani.playing