Skip to content

@graphty/graphty-element / extend / DeclaredAlgorithm

Abstract Class: DeclaredAlgorithm<TOptions> ​

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:64

An algorithm whose result is a value it returns.

Extends ​

Type Parameters ​

TOptions ​

TOptions extends Record<string, unknown> = Record<string, unknown>

The options type this algorithm resolves from its schema.

Constructors ​

Constructor ​

new DeclaredAlgorithm<TOptions>(g, options?): DeclaredAlgorithm<TOptions>

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

Creates a new algorithm instance

Parameters ​

g ​

Graph

The graph to run the algorithm on

options? ​

Partial<TOptions>

Optional configuration options (uses schema defaults if not provided)

Returns ​

DeclaredAlgorithm<TOptions>

Inherited from ​

Algorithm.constructor

Properties ​

descriptor? ​

static optional descriptor?: AlgorithmDescriptor

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:81

What the catalogue publishes about this algorithm.

DECLARED HERE, ON THE PUBLISHED BASE, so a plugin author reads one class to learn what a subclass must carry. It is also what turns the descriptor into the single declaration: descriptor.options is what a form renders, what the catalogue publishes, what the run path validates a caller's parameters against, and -- through resolveOptions below -- what the running code receives. An algorithm used to say all of that twice, in two vocabularies that did not correspond, with nothing cross-checking them.

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


namespace ​

static namespace: string

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

Inherited from ​

Algorithm.namespace


optionsSchema ​

static optionsSchema: OptionsSchema = {}

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

Options schema for this algorithm

Subclasses should override this to define their configurable options. An empty schema means the algorithm has no configurable options.

Deprecated ​

Use zodOptionsSchema instead for new implementations

Inherited from ​

Algorithm.optionsSchema


scopeInput? ​

static optional scopeInput?: ScopeInputDeclaration

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

