• 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/ConnectedComponentsAlgorithm.ts
1
import {connectedComponents} 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 ConnectedComponentsAlgorithm extends Algorithm {
15✔
11
    static namespace = "graphty";
18✔
12
    static type = "connected-components";
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.connected-components.componentId"],
11✔
24
                        output: "style.texture.color",
11✔
25
                        expr: "{ return StyleHelpers.color.categorical.carbon(arguments[0] ?? 0) }",
11✔
26
                    },
11✔
27
                },
11✔
28
                metadata: {
11✔
29
                    name: "Components - Carbon Colors",
11✔
30
                    description: "5 IBM design system colors for components",
11✔
31
                },
11✔
32
            },
11✔
33
        ],
11✔
34
        description: "Visualizes connected components with distinct colors",
11✔
35
        category: "grouping",
11✔
36
    });
11✔
37

38
    /**
39
     * Executes the connected components algorithm on the graph
40
     *
41
     * Identifies connected components and assigns each node to a component.
42
     */
43
    async run(): Promise<void> {
18✔
44
        const g = this.graph;
3✔
45
        const nodes = Array.from(g.getDataManager().nodes.keys());
3✔
46

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

51
        // Convert to @graphty/algorithms format (truly undirected for connected components)
52
        // addReverseEdges: false creates an undirected graph required by connectedComponents
53
        const graphData = toAlgorithmGraph(g, {addReverseEdges: false});
3✔
54

55
        // Run Connected Components algorithm - returns NodeId[][] directly
56
        const components = connectedComponents(graphData);
3✔
57

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

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

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

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