@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 ​
// 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 ​
The graph to run the algorithm on
options? ​
Partial<TOptions>
Optional configuration options (uses schema defaults if not provided)
Returns ​
Algorithm<TOptions>
Properties ​
namespace ​
staticnamespace:string
Defined in: graphty-element/src/algorithms/Algorithm.ts:100
optionsSchema ​
staticoptionsSchema: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? ​
staticoptionalsuggestedStyles:SuggestedStylesProvider
Defined in: graphty-element/src/algorithms/Algorithm.ts:101
type ​
statictype:string
Defined in: graphty-element/src/algorithms/Algorithm.ts:99
zodOptionsSchema? ​
staticoptionalzodOptionsSchema: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 ​
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 ​
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() ​
staticget(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 ​
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() ​
staticgetClass(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() ​
staticgetOptionsSchema():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() ​
staticgetRegisteredAlgorithms(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() ​
staticgetRegisteredTypes():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 ​
const types = Algorithm.getRegisteredTypes();
console.log('Available algorithms:', types);
// ['graphty:betweenness', 'graphty:closeness', 'graphty:degree', ...]getSuggestedStyles() ​
staticgetSuggestedStyles():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() ​
staticgetZodOptionsSchema():OptionsSchema
Defined in: graphty-element/src/algorithms/Algorithm.ts:353
Get the Zod-based options schema for this algorithm.
Returns ​
The Zod options schema, or an empty object if no schema defined
hasOptions() ​
statichasOptions():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() ​
statichasSuggestedStyles():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() ​
statichasZodOptions():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() ​
staticregister<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() ​
abstractrun(g):Promise<void>
Defined in: graphty-element/src/algorithms/Algorithm.ts:217
Parameters ​
g ​
Returns ​
Promise<void>