Whether this algorithm computes over its run's scope. "subgraph": the run context's input hands the algorithm its scope (the compact snapshot, and the scope's masks over the full graph), and the planner estimates the run over the scope. Absent or "none": the whole graph, of whose values the element keeps the scope's, with a caveat saying so; the planner estimates and refuses the run as a whole-graph one.

THE ONE DECLARATION: the input, the caveat and the published descriptor.scopeInput all read it. Declare it only once every node list, edge read and count the class takes comes from the input, because an algorithm that lists its nodes some other way would compute over a scoped topology while reporting every node.

Inherited from ​

Algorithm.scopeInput


type ​

static type: string

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

Inherited from ​

Algorithm.type


zodOptionsSchema? ​

static optional zodOptionsSchema?: OptionsSchema

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

NEW: Zod-based options schema with rich metadata for UI generation.

Override in subclasses to define algorithm-specific options. This is the new unified system that provides both validation and UI metadata.

Inherited from ​

Algorithm.zodOptionsSchema

Accessors ​

namespace ​

Get Signature ​

get namespace(): string

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

Gets the algorithm namespace

Returns ​

string

The algorithm namespace identifier

Inherited from ​

Algorithm.namespace


result ​

Get Signature ​

get result(): RunResult | undefined

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:127

What the last run published.

THE REPLACEMENT FOR algorithmResults. The 1.x entry point used to scatter its numbers onto the render objects under names it chose for itself, and the only way back to them was to walk the graph. It returns a result object now, and this is where the 1.x run() leaves it, so the old call shape still has somewhere to read from.

Returns ​

RunResult | undefined

The result, or undefined when nothing has run or there was nothing to compute.


type ​

Get Signature ​

get type(): string

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

Gets the algorithm type

Returns ​

string

The algorithm type identifier

Inherited from ​

Algorithm.type

Methods ​

compute() ​

abstract compute(context): Promise<AlgorithmOutput | null>

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:140

Compute this algorithm's result.

Report progress and yield through the context rather than running to completion in one block, and honour its signal: an analysis that cannot be watched or stopped is unusable on a graph big enough to be worth analysing.

Parameters ​

context ​

AlgorithmRunContext

What the element gave the run.

Returns ​

Promise<AlgorithmOutput | null>

Everything the run produced, or null when there was nothing to compute.


computeRun() ​

computeRun(context, runId, declared?): Promise<RunResult | undefined>

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:190

Compute this algorithm's result, publish it under a run id, and project the 1.x view of it.

This is what the run executor calls. The catalogue's own field descriptors are passed in because the catalogue states what a reader sees a field called and cannot be imported here without a cycle -- it reads these classes to publish their options.

Parameters ​

context ​

RunControls

What the element gave the run: a signal, a progress channel and a yield. The graph the run computes over is bound here, as the context's input.

runId ​

string

The id the result is published under, which is the <runId> in results.<runId>.

declared? ​

readonly FieldDescriptor[]

The catalogue's descriptors for this algorithm's fields, when the caller holds them.

Returns ​

Promise<RunResult | undefined>

The result, or undefined when there was nothing to compute.

Throws ​

Whatever the context's signal throws once the run has been cancelled, which is a DOMException named AbortError.


get() ​

static get(g, namespace, type, options?): Algorithm<Record<string, unknown>> | null

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

Gets an algorithm instance from the registry

Parameters ​

g ​

Graph

The graph to run the algorithm on

namespace ​

string

The algorithm namespace

type ​

string

The algorithm type

options? ​

Record<string, unknown>

Optional algorithm-specific options to pass to constructor

Returns ​

Algorithm<Record<string, unknown>> | null

A new instance of the algorithm, or null if not found

Inherited from ​

Algorithm.get


getClass() ​

static getClass(namespace, type): AlgorithmClass & AlgorithmStatics | null

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

Gets an algorithm class from the registry

Parameters ​

namespace ​

string

The algorithm namespace

type ​

string

The algorithm type

Returns ​

AlgorithmClass & AlgorithmStatics | null

The algorithm class, or null if not found

Inherited from ​

Algorithm.getClass


getOptionsSchema() ​

static getOptionsSchema(): OptionsSchema

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

Get the options schema for this algorithm

Returns ​

OptionsSchema

The options schema, or an empty object if no options defined

Deprecated ​

Use getZodOptionsSchema() instead

Inherited from ​

Algorithm.getOptionsSchema


getRegisteredAlgorithms() ​

static getRegisteredAlgorithms(namespace?): string[]

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

Get all registered algorithm names.

Parameters ​

namespace? ​

string

Optional namespace to filter by

Returns ​

string[]

Array of algorithm names in "namespace:type" format

Inherited from ​

Algorithm.getRegisteredAlgorithms


getRegisteredTypes() ​

static getRegisteredTypes(): string[]

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

Get all registered algorithm types. This method is provided for API consistency with DataSource.

Returns ​

string[]

Array of algorithm keys in "namespace:type" format

Since ​

1.5.0

Example ​

typescript
const types = Algorithm.getRegisteredTypes();
console.log('Available algorithms:', types);
// ['graphty:betweenness', 'graphty:closeness', 'graphty:degree', ...]

Inherited from ​

Algorithm.getRegisteredTypes


getZodOptionsSchema() ​

static getZodOptionsSchema(): ZodOptionsSchema

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

Get the Zod-based options schema for this algorithm.

Returns ​

ZodOptionsSchema

The Zod options schema, or an empty object if no schema defined

Inherited from ​

Algorithm.getZodOptionsSchema


hasOptions() ​

static hasOptions(): boolean

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

Check if this algorithm has configurable options

Returns ​

boolean

true if the algorithm has at least one option defined

Deprecated ​

Use hasZodOptions() instead

Inherited from ​

Algorithm.hasOptions


hasZodOptions() ​

static hasZodOptions(): boolean

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

Check if this algorithm has a Zod-based options schema.

Returns ​

boolean

true if the algorithm has a Zod options schema defined

Inherited from ​

Algorithm.hasZodOptions


publishResult() ​

publishResult(context, runId, fields?): Promise<RunResult | undefined>

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:166

Compute on behalf of a run, and hand the result back.

The run machinery's entry point, which is DeclaredAlgorithm.computeRun under the name every algorithm answers to.

Parameters ​

context ​

RunControls

A signal, a progress channel and a yield.

runId ​

string

The id the result is published under.

fields? ​

readonly FieldDescriptor[]

The catalogue's descriptors for this algorithm's fields.

Returns ​

Promise<RunResult | undefined>

The result, or undefined when there was nothing to compute.

Throws ​

Whatever the context's signal throws once the run has been cancelled.

Overrides ​

Algorithm.publishResult


register() ​

static register<T>(cls, options?): T

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

Registers an algorithm class in the global registry

Type Parameters ​

T ​

T extends AlgorithmClass

Parameters ​

cls ​

T

The algorithm class to register

options? ​

RegisterOptions

Whether a different class under a key already taken throws instead of replacing it.

Returns ​

T

The registered algorithm class

Inherited from ​

Algorithm.register


run() ​

run(): Promise<void>

Defined in: graphty-element/src/algorithms/results/DeclaredAlgorithm.ts:151

Run the algorithm and publish what it produced on the 1.x result paths.

The 1.x entry point: it returns nothing, and it publishes under the algorithm's own type rather than under a run id, because there is no run behind it. Whoever wants the result calls DeclaredAlgorithm.computeRun, which is the same work with a run in front of it.

Returns ​

Promise<void>

A promise that settles when the result has been published.

Overrides ​

Algorithm.run