• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphty-org / graphty-monorepo / 20690039805

04 Jan 2026 08:00AM UTC coverage: 77.552% (-0.4%) from 77.925%
20690039805

push

github

apowers313
chore: merge master into graphty algorithms and fix errors

13487 of 17880 branches covered (75.43%)

Branch coverage included in aggregate %.

107 of 108 new or added lines in 23 files covered. (99.07%)

245 existing lines in 9 files now uncovered.

41791 of 53399 relevant lines covered (78.26%)

142735.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.19
/graphty-element/src/managers/AlgorithmManager.ts
1
import { Algorithm } from "../algorithms/Algorithm";
15✔
2
import type { Graph } from "../Graph";
3
import type { AlgorithmSpecificOptions } from "../utils/queue-migration";
4
import type { EventManager } from "./EventManager";
5
import type { Manager } from "./interfaces";
6

7
/**
8
 * Manages algorithm execution and coordination
9
 * Handles running algorithms from templates and individual algorithm execution
10
 */
11
export class AlgorithmManager implements Manager {
15✔
12
    /**
13
     * Creates an instance of AlgorithmManager
14
     * @param eventManager - Event manager for emitting algorithm events
15
     * @param graph - Graph instance to run algorithms on
16
     */
17
    constructor(
15✔
18
        private eventManager: EventManager,
1,011✔
19
        private graph: Graph,
1,011✔
20
    ) {}
1,011✔
21

22
    /**
23
     * Initializes the algorithm manager
24
     * @returns Promise that resolves when initialization is complete
25
     */
26
    async init(): Promise<void> {
15✔
27
        // AlgorithmManager doesn't need async initialization
28
        return Promise.resolve();
919✔
29
    }
919✔
30

31
    /**
32
     * Disposes of the algorithm manager and cleans up resources
33
     */
34
    dispose(): void {
15✔
35
        // No cleanup needed for algorithms
36
    }
779✔
37

38
    /**
39
     * Run algorithms specified in the template configuration
40
     * Called during initialization if runAlgorithmsOnLoad is true
41
     * @param algorithms - Array of algorithm names in "namespace:type" format
42
     */
43
    async runAlgorithmsFromTemplate(algorithms: string[]): Promise<void> {
15✔
44
        const errors: Error[] = [];
10✔
45

46
        for (const algName of algorithms) {
10✔
47
            try {
23✔
48
                const trimmedName = algName.trim();
23✔
49
                const [namespace, type] = trimmedName.split(":");
23✔
50
                if (!namespace || !type) {
23!
51
                    throw new Error(`invalid algorithm name format: ${trimmedName}. Expected format: namespace:type`);
1✔
52
                }
1✔
53

54
                await this.runAlgorithm(namespace.trim(), type.trim());
22✔
55
            } catch (error) {
23!
56
                const algorithmError = error instanceof Error ? error : new Error(String(error));
6!
57
                errors.push(algorithmError);
6✔
58
                // Individual error already emitted by runAlgorithm
59
            }
6✔
60
        }
23✔
61

62
        // If there were any errors, throw a summary error
63
        if (errors.length > 0) {
10!
64
            const summaryError = new Error(
4✔
65
                `${errors.length} algorithm(s) failed during template execution: ${errors
4✔
66
                    .map((e) => e.message)
4✔
67
                    .join(", ")}`,
4✔
68
            );
4✔
69

70
            this.eventManager.emitGraphError(this.graph, summaryError, "algorithm", {
4✔
71
                errorCount: errors.length,
4✔
72
                component: "AlgorithmManager",
4✔
73
            });
4✔
74

75
            throw summaryError;
4✔
76
        }
4✔
77
    }
10✔
78

79
    /**
80
     * Run a specific algorithm by namespace and type
81
     * @param namespace - Algorithm namespace (e.g., "graphty")
82
     * @param type - Algorithm type (e.g., "dijkstra")
83
     * @param algorithmOptions - Optional algorithm-specific options (source, target, etc.)
84
     */
85
    async runAlgorithm(namespace: string, type: string, algorithmOptions?: AlgorithmSpecificOptions): Promise<void> {
15✔
86
        try {
92✔
87
            // Pass options to constructor for new-style algorithms with zodOptionsSchema
88
            const alg = Algorithm.get(this.graph, namespace, type, algorithmOptions);
92✔
89
            if (!alg) {
92!
90
                throw new Error(`algorithm not found: ${namespace}:${type}`);
1✔
91
            }
1✔
92

93
            // Also call configure for backward compatibility with legacy algorithms
94
            // that use the deprecated configure() method instead of constructor options
95
            if (algorithmOptions && "configure" in alg && typeof alg.configure === "function") {
92!
UNCOV
96
                alg.configure(algorithmOptions);
×
UNCOV
97
            }
✔
98

99
            await alg.run(this.graph);
91✔
100

101
            // Re-apply styles to all nodes and edges after algorithm completes
102
            // This ensures algorithm results are used in style selector matching
103
            this.graph.getDataManager().applyStylesToExistingNodes();
82✔
104
            this.graph.getDataManager().applyStylesToExistingEdges();
82✔
105
        } catch (error) {
92!
106
            // Emit error event for any error (not found or execution)
107
            const algorithmError = error instanceof Error ? error : new Error(String(error));
10✔
108

109
            this.eventManager.emitGraphError(this.graph, algorithmError, "algorithm", {
10✔
110
                algorithm: `${namespace}:${type}`,
10✔
111
                component: "AlgorithmManager",
10✔
112
            });
10✔
113

114
            throw algorithmError;
10✔
115
        }
10✔
116
    }
92✔
117

118
    /**
119
     * Check if an algorithm exists
120
     * @param namespace - Algorithm namespace
121
     * @param type - Algorithm type
122
     * @returns True if the algorithm exists, false otherwise
123
     */
124
    hasAlgorithm(namespace: string, type: string): boolean {
15✔
125
        try {
3✔
126
            const alg = Algorithm.get(this.graph, namespace, type);
3✔
127
            return alg !== null;
3✔
128
        } catch {
3✔
129
            return false;
1✔
130
        }
1✔
131
    }
3✔
132

133
    /**
134
     * Get list of available algorithms
135
     * TODO: This depends on the Algorithm registry implementation
136
     * @returns Array of available algorithm names
137
     */
138
    getAvailableAlgorithms(): string[] {
15✔
139
        // This would need to be implemented in the Algorithm class
140
        // For now, return empty array
141
        return [];
1✔
142
    }
1✔
143
}
15✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc