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

graphty-org / graphty-element / 20514590651

26 Dec 2025 02:37AM UTC coverage: 70.559% (-0.3%) from 70.836%
20514590651

push

github

apowers313
ci: fix npm ci

9591 of 13363 branches covered (71.77%)

Branch coverage included in aggregate %.

25136 of 35854 relevant lines covered (70.11%)

6233.71 hits per line

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

93.33
/src/algorithms/StronglyConnectedComponentsAlgorithm.ts
1
import {stronglyConnectedComponents} from "@graphty/algorithms";
15✔
2

3
import type {SuggestedStylesConfig} from "../config";
4
import {Algorithm} from "./Algorithm";
15✔
5
import {toAlgorithmGraph} from "./utils/graphConverter";
15✔
6

7
/**
8
 *
9
 */
10
export class StronglyConnectedComponentsAlgorithm extends Algorithm {
15✔
11
    static namespace = "graphty";
18✔
12
    static type = "scc";
119✔
13

14
    static suggestedStyles = (): SuggestedStylesConfig => ({
119✔
15
        layers: [
11✔
16
            {
11✔
17
                node: {
11✔
18
                    selector: "",
11✔
19
                    style: {
11✔
20
                        enabled: true,
11✔
21
                    },
11✔
22
                    calculatedStyle: {
11✔
23
                        inputs: ["algorithmResults.graphty.scc.componentId"],
11✔
24
                        output: "style.texture.color",
11✔
25
                        expr: "{ return StyleHelpers.color.categorical.okabeIto(arguments[0] ?? 0) }",
11✔
26
                    },
11✔
27
                },
11✔
28
                metadata: {
11✔
29
                    name: "SCC - Okabe-Ito Colors",
11✔
30
                    description: "8 colorblind-safe colors for strongly connected components",
11✔
31
                },
11✔
32
            },
11✔
33
        ],
11✔
34
        description: "Visualizes strongly connected components in directed graphs with distinct colors",
11✔
35
        category: "grouping",
11✔
36
    });
11✔
37

38
    /**
39
     * Executes the strongly connected components algorithm on the graph
40
     *
41
     * Identifies maximal strongly connected components in a directed graph.
42
     */
43
    async run(): Promise<void> {
18✔
44
        const g = this.graph;
2✔
45
        const nodes = Array.from(g.getDataManager().nodes.keys());
2✔
46

47
        if (nodes.length === 0) {
2!
48
            return;
×
49
        }
×
50

51
        // Convert to @graphty/algorithms format - SCC requires directed graph
52
        const graphData = toAlgorithmGraph(g, {directed: true, addReverseEdges: false});
2✔
53

54
        // Run Strongly Connected Components algorithm - returns NodeId[][] directly
55
        const components = stronglyConnectedComponents(graphData);
2✔
56

57
        // Store component assignments for each node
58
        const componentMap = new Map<number | string, number>();
2✔
59
        for (let i = 0; i < components.length; i++) {
2✔
60
            for (const nodeId of components[i]) {
30✔
61
                componentMap.set(nodeId, i);
40✔
62
            }
40✔
63
        }
30✔
64

65
        // Store results on nodes
66
        for (const nodeId of nodes) {
2✔
67
            const componentId = componentMap.get(nodeId) ?? 0;
40!
68
            this.addNodeResult(nodeId, "componentId", componentId);
40✔
69
        }
40✔
70

71
        // Store graph-level results
72
        this.addGraphResult("componentCount", components.length);
2✔
73
    }
2✔
74
}
18✔
75

76
// Auto-register this algorithm when the module is imported
77
Algorithm.register(StronglyConnectedComponentsAlgorithm);
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

© 2025 Coveralls, Inc