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

graphty-org / graphty-element / 20390753610

20 Dec 2025 06:53AM UTC coverage: 82.423% (-1.2%) from 83.666%
20390753610

push

github

apowers313
Merge branch 'master' of https://github.com/graphty-org/graphty-element

5162 of 6088 branches covered (84.79%)

Branch coverage included in aggregate %.

24775 of 30233 relevant lines covered (81.95%)

6480.4 hits per line

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

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

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

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

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

44
export class SpectralLayout extends SimpleLayoutEngine {
2✔
45
    static type = "spectral";
2✔
46
    static maxDimensions = 2;
2✔
47
    static zodOptionsSchema: OptionsSchema = spectralLayoutOptionsSchema;
2✔
48
    scalingFactor = 100;
2✔
49
    config: SpectralLayoutConfigType;
50

51
    constructor(opts: SpectralLayoutOpts) {
2✔
52
        super(opts);
1✔
53
        this.config = SpectralLayoutConfig.parse(opts);
1✔
54
    }
1✔
55

56
    static getOptionsForDimension(dimension: 2 | 3): object | null {
2✔
57
        // Spectral layout only supports 2D
58
        if (dimension > this.maxDimensions) {
1✔
59
            return null;
1✔
60
        }
1!
61

62
        return {dim: dimension};
×
63
    }
1✔
64

65
    doLayout(): void {
2✔
66
        this.stale = false;
1✔
67
        const nodes = (): LayoutNode[] => this._nodes.map((n) => n.id as LayoutNode);
1✔
68
        const edges = (): LayoutEdge[] => this._edges.map((e) => [e.srcId, e.dstId] as LayoutEdge);
1✔
69

70
        this.positions = spectralLayout(
1✔
71
            {nodes, edges},
1✔
72
            this.config.scale,
1✔
73
            this.config.center,
1✔
74
            this.config.dim,
1✔
75
        );
1✔
76
    }
1✔
77
}
2✔
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