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

graphty-org / graphty-element / 19792929756

30 Nov 2025 02:57AM UTC coverage: 86.308% (+3.9%) from 82.377%
19792929756

push

github

apowers313
docs: fix stories for chromatic

3676 of 4303 branches covered (85.43%)

Branch coverage included in aggregate %.

17 of 17 new or added lines in 2 files covered. (100.0%)

1093 existing lines in 30 files now uncovered.

17371 of 20083 relevant lines covered (86.5%)

7075.46 hits per line

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

92.59
/src/algorithms/DegreeAlgorithm.ts
1
import type {SuggestedStylesConfig} from "../config";
2
import {Algorithm} from "./Algorithm";
3✔
3
import {toAlgorithmGraph} from "./utils/graphConverter";
3✔
4

5
export class DegreeAlgorithm extends Algorithm {
3✔
6
    static namespace = "graphty";
5✔
7
    static type = "degree";
81✔
8

9
    static suggestedStyles = (): SuggestedStylesConfig => ({
81✔
10
        layers: [
12✔
11
            {
12✔
12
                node: {
12✔
13
                    selector: "",
12✔
14
                    style: {
12✔
15
                        enabled: true,
12✔
16
                    },
12✔
17
                    calculatedStyle: {
12✔
18
                        inputs: ["algorithmResults.graphty.degree.degreePct"],
12✔
19
                        output: "style.texture.color",
12✔
20
                        expr: "{ return StyleHelpers.color.sequential.viridis(arguments[0]) }",
12✔
21
                    },
12✔
22
                },
12✔
23
                metadata: {
12✔
24
                    name: "Degree - Viridis Gradient",
12✔
25
                    description: "Purple (low) → Yellow (high) - colorblind-safe",
12✔
26
                },
12✔
27
            },
12✔
28
        ],
12✔
29
        description: "Visualizes node importance through color based on connection count",
12✔
30
        category: "node-metric",
12✔
31
    });
12✔
32

33
    // eslint-disable-next-line @typescript-eslint/require-await
34
    async run(): Promise<void> {
5✔
35
        const g = this.graph;
14✔
36
        const nodes = Array.from(g.getDataManager().nodes.keys());
14✔
37

38
        if (nodes.length === 0) {
14!
UNCOV
39
            return;
×
UNCOV
40
        }
×
41

42
        // Convert to @graphty/algorithms format - use directed mode to get accurate in/out degrees
43
        const graphData = toAlgorithmGraph(g, {directed: true, addReverseEdges: false});
14✔
44

45
        // Calculate degrees using the @graphty/algorithms Graph methods
46
        let maxInDegree = 0;
14✔
47
        let maxOutDegree = 0;
14✔
48
        let maxDegree = 0;
14✔
49

50
        const degreeResults = new Map<number | string, {inDegree: number, outDegree: number, degree: number}>();
14✔
51

52
        for (const nodeId of nodes) {
14✔
53
            const inDegree = graphData.inDegree(nodeId);
289✔
54
            const outDegree = graphData.outDegree(nodeId);
289✔
55
            const degree = inDegree + outDegree;
289✔
56

57
            degreeResults.set(nodeId, {inDegree, outDegree, degree});
289✔
58

59
            maxInDegree = Math.max(maxInDegree, inDegree);
289✔
60
            maxOutDegree = Math.max(maxOutDegree, outDegree);
289✔
61
            maxDegree = Math.max(maxDegree, degree);
289✔
62
        }
289✔
63

64
        // Store graph-level results
65
        this.addGraphResult("maxInDegree", maxInDegree);
14✔
66
        this.addGraphResult("maxOutDegree", maxOutDegree);
14✔
67
        this.addGraphResult("maxDegree", maxDegree);
14✔
68

69
        // Store node-level results
70
        for (const nodeId of nodes) {
14✔
71
            const result = degreeResults.get(nodeId);
289✔
72
            if (!result) {
289!
UNCOV
73
                continue;
×
UNCOV
74
            }
×
75

76
            const {inDegree, outDegree, degree} = result;
289✔
77

78
            this.addNodeResult(nodeId, "inDegree", inDegree);
289✔
79
            this.addNodeResult(nodeId, "outDegree", outDegree);
289✔
80
            this.addNodeResult(nodeId, "degree", degree);
289✔
81
            // Safe division: return 0 when max is 0 to avoid NaN
82
            this.addNodeResult(nodeId, "inDegreePct", maxInDegree > 0 ? inDegree / maxInDegree : 0);
289✔
83
            this.addNodeResult(nodeId, "outDegreePct", maxOutDegree > 0 ? outDegree / maxOutDegree : 0);
289✔
84
            this.addNodeResult(nodeId, "degreePct", maxDegree > 0 ? degree / maxDegree : 0);
289✔
85
        }
289✔
86
    }
14✔
87
}
5✔
88

89
// Auto-register this algorithm when the module is imported
90
Algorithm.register(DegreeAlgorithm);
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