• 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

95.71
/src/layout/SpectralLayoutEngine.ts
1
import {Edge as LayoutEdge, Node as LayoutNode, spectralLayout} from "@graphty/layout";
14!
2
import {z} from "zod/v4";
14✔
3

4
import {defineOptions, type OptionsSchema} from "../config";
14✔
5
import {SimpleLayoutConfig, SimpleLayoutEngine} from "./LayoutEngine";
14✔
6

7
/**
8
 * Zod-based options schema for Spectral Layout
9
 */
10
export const spectralLayoutOptionsSchema = defineOptions({
14✔
11
    scalingFactor: {
14✔
12
        schema: z.number().min(1).max(1000).default(100),
14✔
13
        meta: {
14✔
14
            label: "Scaling Factor",
14✔
15
            description: "Multiplier for node positions",
14✔
16
        },
14✔
17
    },
14✔
18
    scale: {
14✔
19
        schema: z.number().positive().default(1),
14✔
20
        meta: {
14✔
21
            label: "Scale",
14✔
22
            description: "Scale factor for the spectral layout",
14✔
23
            step: 0.1,
14✔
24
        },
14✔
25
    },
14✔
26
    dim: {
14✔
27
        schema: z.number().int().min(2).max(2).default(2),
14✔
28
        meta: {
14✔
29
            label: "Dimensions",
14✔
30
            description: "Layout dimensionality (2D only for spectral)",
14✔
31
        },
14✔
32
    },
14✔
33
});
14✔
34

35
export const SpectralLayoutConfig = z.strictObject({
14✔
36
    ... SimpleLayoutConfig.shape,
14✔
37
    scale: z.number().positive().default(1),
14✔
38
    center: z.array(z.number()).length(2).or(z.null()).default(null),
14✔
39
    dim: z.number().default(2),
14✔
40
});
14✔
41
export type SpectralLayoutConfigType = z.infer<typeof SpectralLayoutConfig>;
42
export type SpectralLayoutOpts = Partial<SpectralLayoutConfigType>;
43

44
/**
45
 * Spectral layout engine using graph Laplacian eigenvectors
46
 */
47
export class SpectralLayout extends SimpleLayoutEngine {
14✔
48
    static type = "spectral";
14✔
49
    static maxDimensions = 2;
14✔
50
    static zodOptionsSchema: OptionsSchema = spectralLayoutOptionsSchema;
14✔
51
    scalingFactor = 100;
14✔
52
    config: SpectralLayoutConfigType;
53

54
    /**
55
     * Create a spectral layout engine
56
     * @param opts - Configuration options including scale and center
57
     */
58
    constructor(opts: SpectralLayoutOpts) {
14✔
59
        super(opts);
1✔
60
        this.config = SpectralLayoutConfig.parse(opts);
1✔
61
    }
1✔
62

63
    /**
64
     * Get dimension-specific options for spectral layout
65
     * @param dimension - The desired dimension (2 or 3)
66
     * @returns Options object with dim parameter or null for 3D (unsupported)
67
     */
68
    static getOptionsForDimension(dimension: 2 | 3): object | null {
14✔
69
        // Spectral layout only supports 2D
70
        if (dimension > this.maxDimensions) {
1✔
71
            return null;
1✔
72
        }
1!
73

74
        return {dim: dimension};
×
75
    }
1✔
76

77
    /**
78
     * Compute node positions using spectral graph theory
79
     */
80
    doLayout(): void {
14✔
81
        this.stale = false;
1✔
82
        const nodes = (): LayoutNode[] => this._nodes.map((n) => n.id as LayoutNode);
1✔
83
        const edges = (): LayoutEdge[] => this._edges.map((e) => [e.srcId, e.dstId] as LayoutEdge);
1✔
84

85
        this.positions = spectralLayout(
1✔
86
            {nodes, edges},
1✔
87
            this.config.scale,
1✔
88
            this.config.center,
1✔
89
            this.config.dim,
1✔
90
        );
1✔
91
    }
1✔
92
}
14✔
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