Skip to content

@graphty/graphty-element / algorithms/Algorithm / Algorithm

Abstract Class: Algorithm<TOptions> ​

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

Base class for all graph algorithms

Example ​

typescript
// Algorithm with options
interface PageRankOptions {
    dampingFactor: number;
    maxIterations: number;
}

class PageRankAlgorithm extends Algorithm\<PageRankOptions\> {
    static optionsSchema: OptionsSchema = {
        dampingFactor: { type: 'number', default: 0.85, ... },
        maxIterations: { type: 'integer', default: 100, ... }
    };

    async run(): Promise<void> {
        const { dampingFactor, maxIterations } = this.options;
        // ... use options
    }
}

Type Parameters ​

TOptions ​

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

The options type for this algorithm (defaults to empty object)

Constructors ​

Constructor ​

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

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

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 ​

Algorithm<TOptions>

Properties ​

namespace ​

static namespace: string

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


optionsSchema ​

static optionsSchema: OptionsSchema = {}

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

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


suggestedStyles? ​

static optional suggestedStyles: SuggestedStylesProvider

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


type ​

static type: string

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


zodOptionsSchema? ​

static optional zodOptionsSchema: OptionsSchema

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

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.

Accessors ​

namespace ​

Get Signature ​

get namespace(): string

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

Gets the algorithm namespace

Returns ​

string

The algorithm namespace identifier


results ​

Get Signature ​

get results(): AdHocData

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

Gets all algorithm results for nodes, edges, and graph

Returns ​

AdHocData

An object containing node, edge, and graph results


type ​

Get Signature ​

get type(): string

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

Gets the algorithm type

Returns ​

string

The algorithm type identifier

Methods ​

addEdgeResult() ​

addEdgeResult(edge, resultName, result): void

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

Adds a result value for a specific edge

Parameters ​

edge ​

Edge

The edge to add the result to

resultName ​

string

The name of the result field

result ​

unknown

The result value to store

Returns ​

void


addGraphResult() ​

addGraphResult(resultName, result): void

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

Adds a result value for the graph

Parameters ​

resultName ​

string

The name of the result field

result ​

unknown

The result value to store

Returns ​

void


addNodeResult() ​

addNodeResult(nodeId, resultName, result): void

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

Adds a result value for a specific node

Parameters ​

nodeId ​

The ID of the node to add the result to

string | number

resultName ​

string

The name of the result field

result ​

unknown

The result value to store

Returns ​

void


get() ​

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

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

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


getClass() ​

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

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

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


getOptionsSchema() ​

static getOptionsSchema(): OptionsSchema

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

Get the options schema for this algorithm

Returns ​

OptionsSchema

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

Deprecated ​

Use getZodOptionsSchema() instead


getRegisteredAlgorithms() ​

static getRegisteredAlgorithms(namespace?): string[]

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

Get all registered algorithm names.

Parameters ​

namespace? ​

string

Optional namespace to filter by

Returns ​

string[]

Array of algorithm names in "namespace:type" format


getRegisteredTypes() ​

static getRegisteredTypes(): string[]

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

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', ...]

getSuggestedStyles() ​

static getSuggestedStyles(): SuggestedStylesConfig | null

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

Get suggested styles for this algorithm

Returns ​

SuggestedStylesConfig | null

The suggested styles configuration, or null if none defined


getZodOptionsSchema() ​

static getZodOptionsSchema(): OptionsSchema

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

Get the Zod-based options schema for this algorithm.

Returns ​

OptionsSchema

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


hasOptions() ​

static hasOptions(): boolean

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

Check if this algorithm has configurable options

Returns ​

boolean

true if the algorithm has at least one option defined

Deprecated ​

Use hasZodOptions() instead


hasSuggestedStyles() ​

static hasSuggestedStyles(): boolean

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

Check if this algorithm has suggested styles

Returns ​

boolean

true if suggested styles are defined


hasZodOptions() ​

static hasZodOptions(): boolean

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

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

Returns ​

boolean

true if the algorithm has a Zod options schema defined


register() ​

static register<T>(cls): T

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

Registers an algorithm class in the global registry

Type Parameters ​

T ​

T extends AlgorithmClass

Parameters ​

cls ​

T

The algorithm class to register

Returns ​

T

The registered algorithm class


run() ​

abstract run(g): Promise<void>

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

Parameters ​

g ​

Graph

Returns ​

Promise<void>