@graphty/layout 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.github/workflows/ci.yml +105 -0
  2. package/.releaserc.json +22 -0
  3. package/CHANGELOG.md +24 -0
  4. package/CLAUDE.md +104 -0
  5. package/CONTRIBUTING.md +1 -0
  6. package/README.md +893 -34
  7. package/dist/layout-helpers.d.ts +123 -0
  8. package/dist/layout-helpers.js +457 -0
  9. package/dist/layout-helpers.js.map +1 -0
  10. package/dist/layout.d.ts +275 -0
  11. package/dist/layout.js +2280 -0
  12. package/dist/layout.js.map +1 -0
  13. package/dist/vitest.config.d.ts +2 -0
  14. package/dist/vitest.config.js +30 -0
  15. package/dist/vitest.config.js.map +1 -0
  16. package/examples/arf-layout.html +1 -1
  17. package/examples/bfs-layout.html +37 -39
  18. package/examples/bipartite-layout.html +77 -69
  19. package/examples/circular-layout.html +13 -34
  20. package/examples/forceatlas2-layout.html +122 -28
  21. package/examples/kamada-kawai-layout.html +1 -1
  22. package/examples/multipartite-layout.html +64 -51
  23. package/examples/planar-layout.html +1 -1
  24. package/examples/random-layout.html +1 -1
  25. package/examples/shell-layout.html +53 -34
  26. package/examples/spectral-layout.html +1 -1
  27. package/examples/spiral-layout.html +1 -1
  28. package/examples/spring-layout.html +12 -2
  29. package/layout-helpers.ts +559 -0
  30. package/{layout.js → layout.ts} +1261 -771
  31. package/package.json +22 -6
  32. package/test/arf-layout.test.ts +443 -0
  33. package/test/bfs-layout.test.ts +427 -0
  34. package/test/bipartite-layout.test.ts +344 -0
  35. package/test/circular-layout.test.ts +300 -0
  36. package/test/forceatlas2-layout.test.ts +405 -0
  37. package/test/fruchterman-reingold-layout.test.ts +477 -0
  38. package/test/graph-generators.test.ts +450 -0
  39. package/test/kamada-kawai-layout.test.ts +351 -0
  40. package/test/multipartite-layout.test.ts +404 -0
  41. package/test/planar-layout.test.ts +266 -0
  42. package/test/random-layout.test.ts +254 -0
  43. package/test/rescale-layout.test.ts +373 -0
  44. package/test/shell-layout.test.ts +347 -0
  45. package/test/spectral-layout.test.ts +378 -0
  46. package/test/spiral-layout.test.ts +338 -0
  47. package/test/spring-layout.test.ts +241 -0
  48. package/tsconfig.json +16 -0
  49. package/vitest.config.ts +30 -0
  50. package/.husky/commit-msg +0 -1
  51. package/.husky/prepare-commit-msg +0 -1
