Skip to content

@graphty/graphty-element / extend / AlgorithmStatics

Interface: AlgorithmStatics ​

Defined in: graphty-element/src/algorithms/Algorithm.ts:39

Interface for Algorithm class static members Exported for use in type annotations when referencing algorithm classes

Properties ​

cost? ​

optional cost?: (n, m) => number

Defined in: graphty-element/src/algorithms/Algorithm.ts:76

A cost model in seconds over a graph of n nodes and m edges.

HERE RATHER THAN ON THE DESCRIPTOR, because a function is not plain JSON and the composed catalogue has to survive JSON.stringify and a postMessage to a worker. The registry keeps the model beside the class reference, and the estimator reads it from there, so a plugin supplies real arithmetic for "what would this cost before I click" without a descriptor ever carrying something unserialisable.

Absent, the element estimates from the costClass the descriptor declares, which is what every algorithm this package ships does.

Prefer costUnits: seconds written on one machine are wrong on every other, and no calibration can scale them, so an estimate from this hook always reports "modelled".

Parameters ​

n ​

number

m ​

number

Returns ​

number


costUnits? ​

optional costUnits?: (n, m, options) => number

Defined in: graphty-element/src/algorithms/Algorithm.ts:89

A cost model in WORK UNITS over a graph of n nodes and m edges, for the whole run.

The units are those of the descriptor's costClass: elements for instant and iterative (count every iteration), source-edge pairs for heavy, operations for cubic. The element divides them by the rate it measured for that class on this device, so the estimate follows the machine and reports "calibrated" once the device is probed, exactly as a built-in's does. Wins over cost when both are declared.

options are the values the run would use -- the caller's, with the declared defaults filled in -- so an option that multiplies the work (a number of passes) is priced.

Parameters ​

n ​

number

m ​

number

options ​

Readonly<Record<string, unknown>>

Returns ​

number


descriptor? ​

optional descriptor?: AlgorithmDescriptor

Defined in: graphty-element/src/algorithms/Algorithm.ts:60

What the catalogue publishes about this algorithm, for a plugin that wants to be one.

DECLARING IT IS WHAT MAKES A PLUGIN A FIRST-CLASS ALGORITHM. Without it a class can be registered and called, and that is all: the run machinery resolves a key through the catalogue, so a class the catalogue does not carry cannot be started as a run, and everything hanging off a run is out of reach -- progress, cancellation, a cost estimate before the click, a ranking, a histogram, a summary, a plain-language reading, and the styling the element derives from a result's shape.

The shape is the load-bearing field: field NAMES are fixed by the shape rather than by the algorithm, which is what lets any consumer read results.<runId>.value without opening the catalogue first. checkShapeContract will tell you whether your fields match the shape you declared.

Absent, the class stays exactly as capable as it was: registered, callable through the 1.10 address, and invisible to the catalogue.


namespace ​

namespace: string

Defined in: graphty-element/src/algorithms/Algorithm.ts:41


optionsSchema ​

optionsSchema: OptionsSchema

Defined in: graphty-element/src/algorithms/Algorithm.ts:115


scopeInput? ​

optional scopeInput?: ScopeInputDeclaration

Defined in: graphty-element/src/algorithms/Algorithm.ts:114

What a run over a scope computes on. See Algorithm.scopeInput; register publishes it as the descriptor's scopeInput.


suggestedName? ​

optional suggestedName?: (options) => SuggestedName | undefined

Defined in: graphty-element/src/algorithms/Algorithm.ts:109

The name a run's result is given, from the run's option values (the declared defaults filled in): { id, label }, where id becomes the result path results.<id>.value and label is what the layer list and the legend show. Name only the settings worth telling two results apart by, and return undefined (or leave this out) to name the result after the algorithm key.

Two runs with the same name and the same scope are one run: a change to a setting the name does not carry re-runs it in place. The element adds _2, _3, ... when the name is taken by a different computation, and a name the caller passes with as always wins.

Parameters ​

options ​

Readonly<Record<string, unknown>>

Returns ​

SuggestedName | undefined


type ​

type: string

Defined in: graphty-element/src/algorithms/Algorithm.ts:40


version? ​

optional version?: string

Defined in: graphty-element/src/algorithms/Algorithm.ts:97

The plugin's own version, recorded on every run this algorithm produces.

A saved run records the versions of the code that produced its numbers. Without this a run of a third party's algorithm recorded the element's version and the two sibling packages' and nothing at all identifying the code that actually did the work.


zodOptionsSchema? ​

optional zodOptionsSchema?: OptionsSchema

Defined in: graphty-element/src/algorithms/Algorithm.ts:121

NEW: Zod-based options schema for unified validation and UI metadata

Methods ​

getOptionsSchema() ​

getOptionsSchema(): OptionsSchema

Defined in: graphty-element/src/algorithms/Algorithm.ts:117

Returns ​

OptionsSchema

Deprecated ​

Use getZodOptionsSchema() instead


getZodOptionsSchema() ​

getZodOptionsSchema(): ZodOptionsSchema

Defined in: graphty-element/src/algorithms/Algorithm.ts:123

Get the Zod-based options schema for this algorithm

Returns ​

ZodOptionsSchema


hasOptions() ​

hasOptions(): boolean

Defined in: graphty-element/src/algorithms/Algorithm.ts:119

Returns ​

boolean

Deprecated ​

Use hasZodOptions() instead


hasZodOptions() ​

hasZodOptions(): boolean

Defined in: graphty-element/src/algorithms/Algorithm.ts:125

Check if this algorithm has a Zod-based options schema

Returns ​

boolean