UNPKG

gojs

Version:

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

1,325 lines (1,321 loc) 1.56 MB
/* * Type definitions for GoJS v3.0.21 * Project: https://gojs.net * Definitions by: Northwoods Software <https://github.com/NorthwoodsSoftware> * Definitions: https://github.com/NorthwoodsSoftware/GoJS * Copyright 1998-2025 by Northwoods Software Corporation. * This requires TypeScript v2.8 or later. */ 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 Model */ export interface ObjectData { [index: string]: any; } /** * This interface is implemented by the {@link List}, {@link Set}, and {@link Map} * classes; it provides the {@link iterator} read-only property that returns an {@link Iterator}. * * Typical usage is: * ```js * const it = anIterableCollection.iterator; * while (it.next()) { * const item = it.value; * } * ``` * @category Collection */ export interface Iterable<T> { /** * Gets an {@link Iterator} that can iterate over the items in the collection. * * Typical usage is: * ```js * const it = anIterableCollection.iterator; * while (it.next()) { * const item = it.value; * } * ``` */ iterator: Iterator<T>; [Symbol.iterator](): IterableIterator<T>; /** * Returns the first item in the list, or null if there is none. * @returns 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 {@link next} predicate and the {@link value} read-only property. * Some Iterators also provide `key` property values along with each `value`. * * Typical usage is: * ```js * const it = anIterableCollection.iterator; * while (it.next()) { * const item = it.value; * } * ``` * * It is an error if {@link next} is called * after the underlying collection has been modified. * * To avoid confusion when dealing with {@link Iterable}s, * iterators implement the {@link Iterable.iterator} property * by just returning themselves. * @category Collection */ export interface Iterator<T> extends Iterable<T> { /** * Returns itself, which is convenient for code that expects an {@link Iterable} * instead of an {@link Iterator}. */ iterator: Iterator<T>; /** * Call this method to advance the iterator to the next item in the collection. * This should be called before accessing any {@link value}. * @returns whether another item is available; when true the value of {@link 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 {@link value}. * @returns whether another item is available; when true the value of {@link 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 {@link Map} iterators. */ 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 {@link reset}'s itself when it is called. * @virtual * @param pred - This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ 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 {@link reset}'s itself when it is called. * @virtual * @param pred - This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: (x: T) => boolean): boolean; /** * Call the given function on each item in the collection. * * This automatically {@link reset}'s itself when it is called. * @virtual * @param func - This function must not modify the collection. * @returns this iterator itself */ 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 {@link reset}'s itself when it is called. * @virtual * @param func - This function must not modify the collection. * @returns 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 {@link reset}'s itself when it is called. * @virtual * @param pred - This function must not have any side-effects. * @returns this */ filter(pred: (x: T) => boolean): Iterator<T>; /** * Gets the current item in the collection, assuming {@link next} has just returned true. */ readonly value: T; /** * Gets the current index to the item in the collection, assuming {@link 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; } /** * This interface defines properties and methods for iterating over a {@link Map}; * it provides the {@link next} predicate and the {@link key} and {@link value} read-only properties. * * Iterating over Maps is very similar to an {@link Iterator}<{@link IKeyValuePair}>, * but not exactly, because the type of the value property is T, not an {@link IKeyValuePair}. * * Typical usage is: * ```js * const it = aMap.iterator; * while (it.next()) { * const key = it.key; * const val = it.value; * } * ``` * @see {@link Iterator} * @category Collection */ export interface IMapIterator<K, T> { /** {@inheritDoc Iterator.iterator} */ iterator: IMapIterator<K, T>; /** {@inheritDoc Iterator.next} */ next(): boolean; /** * {@inheritDoc Iterator.hasNext} */ hasNext(): boolean; /** * Advance if needed to the first item in the collection and return it, or return null if there is none. * Returns a *key/value pair*, not a *value*. */ first(): IKeyValuePair<K, T> | null; /** {@inheritDoc Iterator.reset} */ reset(): void; /** {@inheritDoc Iterator.any} */ any(pred: (x: IKeyValuePair<K, T>) => boolean): boolean; /** {@inheritDoc Iterator.all} */ all(pred: (x: IKeyValuePair<K, T>) => boolean): boolean; /** {@inheritDoc Iterator.each} */ each(func: (x: IKeyValuePair<K, T>) => void): IMapIterator<K, T>; /** * {@inheritDoc Iterator.map} */ map<S>(func: (x: IKeyValuePair<K, T>) => S): Iterator<S>; /** * {@inheritDoc Iterator.filter} */ filter(pred: (x: IKeyValuePair<K, T>) => boolean): Iterator<IKeyValuePair<K, T>>; /** * Gets the current {@link IKeyValuePair.value|value} in the collection, assuming {@link next} has just returned true. */ readonly value: T; /** * Gets the current {@link IKeyValuePair.key|key} in the collection, assuming {@link next} has just returned true. */ readonly key: K; /** {@inheritDoc Iterator.count} */ readonly count: number; } /** * A (key, value) pair, used in {@link Map}s. * @category Collection */ export interface IKeyValuePair<K, V> { /** * Gets a key for a value in a {@link Map}. * @returns the key uniquely identifying a {@link value} in a {@link Map}. */ readonly key: K; /** * Gets a value in a {@link Map}. * @returns a value in a {@link Map} corresponding to a {@link key}. */ readonly value: V; } /** * (undocumented) interface used for both the SVGSurface and the CanvasSurface, which are undocumented classes. */ export interface ISurface { width: number; height: number; resize(pixelWidth: number, pixelHeight: number, width: number, height: number): boolean; getBoundingClientRect(): 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; /** Only true if a Spot panel has isClipping element */ clipInsteadOfFill: boolean; filter: string; commitTransform(): void; setImageSmoothingEnabled(smooth: boolean): void; arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise: boolean, lx?: number, ly?: number): void; beginPath(): void; endPath(pathIndex?: number): 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(fillRule: boolean, path: Path2D | null): void; fillRect(x: number, y: number, w: number, h: number): void; fillBackground(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(p?: Path2D): void; transform(a: number, b: number, c: number, d: number, e: number, f: number): void; translate(x: number, y: number): void; fillContext(brush: BrushLike, fillRule: boolean, path: Path2D | null): 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; removePartFromView(p: GraphObject): void; createOrUpdateClipGroup(panel: GraphObject, rect: Rect): void; } /** * 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 * const 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 * const it = aList.iterator; * while (it.next()) { * console.log("#" + it.key + " is " + it.value); * } * ``` * Or: * ```js * aList.each(val => { * console.log(val); * }); * ``` * The key will range from zero to {@link count}-1. * * For convenience this **GoJS** List class has synonyms for the following methods and property: * - **get(idx)**: {@link elt} * - **set(idx,val)**: {@link setElt} * - **has(val)**: {@link has} * - **delete(val)**: {@link delete} * - **clear()**: {@link clear} * - **size**: {@link 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 ECMAScript iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @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 * const list = new go.List(); // keep a list of GraphObjects * ``` * @param coll - an optional collection of items to add. */ constructor(coll?: Iterable<T> | Array<T>); /** * This class implements the JavaScript `Symbol.iterator`, * and can be used with spread syntax or `for ... of` statements. */ [Symbol.iterator](): IterableIterator<T>; /** */ 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 * @returns This modified List. */ add(val: T): this; /** * 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 coll - the collection of items to add. * @returns This modified List. */ addAll(coll: Iterable<T> | Array<T>): this; /** * Clears the List. * This sets the {@link 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 val - The value to check. * @returns Whether or not the value is contained within the List. */ contains(val: T): boolean; /** * Returns whether the given value is in this List. * @param val - The value to check. * @returns 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 val - The value to check. * @returns returns -1 if the value is not in this list. */ indexOf(val: T): number; /** * Returns the element at the given index. * @param i - int The index of the element to return. * @returns the value at the given index. */ elt(i: number): T; /** * Returns the element at the given index. * @param i - int The index of the element to return. * @returns the value at the given index. */ get(i: number): T; /** * Set the element at the given index to a given value. * @param i - int The index of the element to set. * @param 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 i - int The index of the element to set. * @param 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. * @returns 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. * @returns This returns null if there are no items in the list. */ 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 {@link add} to push an item onto the end of the list. * Use {@link last} to get the last item without reducing the length of the list. * @returns This returns null if there are no items in the list. */ 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. * @virtual * @param pred - This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ 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. * @virtual * @param pred - This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: ((a: T) => boolean)): boolean; /** * Call the given function on each item in the collection. * @virtual * @param func - This function must not modify the collection. * @returns This List itself */ each(func: ((a: T) => void)): this; /** * Call the given function on each item in the collection and collect the results in a new List. * * Unlike {@link Iterator.map}, this returns a List, not an Iterator. * @virtual * @param func - This function must not modify the collection. */ 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 {@link Iterator.filter}, this returns a List, not an Iterator. * @virtual * @param pred - This function must not have any side-effects. */ 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 i - int The index to insert before. * @param 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 val - The value to remove. * @returns 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 val - The value to remove. * @returns 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 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 from - int The starting index of the range to remove, inclusive; negative values are treated as zero * @param 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 * @returns This modified List */ removeRange(from: number, to: number): this; /** * 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. * @virtual * @returns The new List with the same elements. */ copy(): List<T>; /** * Produces a JavaScript Array from the contents of this List. * @returns A copy of the List in Array form. */ toArray(): Array<T>; /** * Converts the List to a {@link Set | go.Set}. * The count of the resulting Set may be less than the count of this List * if any duplicates were removed. * @returns 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 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. * @returns This modified List. */ sort(sortfunc: ((a: T, b: T) => number)): this; /** * (undocumented) * Sorts a range of consecutive elements in this List based on the given comparison function. * @param 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 from - int The optional index at which to start the sort, including that element; * default to zero, the first element of the list. * @param to - int The optional index at which to end the sort, excluding that element; * defaults to the end of the list. * @returns This modified List. */ sortRange(sortfunc: ((a: T, b: T) => number), from?: number, to?: number): this; /** * Reverse the order of items in this List. * @returns This modified List. */ reverse(): this; /** * This read-only property is the length of the List. */ get count(): number; /** * This read-only property is the length of the List. */ get size(): number; /** * This read-only property is the length of the List, a synonym for the {@link count} property. */ get 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 * const it = aList.iterator; * while (it.next()) { * . . . "index: " + it.key + " value: " + it.value . . . * } * ``` */ get 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 * const it = aList.iteratorBackwards; * while (it.next()) { * . . . 'key: ' + it.key + ' value: ' + it.value . . . * } * ``` */ get iteratorBackwards(): Iterator<T>; } /** * 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 * const set = new go.Set(); // In TypeScript: new go.Set<string>(); * set.add("orange"); * set.add("apple"); * set.add("orange"); * // now set.size === 2 * // and set.has("orange") === true * // and set.has("banana") === false * ``` * * You can iterate over the items in a Set: * ```js * const it = aSet.iterator; * while (it.next()) { * . . . it.value . . . * } * ``` * Or: * ```js * aSet.each(val => { * . . . val . . . * }); * ``` * * For compatibility with versions of GoJS before version 3.0, the following synonyms are defined: * - **remove(val)**: {@link delete} * - **contains(val)**: {@link has} * - **count**: {@link size} * * 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 ECMAScript iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @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 {@link Point}s. * * @param coll - an optional collection of items to add. */ constructor(coll?: Iterable<T> | Array<T>); /** * This class implements the JavaScript `Symbol.iterator`, * and can be used with spread syntax or `for ... of` statements. * @since 3.0 */ [Symbol.iterator](): IterableIterator<T>; /** * Return a JavaScript iterator that produces the values in this Set. * This does not produce the old GoJS style {@link Iterator} -- * use the {@link iterator} property if you want that. * @since 3.0 */ values(): IterableIterator<T>; /** */ 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 val - The value to add to the Set; must not be null. * @returns This modified Set. */ add(val: T): this; /** * Adds all of the values of a collection to this Set. * * Be careful not to call this method while iterating over the collection. * @param coll - the collection of items to add. * @returns This modified Set. */ addAll(coll: Iterable<T> | Array<T>): this; /** * Returns whether the given value is in this Set. * @param val - The value to check. * @returns Whether or not the value is contained within the Set. */ has(val: T): boolean; /** * Returns whether the given value is in this Set. * @param val - The value to check. * @returns Whether or not the value is contained within the Set. */ contains(val: T): boolean; /** * Returns true if all of the values of a given collection are in this Set. * @param coll - the collection of items to check for. */ containsAll(coll: Iterable<T>): boolean; /** * Returns true if any of the values of a given collection are in this Set. * @param coll - the collection of items to check for. */ containsAny(coll: Iterable<T>): boolean; /** * Returns the first item in the collection, or null if there is none. * @returns 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. * @virtual * @param pred - This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ 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. * @virtual * @param pred - This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: ((a: T) => boolean)): boolean; /** * Call the given function on each item in the collection. * @virtual * @param func - This function must not modify the collection. * @returns This Set itself. */ each(func: ((a: T) => void)): this; /** * Call the given function on each item in the collection and collect the results in a new Set. * * Unlike {@link Iterator.map}, this returns a Set, not an Iterator. * @virtual * @param func - This function must not modify the collection. */ 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 {@link Iterator.filter}, this returns a Set, not an Iterator. * @virtual * @param pred - This function must not have any side-effects. */ 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 val - The value to remove. * @returns true if the value was found and removed, false otherwise. */ delete(val: T): boolean; /** * Removes a value (if found) from the Set. * * Be careful not to call this method while iterating over the collection. * @param val - The value to insert. * @returns true if the value was found and removed, false otherwise. */ remove(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 coll - the collection of items to remove. * @returns This modified Set. */ removeAll(coll: Iterable<T> | Array<T>): this; /** * 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 coll - the collection of items that should be kept in this Set. * @returns This modified Set. */ retainAll(coll: Iterable<T>): this; /** * Clears the Set. * This sets the {@link 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. * @virtual * @returns The new Set with the same elements. */ copy(): Set<T>; /** * Produces a JavaScript Array from the contents of this Set. * @returns A copy of the Set in Array form. */ toArray(): Array<T>; /** * Converts the Set to a {@link List}. * Because there is no ordering within a Set, * the values in the List may be in any order. * @returns 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. */ get count(): number; /** * This read-only property is the number of elements in the Set. */ get 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 * const it = aSet.iterator; * while (it.next()) { * . . . " value: " + it.value . . . * } * ``` */ get iterator(): Iterator<T>; /** @hidden */ entries(): IterableIterator<[T, T]>; /** @hidden */ keys(): IterableIterator<T>; /** * Call a provided function once per each key/value pair in this Set. * @param callbackFunc a function to call for each value in the Set * @param thisArg a value to use as this when executing callbackFunc * @since 3.0 */ forEach(callbackFunc: (value1: T, value2: T, map: Set<T>) => void, thisArg: any): void; } /** * 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 * const map = new go.Map(); // In TypeScript: new go.Map<string, number>(); * map.set("one", 1); * map.set("two", 2); * map.set("three", 3); * // now map.size === 3 * // and map.get("two") === 2 * // and map.has("zero") === false * ``` * * You can iterate over the key/value pairs in a Map: * ```js * const it = aMap.iterator; * while (it.next()) { * console.log(it.key + ": " + it.value); * } * ``` * Or: * ```js * aMap.each(kvp => { * console.log(kvp.key + ": " + kvp.value); * }); * ``` * But note that there is no guaranteed ordering amongst the key/value pairs. * * Call {@link toKeySet} to get a read-only {@link Set | go.Set} that holds all of the keys of a Map. * Iterating over that Set will produce values that are the keys in the Map. * * For compatibility with versions of GoJS before version 3.0, the following synonyms are defined: * - **getValue(key)**: {@link get}, but returns null instead of undefined when key is not present * - **add(key,val)**: {@link set} * - **contains(key)**: {@link has} * - **remove(key)**: {@link delete} * - **count**: {@link size} * * 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 ECMAScript iteration, so that functionality has not been made somewhat compatible. * These collection classes were defined in GoJS before the ECMAScript collection classes were proposed. * @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 {@link Point}s. * @param coll - an optional collection of {@link IKeyValuePair}s to add, or an Array of {@link IKeyValuePair}s. */ constructor(coll?: Iterable<IKeyValuePair<K, V>> | Array<IKeyValuePair<K, V>> | Map<K, V>); /** * This class implements the JavaScript `Symbol.iterator`, * and can be used with spread syntax or `for ... of` statements. * @since 3.0 */ [Symbol.iterator](): IterableIterator<[K, V]>; /** * Return a JavaScript iterator that produces the entries ([key, value] pairs) of this Map. * This does not produce the old GoJS style {@link Iterator} -- * use the {@link iterator} property if you want that. * @since 3.0 */ entries(): IterableIterator<[K, V]>; /** */ 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 key - The key or index for storing the value in the Map. * @param val - The value to add to the Map, associated with the key. * @returns This modified Map. */ set(key: K, val: V): this; /** * 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 key - The key or index for storing the value in the Map. * @param val - The value to add to the Map, associated with the key. * @returns This modified Map. */ add(key: K, val: V): Map<K, V>; /** * Adds all of the key-value pairs 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 coll - the collection of {@link IKeyValuePair}s to add, or an Array of {@link IKeyValuePair}s. * @returns This modified Map. */ addAll(coll: Iterable<IKeyValuePair<K, V>> | Array<IKeyValuePair<K, V>> | Map<K, V>): this; /** * Returns the first {@link IKeyValuePair} in the collection, or null if there is none. * @returns This returns null if there are no items in the collection. */ first(): IKeyValuePair<K, V> | null; /** * 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. * @virtual * @param pred - The argument to the predicate will be an {@link IKeyValuePair}. * This function must not have any side-effects. * @returns True if any predicate call is true; false otherwise. */ any(pred: ((a: IKeyValuePair<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. * @virtual * @param pred - The argument to the predicate will be an {@link IKeyValuePair}. * This function must not have any side-effects. * @returns True if all predicate calls are true; false otherwise. */ all(pred: ((a: IKeyValuePair<K, V>) => boolean)): boolean; /** * Call the given function on each key/value pair in the collection. * @virtual * @param func - The argument to the function will be an {@link IKeyValuePair}. * This function must not modify the collection. * @returns This Map itself */ each(func: ((a: IKeyValuePair<K, V>) => void)): this; /** * 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 {@link Iterator.map}, this returns a Map, not an Iterator. * @virtual * @param func - The argument to the function will be an {@link IKeyValuePair}. * This function must not modify the collection. * @returns a new Map with the same keys but values produced by the function */ map<S>(func: ((a: IKeyValuePair<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 {@link Iterator.filter}, this returns a Map, not an Iterator. * @virtual * @param pred - This function must not have any side-effects. */ filter(pred: ((a: IKeyValuePair<K, V>) => boolean)): Map<K, V>; /** * Returns whether the given key is in this Map. * @param key - The key to look up in the Map. * @returns Whether or not the key is contained within the Map. */ has(key: K): boolean; /** * Returns whether the given key is in this Map. * @param key - The key to look up in the Map. * @returns Whether or not the key is contained within the Map. */ contains(key: K): boolean; /** * Returns the value associated with a key. * @param key - The key to look up in the Map. * @returns The value associated with the given key, or null if not present in the Map. */ get(key: K): V | null; /** * Returns the value associated with a key. * @param key - The key to look up in the Map. * @returns The value associated with the given key, or null if not present in the Map. */ getValue(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 key - The key to remove. * @returns true if the key was found and removed, false otherwise. */ delete(key: K): boolean; /** * Removes a key (if found) from the Map. * * Be careful not to call this method while iterating over the collection. * @param key - The key to insert. * @returns true if the key was found and removed, false otherwise. */ remove(key: K): boolean; /** * Clears the Map, removing all key-value associations. * This sets the {@link 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. * @virtual * @returns 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. * @returns A copy of the Map in Array form, each element being an {@link IKeyValuePair} */ toArray(): Array<IKeyValuePair<K, V>>; /** * Produces a {@link Set | go.Set} that provides a read-only view onto the keys of this Map. * The collection of keys is not copied. */ toKeySet(): Set<K>; /** * This read-only property is the number of associations in the Map. */ get count(): number; /** * This read-only property is the number of associations in the Map. */ get size(): number; /** * Gets an object that you can use for iterating over the key-value pairs of a Map. * Typical usage: * ```js * const it = aMap.iterator; * while (it.next()) { * console.log("the key: " + it.key + " has value: " + it.value); * } * ``` */ get iterator(): IMapIterator<K, V>; /** * Gets an object that you can use for iterating over the keys of a Map. * Typical usage: * ```js * const it = aMap.iteratorKeys; * while (it.next()) { * console.log("key: " + it.value); * } * ``` */ get iteratorKeys(): Iterator<K>; /** * Return a JavaScript iterator that produces the keys of this Map. * This does not produce the old GoJS style {@link Iterator} -- * use the {@link iteratorKeys} property if you want that. * @since 3.0 */ keys(): IterableIterator<K>; /** * Gets an object that you can use for iterating over the values of a Map. * Typical usage: * ```js * const it = aMap.iteratorValues; * while (it.next()) { * console.log("value: " + it.value); * } * ``` */ get iteratorValues(): Iterator<V>; /** * Return a JavaScript iterator that produces the values of this Map. * This does not produce the old GoJS style {@link Iterator} -- * use the {@link iteratorValues} property if you want that. * @since 3.0 */ values(): IterableIterator<V>; /** * Call a provided function once per each key/value pair in this Map. * @param callbackFunc a function to call for each entry of the Map * @param thisArg a value to use as this when executing callbackFunc * @since 3.0 */ forEach(callbackFunc: (value: V, key: K, map: Map<K, V>) => void, thisArg: any): void; } /** * A Point represents an x- and y-coordinate pair in two-dimensional space. * * Use the static functions {@link Point.parse} and {@link 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 {@link GraphObject} class or {@link Diagram} * or {@link CommandHandler} or a {@link 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 {@link 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 {@link copy} method. * The static {@link 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 x - The x value. * @param y - The y value. */ constructor(x?: number, y?: number); /** * Modify this Point with new X and Y values. * @param x * @param y * @returns this. */ setTo(x: number, y: number): this; /** * Modify this Point so that its X and Y values are the same as the given Point. * @param p - the given Point. * @returns this. */ set(p: Point): this; /** * Create a copy of this Point, with the same values. * @virtual */ copy(): Point; /** * This static function can be used to read in a {@link Point} from a string that was produced by {@link Point.stringify}. * * `go.Point.parse("1 2")` produces the Point `new go.Point(1, 2)`. * @param str */ static parse(str: string): Point; /** * This static function can be used to write out a {@link Point} as a string that can be read by {@link Point.parse}. * * `go.Point.stringify(new go.Point(1, 2))` produces the string "1 2". * @param val */ static stringify(val: Point): string; /** * This static function returns a function that can be used as a back converter for a Binding * to write out a Point's values as numbers with a fixed number of digits after the decimal point. * * This is useful for limiting the size of JSON output and making it more legible. * It might also be useful for regression testing. * * Example: * ```js * new go.Binding("location", "loc", go.Point.parse, go.Point.stringifyFixed(2)) * ``` * @param digits must be a non-negative integer * @returns a function that converts a Point to a string without so many decimals * @since 3.0 */ static stringifyFixed(digits: number): (val: Point) => string; /** * Indicates whether the given Point is equal to this Point. * @param p - The Point to compare to the current Point. * @returns True if the two Points have identical X and Y values, * false otherwise. * @see {@link equalTo} */ equals(p: Point): boolean; /** * Indicates whether the given point (x, y) is equal to this Point. * @param x * @param y * @returns True if the two Points have identical X and Y values, * false otherwise. * @see {@link equals} */ equalTo(x: number, y: number): boolean; /** * (undocumented) * True when the given Point is nearly equal to this Point. * @param p - The Point to compare to the current Point. * @returns True if the two Points have X and Y values that * are equal with a tolerance of 0.5, false otherwise