@@ -0,0 +1,105 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, develop ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ name: Test
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [18.x, 20.x, 22.x]
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Setup Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ cache: 'npm'
27
+
28
+ - name: Install dependencies
29
+ run: npm ci
30
+
31
+ - name: Run TypeScript compiler
32
+ run: npm run build
33
+
34
+ - name: Run tests
35
+ run: npm run test:run
36
+
37
+ - name: Run tests with coverage
38
+ run: npm run test:coverage
39
+ if: matrix.node-version == '20.x'
40
+
41
+ - name: Upload coverage reports to Codecov
42
+ uses: codecov/codecov-action@v4
43
+ if: matrix.node-version == '20.x'
44
+ with:
45
+ file: ./coverage/lcov.info
46
+ flags: unittests
47
+ name: codecov-umbrella
48
+ fail_ci_if_error: false
49
+ env:
50
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
51
+
52
+ lint:
53
+ name: Lint
54
+ runs-on: ubuntu-latest
55
+
56
+ steps:
57
+ - name: Checkout code
58
+ uses: actions/checkout@v4
59
+
60
+ - name: Setup Node.js
61
+ uses: actions/setup-node@v4
62
+ with:
63
+ node-version: '20.x'
64
+ cache: 'npm'
65
+
66
+ - name: Install dependencies
67
+ run: npm ci
68
+
69
+ - name: Check TypeScript types
70
+ run: npx tsc --noEmit
71
+
72
+ - name: Run commitlint on PR title
73
+ if: github.event_name == 'pull_request'
74
+ run: echo "${{ github.event.pull_request.title }}" | npx commitlint
75
+
76
+ release:
77
+ name: Release
78
+ runs-on: ubuntu-latest
79
+ needs: [test, lint]
80
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
81
+
82
+ steps:
83
+ - name: Checkout code
84
+ uses: actions/checkout@v4
85
+ with:
86
+ fetch-depth: 0
87
+ token: ${{ secrets.GITHUB_TOKEN }}
88
+
89
+ - name: Setup Node.js
90
+ uses: actions/setup-node@v4
91
+ with:
92
+ node-version: '20.x'
93
+ cache: 'npm'
94
+
95
+ - name: Install dependencies
96
+ run: npm ci
97
+
98
+ - name: Build package
99
+ run: npm run build
100
+
101
+ - name: Release
102
+ env:
103
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
105
+ run: npx semantic-release
@@ -0,0 +1,22 @@
1
+ {
2
+ "branches": ["main"],
3
+ "plugins": [
4
+ "@semantic-release/commit-analyzer",
5
+ "@semantic-release/release-notes-generator",
6
+ "@semantic-release/changelog",
7
+ [
8
+ "@semantic-release/npm",
9
+ {
10
+ "npmPublish": true
11
+ }
12
+ ],
13
+ [
14
+ "@semantic-release/git",
15
+ {
16
+ "assets": ["package.json", "package-lock.json", "CHANGELOG.md"],
17
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
18
+ }
19
+ ],
20
+ "@semantic-release/github"
21
+ ]
22
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ ## [1.1.1](https://github.com/graphty-org/layout/compare/v1.1.0...v1.1.1) (2025-07-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * correct main entry point to dist/layout.js ([4e9f95b](https://github.com/graphty-org/layout/commit/4e9f95bfae3d2974808fa4a306b677e95d9706b9))
7
+
8
+ # 1.0.0 (2025-07-12)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * flakey test ([8de0d14](https://github.com/graphty-org/layout/commit/8de0d147f7267b5715c4529db64014578ee06c97))
14
+ * improve performance test reliability for CI ([0a41ee2](https://github.com/graphty-org/layout/commit/0a41ee238bdbaa1f4d68d864998b24bd4c59ff3d))
15
+ * increase test timeout for CI environments ([36b20a8](https://github.com/graphty-org/layout/commit/36b20a8ea0811cdac7d97975ab0490f2cf29b6ae))
16
+ * make ForceAtlas2 balanced layout test more tolerant ([78fb975](https://github.com/graphty-org/layout/commit/78fb975053dd25d26e351626170fe73d2b68b677))
17
+ * remove conflicting .releaserc file ([1fffa82](https://github.com/graphty-org/layout/commit/1fffa821219774efab8203fc2ea7943493ad1825))
18
+ * resolve CI pipeline and test coverage issues ([9c60656](https://github.com/graphty-org/layout/commit/9c606562074bafc234499f4f2637a55730195af3))
19
+ * update tests to import from TypeScript source instead of dist ([d000b23](https://github.com/graphty-org/layout/commit/d000b23c301fe84807958e54f29ba4ca682818fd))
20
+
21
+
22
+ ### Features
23
+
24
+ * add layout helpers ([d43562c](https://github.com/graphty-org/layout/commit/d43562c02a68720f96905ad4c969e12c0a0e5db4))
package/CLAUDE.md ADDED
@@ -0,0 +1,104 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ @graphty/layout is a TypeScript graph layout library that ports NetworkX Python algorithms to JavaScript. All layout algorithms are implemented in a single file: `layout.ts`.
8
+
9
+ ## Key Commands
10
+
11
+ ### Development
12
+ ```bash
13
+ # Build TypeScript to JavaScript
14
+ npm run build
15
+
16
+ # Watch mode for development
17
+ npm run watch
18
+ # or
19
+ npm run dev
20
+
21
+ # Currently no test framework is configured
22
+ # npm test exits with error code 1
23
+ ```
24
+
25
+ ### Git Commits
26
+ This project uses conventional commits with commitizen:
27
+ ```bash
28
+ # Use commitizen for formatted commits
29
+ npm run commit
30
+ ```
31
+
32
+ Commit types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
33
+
34
+ ## Architecture
35
+
36
+ The entire library is contained in `layout.ts` with the following structure:
37
+
38
+ 1. **Type System** (lines 1-50):
39
+ - `Node`: string | number
40
+ - `Edge`: [Node, Node]
41
+ - `Graph`: Interface with adjacency(), nodes(), edges() methods
42
+ - `PositionMap`: Map<Node, Position> for storing layouts
43
+
44
+ 2. **NumPy-like Utilities** (lines 50-500):
45
+ - Array manipulation functions under `np` object
46
+ - Used for mathematical operations in layout algorithms
47
+
48
+ 3. **Layout Algorithms** (lines 500-2591):
49
+ - Force-directed: springLayout, forceatlas2Layout, arfLayout, kamadaKawaiLayout
50
+ - Geometric: randomLayout, circularLayout, shellLayout, spiralLayout
51
+ - Specialized: spectralLayout, bipartiteLayout, multipartiteLayout, bfsLayout, planarLayout
52
+ - Utilities: rescaleLayout, rescaleLayoutDict
53
+
54
+ Each algorithm returns a `PositionMap` with node positions.
55
+
56
+ ## Module System
57
+
58
+ This is an ES module project (`"type": "module"` in package.json). When importing:
59
+ ```typescript
60
+ import { springLayout, circularLayout } from '@graphty/layout';
61
+ ```
62
+
63
+ ## Common Tasks
64
+
65
+ ### Adding a New Layout Algorithm
66
+ 1. Add the function to `layout.ts` following the existing pattern
67
+ 2. Export it at the bottom of the file
68
+ 3. Update README.md with documentation and example
69
+ 4. Add an example HTML file in `examples/`
70
+
71
+ ### Modifying Build Output
72
+ Edit `tsconfig.json`. Current settings:
73
+ - Target: ES2020
74
+ - Module: ES2020
75
+ - Output: `dist/` directory
76
+ - Generates declaration files and source maps
77
+
78
+ ## Testing
79
+
80
+ ### Running Tests
81
+ ```bash
82
+ npm test # Run tests in watch mode
83
+ npm run test:run # Run tests once
84
+ npm run test:coverage # Run with coverage report
85
+ ```
86
+
87
+ ### Testing Preferences
88
+ - Use `assert` instead of `expect` for test assertions
89
+ - Tests are organized by layout algorithm in `test/` directory
90
+ - Each test file covers: basic functionality, parameter variations, edge cases, and algorithm-specific behaviors
91
+ - Graph generation utilities are available for creating test graphs
92
+
93
+ ## Important Notes
94
+
95
+ - All algorithms should match NetworkX Python library behavior where possible
96
+ - Graph interface is minimal - algorithms work with any object providing nodes() and edges() methods
97
+ - Examples in `examples/` directory demonstrate usage patterns
98
+ - Tests serve as additional documentation for expected behavior
99
+
100
+ ## Claude Preferences
101
+
102
+ - NEVER automatically stage files with git add or create commits
103
+ - NEVER create commits unless explicitly requested by the user
104
+ - User prefers to handle git operations manually
@@ -0,0 +1 @@
1
+ # Graphty Layout Algorithms