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

graphty-org / graphty-element / 16281745178

15 Jul 2025 01:24AM UTC coverage: 70.353% (-2.2%) from 72.536%
16281745178

push

github

apowers313
fix: build and optional argument fixes

735 of 934 branches covered (78.69%)

Branch coverage included in aggregate %.

7 of 8 new or added lines in 2 files covered. (87.5%)

878 existing lines in 24 files now uncovered.

4742 of 6851 relevant lines covered (69.22%)

311.14 hits per line

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

67.69
/src/algorithms/Algorithm.ts
1
import {set as deepSet} from "lodash";
3✔
2

3
import {AdHocData} from "../config";
4
import {Edge} from "../Edge";
5
import {Graph} from "../Graph";
6

7
type AlgorithmClass = new (g: Graph) => Algorithm;
8
const algorithmRegistry = new Map<string, AlgorithmClass>();
3✔
9

10
// algorithmResults layout:
11
// {
12
//     node: {
13
//         id: {
14
//             namespace: {
15
//                 algorithm: {
16
//                     result: unknown
17
//                 }
18
//             }
19
//         }
20
//     },
21
//     edge: {
22
//         id: {
23
//             namespace: {
24
//                 algorithm: {
25
//                     result: unknown
26
//                 }
27
//             }
28
//         }
29
//     },
30
//     graph: {
31
//         namespace: {
32
//             algorithm: {
33
//                 result: unknown
34
//             }
35
//         }
36
//     }
37
// }
38

39
export abstract class Algorithm {
3✔
40
    static type: string;
41
    static namespace: string;
42
    protected graph: Graph;
43

44
    constructor(g: Graph) {
3✔
45
        this.graph = g;
4✔
46
    }
4✔
47

48
    get type(): string {
3✔
49
        return (this.constructor as typeof Algorithm).type;
924✔
50
    }
924✔
51

52
    get namespace(): string {
3✔
53
        return (this.constructor as typeof Algorithm).namespace;
924✔
54
    }
924✔
55

56
    get results(): AdHocData {
3✔
57
        const algorithmResults = {} as AdHocData;
×
58
        for (const n of this.graph.getDataManager().nodes.values()) {
×
59
            deepSet(algorithmResults, `node.${n.id}`, n.algorithmResults);
×
60
        }
×
61

62
        // TODO: edge and graph
63

64
        return algorithmResults;
×
65
        // return structuredClone(algorithmResults) as AdHocData;
66
    }
×
67

68
    abstract run(g: Graph): Promise<void>;
69

70
    #createPath(resultName: string): string[] {
3✔
71
        const ret: string[] = [];
924✔
72

73
        ret.push("algorithmResults");
924✔
74
        ret.push(this.namespace);
924✔
75
        ret.push(this.type);
924✔
76
        ret.push(resultName);
924✔
77

78
        return ret;
924✔
79
    }
924✔
80

81
    addNodeResult(nodeId: number | string, resultName: string, result: unknown): void {
3✔
82
        const p = this.#createPath(resultName);
924✔
83
        const n = this.graph.getDataManager().nodes.get(nodeId);
924✔
84
        if (!n) {
924!
85
            throw new Error(`couldn't find nodeId '${nodeId}' while trying to run algorithm '${this.type}'`);
×
86
        }
×
87

88
        deepSet(n, p, result);
924✔
89
        // XXX: THIS IS WHERE I LEFT OFF
90
        // replace algorithmResults with graph.nodes; set result on each node.algorithmResult
91
    }
924✔
92

93
    addEdgeResult(_e: Edge, _result: unknown): void {
3✔
94
        // Edge result added - parameters are intentionally unused
95
        void _e;
×
UNCOV
96
        void _result;
×
UNCOV
97
    }
×
98

99
    addGraphResult(_g: Graph, _result: unknown): void {
3✔
100
        // Graph result added - parameters are intentionally unused
UNCOV
101
        void _g;
×
UNCOV
102
        void _result;
×
UNCOV
103
    }
×
104

105
    static register<T extends AlgorithmClass>(cls: T): T {
3✔
106
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
        const t: string = (cls as any).type;
7✔
108
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
        const ns: string = (cls as any).namespace;
7✔
110
        algorithmRegistry.set(`${ns}:${t}`, cls);
7✔
111
        return cls;
7✔
112
    }
7✔
113

114
    static get(g: Graph, namespace: string, type: string): Algorithm | null {
3✔
UNCOV
115
        const SourceClass = algorithmRegistry.get(`${namespace}:${type}`);
×
116
        if (SourceClass) {
×
UNCOV
117
            return new SourceClass(g);
×
UNCOV
118
        }
×
119

UNCOV
120
        return null;
×
UNCOV
121
    }
×
122
}
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

© 2025 Coveralls, Inc