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

graphty-org / graphty-element / 20194755040

13 Dec 2025 04:28PM UTC coverage: 86.405% (+0.02%) from 86.388%
20194755040

push

github

apowers313
Merge branch 'master' of https://github.com/graphty-org/graphty-element

3688 of 4321 branches covered (85.35%)

Branch coverage included in aggregate %.

17476 of 20173 relevant lines covered (86.63%)

8620.8 hits per line

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

94.64
/src/managers/AlgorithmManager.ts
1
import {Algorithm} from "../algorithms/Algorithm";
3✔
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 {
3✔
12
    constructor(
3✔
13
        private eventManager: EventManager,
645✔
14
        private graph: Graph,
645✔
15
    ) {}
645✔
16

17
    async init(): Promise<void> {
3✔
18
        // AlgorithmManager doesn't need async initialization
19
        return Promise.resolve();
563✔
20
    }
563✔
21

22
    dispose(): void {
3✔
23
        // No cleanup needed for algorithms
24
    }
531✔
25

26
    /**
27
     * Run algorithms specified in the template configuration
28
     * Called during initialization if runAlgorithmsOnLoad is true
29
     */
30
    async runAlgorithmsFromTemplate(algorithms: string[]): Promise<void> {
3✔
31
        const errors: Error[] = [];
10✔
32

33
        for (const algName of algorithms) {
10✔
34
            try {
23✔
35
                const trimmedName = algName.trim();
23✔
36
                const [namespace, type] = trimmedName.split(":");
23✔
37
                if (!namespace || !type) {
23✔
38
                    throw new Error(`invalid algorithm name format: ${trimmedName}. Expected format: namespace:type`);
1✔
39
                }
1✔
40

41
                await this.runAlgorithm(namespace.trim(), type.trim());
22✔
42
            } catch (error) {
23✔
43
                const algorithmError = error instanceof Error ? error : new Error(String(error));
6!
44
                errors.push(algorithmError);
6✔
45
                // Individual error already emitted by runAlgorithm
46
            }
6✔
47
        }
23✔
48

49
        // If there were any errors, throw a summary error
50
        if (errors.length > 0) {
10✔
51
            const summaryError = new Error(
4✔
52
                `${errors.length} algorithm(s) failed during template execution: ${
4✔
53
                    errors.map((e) => e.message).join(", ")
4✔
54
                }`,
4✔
55
            );
4✔
56

57
            this.eventManager.emitGraphError(
4✔
58
                this.graph,
4✔
59
                summaryError,
4✔
60
                "algorithm",
4✔
61
                {
4✔
62
                    errorCount: errors.length,
4✔
63
                    component: "AlgorithmManager",
4✔
64
                },
4✔
65
            );
4✔
66

67
            throw summaryError;
4✔
68
        }
4✔
69
    }
10✔
70

71
    /**
72
     * Run a specific algorithm by namespace and type
73
     * @param namespace - Algorithm namespace (e.g., "graphty")
74
     * @param type - Algorithm type (e.g., "dijkstra")
75
     * @param algorithmOptions - Optional algorithm-specific options (source, target, etc.)
76
     */
77
    async runAlgorithm(
3✔
78
        namespace: string,
92✔
79
        type: string,
92✔
80
        algorithmOptions?: AlgorithmSpecificOptions,
92✔
81
    ): Promise<void> {
92✔
82
        try {
92✔
83
            const alg = Algorithm.get(this.graph, namespace, type);
92✔
84
            if (!alg) {
92✔
85
                throw new Error(`algorithm not found: ${namespace}:${type}`);
1✔
86
            }
1✔
87

88
            // Configure the algorithm if options are provided and configure method exists
89
            if (algorithmOptions && "configure" in alg && typeof alg.configure === "function") {
92!
90
                alg.configure(algorithmOptions);
×
91
            }
✔
92

93
            await alg.run(this.graph);
91✔
94

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

103
            this.eventManager.emitGraphError(
10✔
104
                this.graph,
10✔
105
                algorithmError,
10✔
106
                "algorithm",
10✔
107
                {
10✔
108
                    algorithm: `${namespace}:${type}`,
10✔
109
                    component: "AlgorithmManager",
10✔
110
                },
10✔
111
            );
10✔
112

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

117
    /**
118
     * Check if an algorithm exists
119
     */
120
    hasAlgorithm(namespace: string, type: string): boolean {
3✔
121
        try {
3✔
122
            const alg = Algorithm.get(this.graph, namespace, type);
3✔
123
            return alg !== null;
3✔
124
        } catch {
3✔
125
            return false;
1✔
126
        }
1✔
127
    }
3✔
128

129
    /**
130
     * Get list of available algorithms
131
     * TODO: This depends on the Algorithm registry implementation
132
     */
133
    getAvailableAlgorithms(): string[] {
3✔
134
        // This would need to be implemented in the Algorithm class
135
        // For now, return empty array
136
        return [];
1✔
137
    }
1✔
138
}
3✔
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