UNPKG

gojs

Version:

Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams

1,308 lines (1,303 loc) 1.32 MB
/* * Type definitions for GoJS v2.1.18 * Project: https://gojs.net * Definitions by: Northwoods Software <https://github.com/NorthwoodsSoftware> * Definitions: https://github.com/NorthwoodsSoftware/GoJS * Copyright (C) 1998-2020 by Northwoods Software Corporation. * This requires TypeScript v2.8 or later. */ // UMD. For ES6, use go-module.d.ts export as namespace go; /** * The ObjectData type is the same as `{ [index: string]: any; }`. * This is to ease writing `someDataObject.anyPropertyName`, * when dealing with arbitrary JavaScript Objects used as model data. * @category Type */ export interface ObjectData { [index: string]: any; } /** * Undocumented * @unrestricted */ export class EnumValue { /** * @param {function()} classfunc * @param {string} name * @param {number} val */ constructor(classfunc: Function, name: string, val: number); /** */ readonly classType: Function; /** */ readonly name: string; } /** * This interface is implemented by the List, Set, and Map * classes; it provides the #iterator read-only property that returns an Iterator. * * Typical usage is: * ```js * var it = anIterableCollection.iterator; * while (it.next()) { * var item = it.value; * } * ``` * @interface * @template T * @category Collection */ export interface Iterable<T> { /** * Gets an Iterator that can iterate over the items in the collection. * * Typical usage is: * ```js * var it = anIterableCollection.iterator; * while (it.next()) { * var item = it.value; * } * ``` * @return {Iterator.<T>} */ iterator: Iterator<T>; /** * Returns the first item in the list, or null if there is none. * @return {T|null} This returns null if there are no items in the list. */ first(): T | null; /** * This read-only property is the number of elements in the collection. */ readonly count: number; } /** * This interface defines properties and methods for iterating over a collection; * it provides the #next predicate and the #value read-only property. * Some Iterators also provide `key` property values along with each `value`. * * Typical usage is: * ```js * var it = anIterableCollection.iterator; * while (it.next()) { * var item = it.value; * } * ``` * * Many iterators will signal an error if #next is called * after the underlying collection has been modified. * * To avoid confusion when dealing with Iterables, * iterators implement the Iterable#iterator property * by just returning themselves. * @interface * @template T * @extends {Iterable.<T>} * @category Collection */ export interface Iterator<T> extends Iterable<T> { /** * Returns itself, which is convenient for code that expects an Iterable * instead of an Iterator. * @return {Iterator.<T>} */ iterator: Iterator<T>; /** * Call this method to advance the iterator to the next item in the collection. * This should be called before accessing any #value. * @return {boolean} whether another item is available; when true the value of #value will be that item. */ next(): boolean; /** * Call this method to advance the iterator to the next item in the collection. * This should be called before accessing any #value. * @return {boolean} whether another item is available; when true the value of #value will be that item. */ hasNext(): boolean; /** * Advance if needed to the first item in the collection and return it, or return null if there is none. * * Caution: this returns a *key/value pair*, not a *value*, for Map iterators. * @return {T|null} * @since 1.1 */ first(): T | null; /** * Start this iterator all over again. */ reset(): void; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each item in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * * This automatically #reset's itself when it is called. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {boolean} True if any predicate call is true; false otherwise. * @since 1.4 */ any(pred: (x: T) => boolean): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each item in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * * This automatically #reset's itself when it is called. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {boolean} True if all predicate calls are true; false otherwise. * @since 1.4 */ all(pred: (x: T) => boolean): boolean; /** * Call the given function on each item in the collection. * * This automatically #reset's itself when it is called. * @expose * @param {function(T)} func This function must not modify the collection. * @return {Iterator} this iterator itself * @since 1.4 */ each(func: (x: T) => void): void; /** * Call the given function on each item in the collection and present the results in an iterator. * * This automatically #reset's itself when it is called. * @expose * @param {function(T)} func This function must not modify the collection. * @return {Iterator} this */ map<S>(func: (x: T) => S): Iterator<S>; /** * Call the given predicate on each item in the collection and for each item that it returns true, present the item in an iterator. * * This automatically #reset's itself when it is called. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {Iterator.<T>} this */ filter(pred: (x: T) => boolean): Iterator<T>; /** * Gets the current item in the collection, assuming #next has just returned true. */ readonly value: T; /** * Gets the current index to the item in the collection, assuming #next has just returned true. */ readonly key: any; /** * This read-only property is the total number of items in the iterated collection. */ readonly count: number; } /** * Undocumented interface used for both the SVGSurface and the CanvasSurface, which are undocumented classes. */ export interface ISurface { domElement: Element; context: IContext; width: number; height: number; ownerDocument: Document; resize(pixelWidth: number, pixelHeight: number, width: number, height: number): boolean; elementFinished: ((a: GraphObject, b: SVGElement) => void) | null; getBoundingClientRect(): ClientRect | DOMRect; focus(): void; dispose(): void; style: CSSStyleDeclaration; } /** * Undocumented interface used for both the SVGContext and the CanvasSurfaceContext, which are undocumented classes. */ export interface IContext { fillStyle: string | CanvasGradient | CanvasPattern | SGradient; font: string; globalAlpha: number; lineCap: string; lineDashOffset: number; lineJoin: string; lineWidth: number; miterLimit: number; shadowBlur: number; shadowColor: string; shadowOffsetX: number; shadowOffsetY: number; strokeStyle: string | CanvasGradient | CanvasPattern | SGradient; textAlign: string; imageSmoothingEnabled: boolean; clipInsteadOfFill: boolean; setImageSmoothingEnabled(smooth: boolean): void; arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise: boolean, lx?: number, ly?: number): void; beginPath(): void; bezierCurveTo(a: number, b: number, c: number, d: number, e: number, f: number): void; clearRect(x: number, y: number, w: number, h: number): void; clip(): void; closePath(): void; createLinearGradient(aX0: number, aY0: number, aX1: number, aY1: number): CanvasGradient | SGradient; createPattern(image: HTMLCanvasElement | HTMLImageElement, repetition: string): CanvasPattern | string; createRadialGradient(aX0: number, aY0: number, aR0: number, aX1: number, aY1: number, aR1: number): CanvasGradient | SGradient; drawImage(src: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement, sx: number, sy: number, sw?: number, sh?: number, dx?: number, dy?: number, dw?: number, dh?: number): void; fill(): void; fillRect(x: number, y: number, w: number, h: number): void; fillText(str: string, x: number, y: number): void; getImageData(x: number, y: number, w: number, h: number): ImageData; lineTo(x: number, y: number): void; measureText(text: string): TextMetrics; moveTo(x: number, y: number): void; quadraticCurveTo(a: number, b: number, c: number, d: number): void; rect(x: number, y: number, w: number, h: number): void; restore(): void; rotate(angle: number): void; save(): void; setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void; scale(x: number, y: number): void; stroke(): void; transform(a: number, b: number, c: number, d: number, e: number, f: number): void; translate(x: number, y: number): void; fillContext(brush: BrushLike): void; strokeContext(): void; shadowsSet(x: number, y: number, blur: number): void; shadowsOff(): void; shadowsOn(): void; enableDash(strokeDashArray: Array<number>, strokeDashOffset: number): void; disableDash(): void; clearContextCache(clearFont: boolean): void; } /** * <span style="color: red; font-weight: bold;">NOTE: For 2.0 the #constructor argument has changed. * List now optionally accepts a collection, and only checks types in TypeScript.</span> * * An ordered iterable collection. * In TypeScript it is a generic class that enforces at compile-time the type of elements that may be added to the List. * * An example usage: * ```js * var list = new go.List(); // or in TypeScript: new go.List<go.Point>(); * list.add(new go.Point(0, 0)); * list.add(new go.Point(20, 10)); * list.add(new go.Point(10, 20)); * // now list.length === 3 * // and list.elt(1) instanceof go.Point * ``` * * You can iterate over the items in a List: * ```js * var it = aList.iterator; * while (it.next()) { * console.log("#" + it.key + " is " + it.value); * } * ``` * Or: * ```js * aList.each(function(val) { * console.log(val); * }); * ``` * The key will range from zero to #count-1. * * For convenience this **GoJS** List class has synonyms for the following methods and property: * - **get(idx)**: #elt * - **set(idx,val)**: #setElt * - **has(val)**: #contains * - **delete(val)**: #remove * - **clear()**: #clear * - **size**: #count * * The constructor now takes an optional Iterable or Array argument that provides the initial elements for the new List. * * Note that GoJS iteration is quite different than ES6 iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ES6 collection classes were proposed. * @template T * @implements {Iterable.<T>} * @unrestricted * @category Collection */ export class List<T> implements Iterable<T> { /** * There are two possible constructors: * * `new go.List()`, for JavaScript * * `new go.List<type>()` for TypeScript, to enforce type checking. * * Typical usage would be something like: * ```js * var list = new go.List(); // keep a list of GraphObjects * ``` * @param {Iterable.<T>|Array.<T>=} coll an optional collection of items to add. */ constructor(coll?: Iterable<T> | Array<T>); /** * @return {string} */ toString(): string; /** * Adds a given value to the end of the List. * * Be careful not to call this method while iterating over the collection. * @param {*} val * @return {List.<T>} This modified List. */ add(val: T): List<T>; /** * Adds a given value to the end of the List. * * Be careful not to call this method while iterating over the collection. * @param {*} val */ push(val: T): void; /** * Adds all of the values of a collection to the end of this List. * * Be careful not to call this method while iterating over the collection. * @param {Iterable.<T>|Array.<T>} coll the collection of items to add. * @return {List.<T>} This modified List. */ addAll(coll: Iterable<T> | Array<T>): List<T>; /** * Clears the List. * This sets the #count to zero. * * Be careful not to call this method while iterating over the collection. */ clear(): void; /** * Returns whether the given value is in this List. * @param {T} val The value to check. * @return {boolean} Whether or not the value is contained within the List. */ contains(val: T): boolean; /** * Returns whether the given value is in this List. * @param {T} val The value to check. * @return {boolean} Whether or not the value is contained within the List. */ has(val: T): boolean; /** * Returns the index of the given value if it is in this List. * @param {T} val The value to check. * @return {number} int returns -1 if the value is not in this list. */ indexOf(val: T): number; /** * Returns the element at the given index. * @param {number} i int The index of the element to return. * @return {T} the value at the given index. */ elt(i: number): T; /** * Returns the element at the given index. * @param {number} i int The index of the element to return. * @return {T} the value at the given index. */ get(i: number): T; /** * Set the element at the given index to a given value. * @param {number} i int The index of the element to set. * @param {T} val The value to set at the index. */ setElt(i: number, val: T): void; /** * Set the element at the given index to a given value. * @param {number} i int The index of the element to set. * @param {T} val The value to set at the index. */ set(i: number, val: T): void; /** * Returns the first item in the list, or null if there is none. * @return {T|null} This returns null if there are no items in the list. */ first(): T | null; /** * Returns the last item in the list, or null if these is none. * @return {T|null} This returns null if there are no items in the list. * @since 1.5 */ last(): T | null; /** * Returns the last item in the list and removes it from the list, or just return null if these is none. * Use #add to push an item onto the end of the list. * Use #last to get the last item without reducing the length of the list. * @return {T|null} This returns null if there are no items in the list. * @since 1.5 */ pop(): T | null; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each item in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {boolean} True if any predicate call is true; false otherwise. * @since 1.4 */ any(pred: ((a: T) => boolean)): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each item in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {boolean} True if all predicate calls are true; false otherwise. * @since 1.4 */ all(pred: ((a: T) => boolean)): boolean; /** * Call the given function on each item in the collection. * @expose * @param {function(T)} func This function must not modify the collection. * @return {List.<T>} This List itself * @since 1.4 */ each(func: ((a: T) => void)): List<T>; /** * Call the given function on each item in the collection and collect the results in a new List. * * Unlike Iterator#map, this returns a List, not an Iterator. * @expose * @param {function(T):*} func This function must not modify the collection. * @return {List.<S>} */ map<S>(func: ((a: T) => S)): List<S>; /** * Call the given predicate on each item in the collection and for each item that it returns true, collect the item in a new List. * * Unlike Iterator#filter, this returns a List, not an Iterator. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {List.<T>} */ filter(pred: ((a: T) => boolean)): List<T>; /** * Insert a value before the index i. * * Be careful not to call this method while iterating over the collection. * @param {number} i int The index to insert before. * @param {T} val The value to insert. */ insertAt(i: number, val: T): void; /** * Removes a given value (if found) from the List. * * Be careful not to call this method while iterating over the collection. * @param {T} val The value to remove. * @return {boolean} true if the value was found and removed, false otherwise. */ remove(val: T): boolean; /** * Removes a given value (if found) from the List. * * Be careful not to call this method while iterating over the collection. * @param {T} val The value to remove. * @return {boolean} true if the value was found and removed, false otherwise. */ delete(val: T): boolean; /** * Removes a value at a given index from the List. * * Be careful not to call this method while iterating over the collection. * @param {number} i int The index to remove. */ removeAt(i: number): void; /** * Removes a range of values from the List, given both the starting and the ending zero-based indexes. * For example, * ```js * list.removeRange(2, 4) * ``` * will remove elements 2, 3, and 4 from the list. * If there were two or fewer elements in the list to begin with, the list is unchanged. * If *from* is greater than *to*, the list is unchanged. * If *from* is greater than or equal to the length, the list is unchanged. * If *to* is less than zero, the list is unchanged. * * Be careful not to call this method while iterating over the collection. * @param {number} from int The starting index of the range to remove, inclusive; negative values are treated as zero * @param {number} to int The ending index of the range to remove, inclusive; values greater than the length of the list are treated as referring to the last element * @return {List.<T>} This modified List */ removeRange(from: number, to: number): List<T>; /** * Makes a shallow copy of this List. * The values are not copied, * so if they are objects they may continue to be shared with the original List. * @expose * @return {List.<T>} The new List with the same elements. */ copy(): List<T>; /** * Produces a JavaScript Array from the contents of this List. * @return {Array.<T>} A copy of the List in Array form. */ toArray(): Array<T>; /** * Converts the List to a Set. * The count of the resulting Set may be less than the count of this List * if any duplicates were removed. * @return {Set.<T>} A copy of the contents of this List, * but with duplicates removed and ordering lost. */ toSet(): Set<T>; /** * Sort the List according to a comparison function. * @param {function(T,T):number} sortfunc This function is passed two items in the list. * It should return zero if they are equal, * less than zero if the first value should come before the second value, * or greater than zero if the first value should come after the second value. * @return {List.<T>} This modified List. */ sort(sortfunc: ((a: T, b: T) => number)): List<T>; /** * Undocumented * @param {function(*,*):number} sortfunc This function is passed two elements in the list. * It should return zero if they are equal, * less than zero if the first value should come before the second value, * or greater than zero if the first value should come after the second value. * @param {number=} from int The optional index at which to start the sort, including that element; * default to zero, the first element of the list. * @param {number=} to int The optional index at which to end the sort, excluding that element; * defaults to the end of the list. * @return {List.<T>} This modified List. */ sortRange(sortfunc: ((a: T, b: T) => number), from?: number, to?: number): List<T>; /** * Reverse the order of items in this List. * @return {List.<T>} This modified List. */ reverse(): List<T>; /** * This read-only property is the length of the List. */ readonly count: number; /** * This read-only property is the length of the List. */ readonly size: number; /** * This read-only property is the length of the List, a synonym for the #count property. */ readonly length: number; /** * Gets an object that you can use for iterating over the List. * The key will be an integer from zero to the count-1. * The value will be the item at that index in the list. * Typical usage: * ```js * var it = aList.iterator; * while (it.next()) { * . . . "index: " + it.key + " value: " + it.value . . . * } * ``` */ readonly iterator: Iterator<T>; /** * Gets an object that you can use for iterating over the List in backwards order. * The key will be an integer from count-1 to zero. * The value will be the item at that index in the list. * The list is not modified by traversing in reverse order. * Typical usage: * ```js * var it = aList.iteratorBackwards; * while (it.next()) { * . . . 'key: ' + it.key + ' value: ' + it.value . . . * } * ``` */ readonly iteratorBackwards: Iterator<T>; } /** * <span style="color: red; font-weight: bold;">NOTE: For 2.0 the #constructor argument has changed. * Set now optionally accepts a collection, and only checks types in TypeScript.</span> * * An unordered iterable collection that cannot contain two instances of the same value. * In TypeScript it is a generic class that enforces at compile-time the type of elements that may be added to the Set. * * An example usage: * ```js * var set = new go.Set(); // In TypeScript: new go.Set<string>(); * set.add("orange"); * set.add("apple"); * set.add("orange"); * // now set.count === 2 * // and set.contains("orange") === true * // and set.contains("banana") === false * ``` * * You can iterate over the items in a Set: * ```js * var it = aSet.iterator; * while (it.next()) { * . . . it.value . . . * } * ``` * Or: * ```js * aSet.each(function(val) { * . . . val . . . * }); * ``` * * Although not precisely implementing the features of the EcmaScript 6 **Set** class, * this **GoJS** Set class has synonyms for the following methods and property: * - **add(val)**: #add * - **delete(val)**: #remove * - **has(val)**: #contains * - **clear()**: #clear * - **size**: #count * * The constructor now takes an optional Iterable or Array argument that provides the initial elements for the new Set. * * Note that GoJS iteration is quite different than ES6 iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ES6 collection classes were proposed. * @template T * @implements {Iterable.<T>} * @unrestricted * @category Collection */ export class Set<T> implements Iterable<T> { /** * There are two possible constructors: * * `new go.Set()`, for JavaScript * * `new go.Set<T>()` for TypeScript * * In TypeScript, the optional generic argument describes the type of values * that this Set may hold. * * For example, the expression: * ```js * // TypeScript: * new go.Set<go.Point>() * ``` * * Creates a new Set that may only contain Points. * * @param {Iterable.<T>|Array.<T>=} coll an optional collection of items to add. */ constructor(coll?: Iterable<T> | Array<T>); /** * @return {string} */ toString(): string; /** * Adds a given value to the Set, if not already present. * * Be careful not to call this method while iterating over the collection. * @param {T} val The value to add to the Set; must not be null. * @return {Set.<T>} This modified Set. */ add(val: T): Set<T>; /** * Adds all of the values of a collection to this Set. * * Be careful not to call this method while iterating over the collection. * @param {Iterable.<T>|Array.<T>} coll the collection of items to add. * @return {Set.<T>} This modified Set. */ addAll(coll: Iterable<T> | Array<T>): Set<T>; /** * Returns whether the given value is in this Set. * @param {T} val The value to check. * @return {boolean} Whether or not the value is contained within the Set. */ contains(val: T): boolean; /** * Returns whether the given value is in this Set. * @param {T} val The value to check. * @return {boolean} Whether or not the value is contained within the Set. */ has(val: T): boolean; /** * Returns true if all of the values of a given collection are in this Set. * @param {Iterable.<T>} coll the collection of items to check for. * @return {boolean} */ containsAll(coll: Iterable<T>): boolean; /** * Returns true if any of the values of a given collection are in this Set. * @param {Iterable.<T>} coll the collection of items to check for. * @return {boolean} */ containsAny(coll: Iterable<T>): boolean; /** * Returns the first item in the collection, or null if there is none. * @return {T|null} This returns null if there are no items in the collection. */ first(): T | null; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each item in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {boolean} True if any predicate call is true; false otherwise. * @since 1.4 */ any(pred: ((a: T) => boolean)): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each item in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {boolean} True if all predicate calls are true; false otherwise. * @since 1.4 */ all(pred: ((a: T) => boolean)): boolean; /** * Call the given function on each item in the collection. * @expose * @param {function(T)} func This function must not modify the collection. * @return {Set.<T>} This Set itself. * @since 1.4 */ each(func: ((a: T) => void)): Set<T>; /** * Call the given function on each item in the collection and collect the results in a new Set. * * Unlike Iterator#map, this returns a Set, not an Iterator. * @expose * @param {function(T):*} func This function must not modify the collection. * @return {Set.<S>} */ map<S>(func: ((a: T) => S)): Set<S>; /** * Call the given predicate on each item in the collection and for each item that it returns true, collect the item in a new Set. * * Unlike Iterator#filter, this returns a Set, not an Iterator. * @expose * @param {function(T):boolean} pred This function must not have any side-effects. * @return {Set.<T>} */ filter(pred: ((a: T) => boolean)): Set<T>; /** * Removes a value (if found) from the Set. * * Be careful not to call this method while iterating over the collection. * @param {T} val The value to remove. * @return {boolean} true if the value was found and removed, false otherwise. */ remove(val: T): boolean; /** * Removes a value (if found) from the Set. * * Be careful not to call this method while iterating over the collection. * @param {T} val The value to insert. * @return {boolean} true if the value was found and removed, false otherwise. */ delete(val: T): boolean; /** * Removes all of the values of a collection from this Set. * * Be careful not to call this method while iterating over the collection. * @param {Iterable.<T>|Array.<T>} coll the collection of items to remove. * @return {Set.<T>} This modified Set. */ removeAll(coll: Iterable<T> | Array<T>): Set<T>; /** * Removes from this Set all items that are not in the given collection. * * Be careful not to call this method while iterating over the collection. * @param {Iterable.<T>} coll the collection of items that should be kept in this Set. * @return {Set.<T>} This modified Set. */ retainAll(coll: Iterable<T>): Set<T>; /** * Clears the Set. * This sets the #count to zero. * * Be careful not to call this method while iterating over the collection. */ clear(): void; /** * Makes a shallow copy of this Set. * The values are not copied, * so if they are objects they may continue to be shared with the original Set. * @expose * @return {Set.<T>} The new Set with the same elements. */ copy(): Set<T>; /** * Produces a JavaScript Array from the contents of this Set. * @return {Array.<T>} A copy of the Set in Array form. */ toArray(): Array<T>; /** * Converts the Set to a List. * Because there is no ordering within a Set, * the values in the List may be in any order. * @return {List.<T>} A copy of the contents of this Set in List form. */ toList(): List<T>; /** * This read-only property is the number of elements in the Set. */ readonly count: number; /** * This read-only property is the number of elements in the Set. */ readonly size: number; /** * Gets an object that you can use for iterating over the Set. * The value will be a member of the Set. * Typical usage: * ```js * var it = aSet.iterator; * while (it.next()) { * . . . " value: " + it.value . . . * } * ``` */ readonly iterator: Iterator<T>; /** * Undocumented. * Set the unique hash ID for an object. * This should be called at the beginning of each constructor that does not inherit from another class. */ static uniqueHash(obj: ObjectData): void; /** * Undocumented. * Get the unique hash ID for an object, making it if necessary. */ static hashIdUnique(obj: ObjectData): number; /** * Undocumented. * Get the unique hash ID for an object; may return undefined. */ static hashId(obj: ObjectData): number | undefined; } /** * Undocumented * @template K,V * @unrestricted */ export class KeyValuePair<K, V> { /** * @param {K} k * @param {V} v */ constructor(k: K, v: V); /** * @return {string} */ toString(): string; /** * Gets a key for a value in a Map. * @return {K} the key uniquely identifying a #value in a Map. */ key: K; /** * Gets a value in a Map. * @return {V} a value in a Map corresponding to a #key. */ value: V; } /** * Undocumented. * Iterating over Maps is very similar to an Iterator<KeyValuePair<K, V>>, * but not exactly, because the type of the value property is V, not KeyValuePair<K, V>. */ export interface IMapIterator<K, T> { /** @hidden */ iterator: IMapIterator<K, T>; /** @hidden */ next(): boolean; /** @hidden */ hasNext(): boolean; /** @hidden */ first(): KeyValuePair<K, T> | null; /** @hidden */ reset(): void; /** @hidden */ any(pred: (x: KeyValuePair<K, T>) => boolean): boolean; /** @hidden */ all(pred: (x: KeyValuePair<K, T>) => boolean): boolean; /** @hidden */ each(func: (x: KeyValuePair<K, T>) => void): IMapIterator<K, T>; /** @hidden */ map<S>(func: (x: KeyValuePair<K, T>) => S): Iterator<S>; /** @hidden */ filter(pred: (x: KeyValuePair<K, T>) => boolean): Iterator<KeyValuePair<K, T>>; /** @hidden */ readonly key: K; /** @hidden */ readonly value: T; /** @hidden */ readonly count: number; } /** * <span style="color: red; font-weight: bold;">NOTE: For 2.0 the #constructor arguments have changed. * Map now optionally accepts a collection, and only checks types in TypeScript.</span> * * An unordered iterable collection of key/value pairs that cannot contain two instances of the same key. * In TypeScript it is a generic class that enforces at compile-time the type of the key and the type of the associated value. * * To create a Map: * ```js * var map = new go.Map(); // In TypeScript: new go.Map<string, number>(); * map.add("one", 1); * map.add("two", 2); * map.add("three", 3); * // now map.count === 3 * // and map.getValue("two") === 2 * // and map.contains("zero") === false * ``` * * You can iterate over the key/value pairs in a Map: * ```js * var it = aMap.iterator; * while (it.next()) { * console.log(it.key + ": " + it.value); * } * ``` * Or: * ```js * aMap.each(function(kvp) { * console.log(kvp.key + ": " + kvp.value); * }); * ``` * But note that there is no guaranteed ordering amongst the key/value pairs. * * Call #toKeySet to get a read-only Set that holds all of the keys of a Map. * Iterating over that Set will produce values that are the keys in the Map. * * Although not precisely implementing the features and semantics of the EcmaScript 6 **Map** class, * this **GoJS** Map class has synonyms for the following methods and property: * - **get(key)**: #getValue, but returns null instead of undefined when key is not present * - **set(key,val)**: #add * - **has(key)**: #contains * - **delete(key)**: #remove * - **clear()**: #clear * - **size**: #count * * The constructor now takes an optional Iterable or Array argument that provides the initial entries for the new Map. * * Note that GoJS iteration is quite different than ES6 iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ES6 collection classes were proposed. * @template K, V * @unrestricted * @category Collection */ export class Map<K, V> { /** * There are two possible constructors: * * `new go.Map()`, for JavaScript * * `new go.Map<K, V>()` for TypeScript * * In TypeScript, the two optional generic arguments describe the types of keys * and the types of values that this Map may hold. * * For example, the expression: * ```js * // TypeScript: * new go.Map<string, go.Point>() * ``` * produces a Map that has keys that must be strings and whose associated values * must be Points. * @param {Iterable.<KeyValuePair.<K,V>>|Array.<KeyValuePair.<K,V>>=} coll an optional collection of keys/values to add, or an Array of { key: ..., value: ... } objects. * Note that the key/value pairs are objects with "key" and "value" properties, not Arrays of length 2. */ constructor(coll?: Iterable<KeyValuePair<K, V>> | Array<KeyValuePair<K, V>> | Map<K, V>); /** * @return {string} */ toString(): string; /** * Adds a key-value association to the Map, or replaces the value associated with the key * if the key was already present in the map. * * Be careful not to call this method while iterating over the collection. * @param {K} key The key or index for storing the value in the Map. * @param {V} val The value to add to the Map, associated with the key. * @return {Map.<K,V>} This modified Map. */ add(key: K, val: V): Map<K, V>; /** * Adds a key-value association to the Map, or replaces the value associated with the key * if the key was already present in the map. * * Be careful not to call this method while iterating over the collection. * @param {K} key The key or index for storing the value in the Map. * @param {V} val The value to add to the Map, associated with the key. * @return {Map.<K,V>} This modified Map. */ set(key: K, val: V): Map<K, V>; /** * Adds all of the key-value pairs of another Map to this Map. * If a key is already present in this Map, * its value is replaced with the corresponding value from the given map. * * Be careful not to call this method while iterating over the collection. * @param {Iterable.<KeyValuePair.<K,V>>|Array.<KeyValuePair.<K,V>>} coll the collection of keys/values to add, or an Array of { key: ..., value: ... } objects. * @return {Map.<K,V>} This modified Map. */ addAll(coll: Iterable<KeyValuePair<K, V>> | Array<KeyValuePair<K, V>> | Map<K, V>): Map<K, V>; /** * Returns the first key/value pair in the collection, or null if there is none. * @return {KeyValuePair.<K,V>} This returns null if there are no items in the collection. * @since 1.4 */ first(): KeyValuePair<K, V>; /** * This is true if any invocation of the given predicate on items in the collection is true. * * Call the given predicate on each key/value pair in the collection. * As soon as a call returns true, this returns true. * Otherwise this returns false. * For an empty collection this returns false. * @expose * @param {function(KeyValuePair.<K,V>):boolean} pred The argument to the predicate will be an object with both "key" and "value" properties. * This function must not have any side-effects. * @return {boolean} True if any predicate call is true; false otherwise. * @since 1.4 */ any(pred: ((a: KeyValuePair<K, V>) => boolean)): boolean; /** * This is true if all invocations of the given predicate on items in the collection are true. * * Call the given predicate on each key/value pair in the collection. * As soon as a call returns false, this returns false. * Otherwise this returns true. * For an empty collection this returns true. * @expose * @param {function(KeyValuePair.<K,V>):boolean} pred The argument to the predicate will be an object with both "key" and "value" properties. * This function must not have any side-effects. * @return {boolean} True if all predicate calls are true; false otherwise. * @since 1.4 */ all(pred: ((a: KeyValuePair<K, V>) => boolean)): boolean; /** * Call the given function on each key/value pair in the collection. * @expose * @param {function(KeyValuePair.<K,V>)} func The argument to the function will be an object with both "key" and "value" properties. * This function must not modify the collection. * @return {Map.<K,V>} This Map itself * @since 1.4 */ each(func: ((a: KeyValuePair<K, V>) => void)): Map<K, V>; /** * Call the given function on each key-value pair in the collection and associate the key with the result of the function in a new Map. * * Unlike Iterator#map, this returns a Map, not an Iterator. * @expose * @param {function(KeyValuePair.<K,V>):*} func The argument to the function will be an object with both "key" and "value" properties. * This function must not modify the collection. * @return {Map.<K,S>} a new Map with the same keys but values produced by the function */ map<S>(func: ((a: KeyValuePair<K, V>) => S)): Map<K, S>; /** * Call the given predicate on each key-value pair in the collection and for each pair that it returns true, add the key-value association in a new Map. * * Unlike Iterator#filter, this returns a Map, not an Iterator. * @expose * @param {function(KeyValuePair.<K,V>):boolean} pred This function must not have any side-effects. * @return {Map.<K,V>} */ filter(pred: ((a: KeyValuePair<K, V>) => boolean)): Map<K, V>; /** * Returns whether the given key is in this Map. * @param {K} key The key to look up in the Map. * @return {boolean} Whether or not the key is contained within the Map. */ contains(key: K): boolean; /** * Returns whether the given key is in this Map. * @param {K} key The key to look up in the Map. * @return {boolean} Whether or not the key is contained within the Map. */ has(key: K): boolean; /** * Returns the value associated with a key. * @param {K} key The key to look up in the Map. * @return {V|null} The value associated with the given key, or null if not present in the Map. */ getValue(key: K): V | null; /** * Returns the value associated with a key. * @param {K} key The key to look up in the Map. * @return {V|null} The value associated with the given key, or null if not present in the Map. */ get(key: K): V | null; /** * Removes a key (if found) from the Map. * * Be careful not to call this method while iterating over the collection. * @param {K} key The key to remove. * @return {boolean} true if the key was found and removed, false otherwise. */ remove(key: K): boolean; /** * Removes a key (if found) from the Map. * * Be careful not to call this method while iterating over the collection. * @param {K} key The key to insert. * @return {boolean} true if the key was found and removed, false otherwise. */ delete(key: K): boolean; /** * Clears the Map, removing all key-value associations. * This sets the #count to zero. * * Be careful not to call this method while iterating over the collection. */ clear(): void; /** * Makes a shallow copy of this Map. * The keys and their values are not copied, * so if they are objects they may continue to be shared with the original Map. * @expose * @return {Map.<K,V>} The new Map with copies of the same entries. */ copy(): Map<K, V>; /** * Produces a JavaScript Array of key/value pair objects from the contents of this Map. * @return {Array.<KeyValuePair.<K,V>>} A copy of the Map in Array form, * each element being an Object with 'key' and 'value' properties. */ toArray(): Array<KeyValuePair<K, V>>; /** * Produces a Set that provides a read-only view onto the keys of this Map. * The collection of keys is not copied. * @return {Set.<K>} */ toKeySet(): Set<K>; /** * This read-only property is the number of associations in the Map. */ readonly count: number; /** * This read-only property is the number of associations in the Map. */ readonly size: number; /** * Gets an object that you can use for iterating over the key-value pairs of a Map. * Typical usage: * ```js * var it = aMap.iterator; * while (it.next()) { * console.log("the key: " + it.key + " has value: " + it.value); * } * ``` */ readonly iterator: IMapIterator<K, V>; /** * Gets an object that you can use for iterating over the keys of a Map. * Typical usage: * ```js * var it = aMap.iteratorKeys; * while (it.next()) { * console.log("key: " + it.value); * } * ``` * @since 1.4 */ readonly iteratorKeys: Iterator<K>; /** * Gets an object that you can use for iterating over the values of a Map. * Typical usage: * ```js * var it = aMap.iteratorValues; * while (it.next()) { * console.log("value: " + it.value); * } * ``` * @since 1.4 */ readonly iteratorValues: Iterator<V>; } /** * A Point represents an x- and y-coordinate pair in two-dimensional space. * * Use the static functions Point.parse and Point.stringify to convert to and from * a standard string representation that is independent of the current locale. * * When an instance of this class is the value of a property of a GraphObject class or Diagram * or CommandHandler or a Tool class, you should treat the object * as if it were frozen or read-only -- you cannot modify its properties. * This allows the property to return a value without allocating a new instance. * If you need to do your own calculations with the value, call #copy to make * a new instance with the same values that you can modify. * * Many methods modify the object's properties and then return a reference to "this" object. * The only instance method to allocate a new object is the #copy method. * The static Point.parse method also allocates a new object. * * The "Debug" implementation of this class is significantly slower than the "Release" implementation, * mostly due to additional error checking. * * You cannot inherit from this class. * @category Geometry */ export class Point { /** * The default constructor produces the Point(0,0). * This constructor may take either zero arguments or two arguments. * @param {number=} x The x value. * @param {number=} y The y value. */ constructor(x?: number, y?: number); /** * Modify this Point with new X and Y values. * @param {number} x * @param {number} y * @return {Point} this. */ setTo(x: number, y: number): Point; /** * Modify this Point so that its X and Y values are the same as the given Point. * @param {Point} p the given Point. * @return {Point} this. */ set(p: Point): Point; /** * Create a copy of this Point, with the same values. * @expose * @return {Point} */ copy(): Point; /** * This static function can be used to read in a Point from a string that was produced by Point.stringify. * * `go.Point.parse("1 2")` produces the Point `new go.Point(1, 2)`. * @param {string} str * @return {Point} */ static parse(str: string): Point; /** * This static function can be used to write out a Point as a string that can be read by Point.parse. * * `go.Point.stringify(new go.Point(1, 2))` produces the string "1 2". * @param {Point} val * @return {string} */ static stringify(val: Point): string; /** * Indicates whether the given Point is equal to this Point. * @param {Point} p The Point to compare to the current Point. * @return {boolean} True if the two Points have identical X and Y values, * fal