@cosmos.gl/graph 2.6.2-rc.0 → 2.7.0-beta.0
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.
- package/.eslintrc +147 -0
- package/.github/SECURITY.md +13 -0
- package/.github/dco.yml +4 -0
- package/.github/workflows/github_pages.yml +54 -0
- package/.storybook/main.ts +26 -0
- package/.storybook/manager-head.html +1 -0
- package/.storybook/manager.ts +14 -0
- package/.storybook/preview.ts +29 -0
- package/.storybook/style.css +3 -0
- package/CHARTER.md +69 -0
- package/CODE_OF_CONDUCT.md +178 -0
- package/CONTRIBUTING.md +22 -0
- package/GOVERNANCE.md +21 -0
- package/cosmos-2-0-migration-notes.md +98 -0
- package/cosmos_awesome.md +96 -0
- package/dist/config.d.ts +5 -9
- package/dist/graph/utils/error-message.d.ts +1 -1
- package/dist/helper.d.ts +39 -2
- package/dist/index-FUIgayhu.js +19827 -0
- package/dist/index-FUIgayhu.js.map +1 -0
- package/dist/index.d.ts +17 -64
- package/dist/index.js +14 -14654
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1062 -475
- package/dist/index.min.js.map +1 -1
- package/dist/modules/Clusters/index.d.ts +11 -3
- package/dist/modules/ForceCenter/index.d.ts +10 -3
- package/dist/modules/ForceGravity/index.d.ts +5 -1
- package/dist/modules/ForceLink/index.d.ts +8 -5
- package/dist/modules/ForceManyBody/index.d.ts +16 -7
- package/dist/modules/ForceMouse/index.d.ts +5 -1
- package/dist/modules/GraphData/index.d.ts +0 -1
- package/dist/modules/Lines/index.d.ts +11 -5
- package/dist/modules/Points/index.d.ts +31 -13
- package/dist/modules/Store/index.d.ts +93 -0
- package/dist/modules/core-module.d.ts +3 -3
- package/dist/stories/beginners/basic-set-up/data-gen.d.ts +4 -0
- package/dist/stories/beginners/basic-set-up/index.d.ts +6 -0
- package/dist/stories/beginners/link-hovering/data-generator.d.ts +19 -0
- package/dist/stories/beginners/link-hovering/index.d.ts +6 -0
- package/dist/stories/beginners/point-labels/data.d.ts +13 -0
- package/dist/stories/beginners/point-labels/index.d.ts +10 -0
- package/dist/stories/beginners/point-labels/labels.d.ts +8 -0
- package/dist/stories/beginners/quick-start.d.ts +6 -0
- package/dist/stories/beginners/remove-points/config.d.ts +2 -0
- package/dist/stories/beginners/remove-points/data-gen.d.ts +4 -0
- package/dist/stories/beginners/remove-points/index.d.ts +6 -0
- package/dist/stories/beginners.stories.d.ts +10 -0
- package/dist/stories/clusters/polygon-selection/index.d.ts +6 -0
- package/dist/stories/clusters/polygon-selection/polygon.d.ts +20 -0
- package/dist/stories/clusters/radial.d.ts +6 -0
- package/dist/stories/clusters/with-labels.d.ts +6 -0
- package/dist/stories/clusters/worm.d.ts +6 -0
- package/dist/stories/clusters.stories.d.ts +9 -0
- package/dist/stories/create-cluster-labels.d.ts +4 -0
- package/dist/stories/create-cosmos.d.ts +17 -0
- package/dist/stories/create-story.d.ts +16 -0
- package/dist/stories/experiments/full-mesh.d.ts +6 -0
- package/dist/stories/experiments/mesh-with-holes.d.ts +6 -0
- package/dist/stories/experiments.stories.d.ts +7 -0
- package/dist/stories/generate-mesh-data.d.ts +12 -0
- package/dist/stories/geospatial/moscow-metro-stations/index.d.ts +16 -0
- package/dist/stories/geospatial/moscow-metro-stations/moscow-metro-coords.d.ts +1 -0
- package/dist/stories/geospatial/moscow-metro-stations/point-colors.d.ts +1 -0
- package/dist/stories/geospatial.stories.d.ts +6 -0
- package/dist/stories/shapes/all-shapes/index.d.ts +6 -0
- package/dist/stories/shapes/image-example/index.d.ts +6 -0
- package/dist/stories/shapes.stories.d.ts +7 -0
- package/dist/stories/test-luma-migration.d.ts +6 -0
- package/dist/stories/test.stories.d.ts +6 -0
- package/dist/webgl-device-B9ewDj5L.js +3923 -0
- package/dist/webgl-device-B9ewDj5L.js.map +1 -0
- package/logo.svg +3 -0
- package/package.json +5 -7
- package/rollup.config.js +70 -0
- package/src/config.ts +728 -0
- package/src/declaration.d.ts +12 -0
- package/src/graph/utils/error-message.ts +23 -0
- package/src/helper.ts +113 -0
- package/src/index.ts +1769 -0
- package/src/modules/Clusters/calculate-centermass.frag +12 -0
- package/src/modules/Clusters/calculate-centermass.vert +38 -0
- package/src/modules/Clusters/force-cluster.frag +55 -0
- package/src/modules/Clusters/index.ts +578 -0
- package/src/modules/Drag/index.ts +33 -0
- package/src/modules/FPSMonitor/css.ts +53 -0
- package/src/modules/FPSMonitor/index.ts +28 -0
- package/src/modules/ForceCenter/calculate-centermass.frag +9 -0
- package/src/modules/ForceCenter/calculate-centermass.vert +26 -0
- package/src/modules/ForceCenter/force-center.frag +37 -0
- package/src/modules/ForceCenter/index.ts +284 -0
- package/src/modules/ForceGravity/force-gravity.frag +40 -0
- package/src/modules/ForceGravity/index.ts +107 -0
- package/src/modules/ForceLink/force-spring.ts +89 -0
- package/src/modules/ForceLink/index.ts +293 -0
- package/src/modules/ForceManyBody/calculate-level.frag +9 -0
- package/src/modules/ForceManyBody/calculate-level.vert +37 -0
- package/src/modules/ForceManyBody/force-centermass.frag +61 -0
- package/src/modules/ForceManyBody/force-level.frag +138 -0
- package/src/modules/ForceManyBody/index.ts +525 -0
- package/src/modules/ForceManyBody/quadtree-frag-shader.ts +89 -0
- package/src/modules/ForceManyBodyQuadtree/calculate-level.frag +9 -0
- package/src/modules/ForceManyBodyQuadtree/calculate-level.vert +25 -0
- package/src/modules/ForceManyBodyQuadtree/index.ts +157 -0
- package/src/modules/ForceManyBodyQuadtree/quadtree-frag-shader.ts +93 -0
- package/src/modules/ForceMouse/force-mouse.frag +35 -0
- package/src/modules/ForceMouse/index.ts +102 -0
- package/src/modules/GraphData/index.ts +383 -0
- package/src/modules/Lines/draw-curve-line.frag +59 -0
- package/src/modules/Lines/draw-curve-line.vert +248 -0
- package/src/modules/Lines/geometry.ts +18 -0
- package/src/modules/Lines/hovered-line-index.frag +43 -0
- package/src/modules/Lines/hovered-line-index.vert +13 -0
- package/src/modules/Lines/index.ts +661 -0
- package/src/modules/Points/atlas-utils.ts +137 -0
- package/src/modules/Points/drag-point.frag +34 -0
- package/src/modules/Points/draw-highlighted.frag +44 -0
- package/src/modules/Points/draw-highlighted.vert +145 -0
- package/src/modules/Points/draw-points.frag +259 -0
- package/src/modules/Points/draw-points.vert +203 -0
- package/src/modules/Points/fill-sampled-points.frag +12 -0
- package/src/modules/Points/fill-sampled-points.vert +51 -0
- package/src/modules/Points/find-hovered-point.frag +15 -0
- package/src/modules/Points/find-hovered-point.vert +90 -0
- package/src/modules/Points/find-points-on-area-selection.frag +88 -0
- package/src/modules/Points/find-points-on-polygon-selection.frag +89 -0
- package/src/modules/Points/index.ts +2292 -0
- package/src/modules/Points/track-positions.frag +30 -0
- package/src/modules/Points/update-position.frag +39 -0
- package/src/modules/Shared/buffer.ts +39 -0
- package/src/modules/Shared/clear.frag +10 -0
- package/src/modules/Shared/quad.vert +13 -0
- package/src/modules/Store/index.ts +283 -0
- package/src/modules/Zoom/index.ts +148 -0
- package/src/modules/core-module.ts +28 -0
- package/src/stories/1. welcome.mdx +75 -0
- package/src/stories/2. configuration.mdx +111 -0
- package/src/stories/3. api-reference.mdx +591 -0
- package/src/stories/beginners/basic-set-up/data-gen.ts +33 -0
- package/src/stories/beginners/basic-set-up/index.ts +167 -0
- package/src/stories/beginners/basic-set-up/style.css +35 -0
- package/src/stories/beginners/link-hovering/data-generator.ts +198 -0
- package/src/stories/beginners/link-hovering/index.ts +65 -0
- package/src/stories/beginners/link-hovering/style.css +73 -0
- package/src/stories/beginners/point-labels/data.ts +73 -0
- package/src/stories/beginners/point-labels/index.ts +69 -0
- package/src/stories/beginners/point-labels/labels.ts +46 -0
- package/src/stories/beginners/point-labels/style.css +16 -0
- package/src/stories/beginners/quick-start.ts +54 -0
- package/src/stories/beginners/remove-points/config.ts +25 -0
- package/src/stories/beginners/remove-points/data-gen.ts +30 -0
- package/src/stories/beginners/remove-points/index.ts +96 -0
- package/src/stories/beginners/remove-points/style.css +31 -0
- package/src/stories/beginners.stories.ts +130 -0
- package/src/stories/clusters/polygon-selection/index.ts +52 -0
- package/src/stories/clusters/polygon-selection/polygon.ts +143 -0
- package/src/stories/clusters/polygon-selection/style.css +8 -0
- package/src/stories/clusters/radial.ts +24 -0
- package/src/stories/clusters/with-labels.ts +54 -0
- package/src/stories/clusters/worm.ts +40 -0
- package/src/stories/clusters.stories.ts +77 -0
- package/src/stories/create-cluster-labels.ts +50 -0
- package/src/stories/create-cosmos.ts +72 -0
- package/src/stories/create-story.ts +51 -0
- package/src/stories/experiments/full-mesh.ts +13 -0
- package/src/stories/experiments/mesh-with-holes.ts +13 -0
- package/src/stories/experiments.stories.ts +43 -0
- package/src/stories/generate-mesh-data.ts +125 -0
- package/src/stories/geospatial/moscow-metro-stations/index.ts +66 -0
- package/src/stories/geospatial/moscow-metro-stations/moscow-metro-coords.ts +1 -0
- package/src/stories/geospatial/moscow-metro-stations/point-colors.ts +46 -0
- package/src/stories/geospatial/moscow-metro-stations/style.css +30 -0
- package/src/stories/geospatial.stories.ts +30 -0
- package/src/stories/shapes/all-shapes/index.ts +73 -0
- package/src/stories/shapes/image-example/icons/box.png +0 -0
- package/src/stories/shapes/image-example/icons/lego.png +0 -0
- package/src/stories/shapes/image-example/icons/s.png +0 -0
- package/src/stories/shapes/image-example/icons/swift.png +0 -0
- package/src/stories/shapes/image-example/icons/toolbox.png +0 -0
- package/src/stories/shapes/image-example/index.ts +246 -0
- package/src/stories/shapes.stories.ts +37 -0
- package/src/stories/test-luma-migration.ts +195 -0
- package/src/stories/test.stories.ts +25 -0
- package/src/variables.ts +68 -0
- package/tsconfig.json +41 -0
- package/vite.config.ts +52 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { scaleSequential } from 'd3-scale'
|
|
2
|
+
import { interpolateWarm } from 'd3-scale-chromatic'
|
|
3
|
+
import { getRgbaColor } from '@cosmos.gl/graph'
|
|
4
|
+
|
|
5
|
+
export const getPointColors = (pointPositions: number[]): Float32Array => {
|
|
6
|
+
const pointColorScale = scaleSequential(interpolateWarm)
|
|
7
|
+
const numPoints = pointPositions.length / 2
|
|
8
|
+
|
|
9
|
+
// Calculate center coordinates
|
|
10
|
+
let centerX = 0
|
|
11
|
+
let centerY = 0
|
|
12
|
+
for (let i = 0, idx = 0; i < numPoints; i++, idx += 2) {
|
|
13
|
+
centerX += pointPositions[idx] as number
|
|
14
|
+
centerY += pointPositions[idx + 1] as number
|
|
15
|
+
}
|
|
16
|
+
centerX /= numPoints
|
|
17
|
+
centerY /= numPoints
|
|
18
|
+
|
|
19
|
+
// Find maximum distance from center (using squared distance for optimization)
|
|
20
|
+
let maxDistanceSquared = 0
|
|
21
|
+
for (let i = 0, idx = 0; i < numPoints; i++, idx += 2) {
|
|
22
|
+
const dx = (pointPositions[idx] as number) - centerX
|
|
23
|
+
const dy = (pointPositions[idx + 1] as number) - centerY
|
|
24
|
+
const distanceSquared = dx * dx + dy * dy
|
|
25
|
+
if (distanceSquared > maxDistanceSquared) maxDistanceSquared = distanceSquared
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pointColorScale.domain([0, Math.sqrt(maxDistanceSquared)])
|
|
29
|
+
|
|
30
|
+
// Calculate colors
|
|
31
|
+
const pointColors = new Float32Array(numPoints * 4)
|
|
32
|
+
for (let i = 0, posIdx = 0, colorIdx = 0; i < numPoints; i++, posIdx += 2, colorIdx += 4) {
|
|
33
|
+
const dx = (pointPositions[posIdx] as number) - centerX
|
|
34
|
+
const dy = (pointPositions[posIdx + 1] as number) - centerY
|
|
35
|
+
const distance = Math.sqrt(dx * dx + dy * dy)
|
|
36
|
+
const pointColor = pointColorScale(distance)
|
|
37
|
+
const rgba = getRgbaColor(pointColor)
|
|
38
|
+
|
|
39
|
+
pointColors[colorIdx] = rgba[0]
|
|
40
|
+
pointColors[colorIdx + 1] = rgba[1]
|
|
41
|
+
pointColors[colorIdx + 2] = rgba[2]
|
|
42
|
+
pointColors[colorIdx + 3] = rgba[3]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return pointColors
|
|
46
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
body {
|
|
2
|
+
font-family: "Nunito Sans", -apple-system, ".SFNSText-Regular", "San Francisco", BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
3
|
+
margin: 0px;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.app {
|
|
7
|
+
position: absolute;
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.graph {
|
|
13
|
+
width: 100%;
|
|
14
|
+
height: 100vh;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.actions {
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 10px;
|
|
20
|
+
left: 10px;
|
|
21
|
+
color: #ccc;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.action {
|
|
25
|
+
margin-left: 2px;
|
|
26
|
+
font-size: 10pt;
|
|
27
|
+
text-decoration: underline;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
user-select: none;
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/html'
|
|
2
|
+
|
|
3
|
+
import { createStory, Story } from '@/graph/stories/create-story'
|
|
4
|
+
import { CosmosStoryProps } from './create-cosmos'
|
|
5
|
+
import { moscowMetroStations } from './geospatial/moscow-metro-stations'
|
|
6
|
+
|
|
7
|
+
import moscowMetroStationsStoryRaw from './geospatial/moscow-metro-stations/index?raw'
|
|
8
|
+
import dataRaw from './geospatial/moscow-metro-stations/moscow-metro-coords?raw'
|
|
9
|
+
import pointColorsRaw from './geospatial/moscow-metro-stations/point-colors?raw'
|
|
10
|
+
import styleRaw from './geospatial/moscow-metro-stations/style.css?raw'
|
|
11
|
+
|
|
12
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
13
|
+
const meta: Meta<CosmosStoryProps> = {
|
|
14
|
+
title: 'Examples/Geospatial',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const MoscowMetroStations: Story = {
|
|
18
|
+
...createStory(moscowMetroStations),
|
|
19
|
+
parameters: {
|
|
20
|
+
sourceCode: [
|
|
21
|
+
{ name: 'Story', code: moscowMetroStationsStoryRaw },
|
|
22
|
+
{ name: 'moscow-metro-coords', code: dataRaw },
|
|
23
|
+
{ name: 'point-colors', code: pointColorsRaw },
|
|
24
|
+
{ name: 'style.css', code: styleRaw },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line import/no-default-export
|
|
30
|
+
export default meta
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Graph, PointShape } from '@cosmos.gl/graph'
|
|
2
|
+
|
|
3
|
+
export const allShapes = (): {div: HTMLDivElement; graph: Graph; destroy?: () => void } => {
|
|
4
|
+
// Create container div
|
|
5
|
+
const div = document.createElement('div')
|
|
6
|
+
div.style.height = '100vh'
|
|
7
|
+
div.style.width = '100%'
|
|
8
|
+
|
|
9
|
+
// Create 8 points, one for each shape
|
|
10
|
+
const spaceSize = 4096
|
|
11
|
+
const pointCount = 8
|
|
12
|
+
const spacing = spaceSize / pointCount
|
|
13
|
+
|
|
14
|
+
const pointPositions = new Float32Array(pointCount * 2)
|
|
15
|
+
const pointColors = new Float32Array(pointCount * 4)
|
|
16
|
+
const pointShapes = new Float32Array(pointCount)
|
|
17
|
+
|
|
18
|
+
// Define distinct colors for each shape
|
|
19
|
+
const shapeColors: [number, number, number][] = [
|
|
20
|
+
[1.0, 0.42, 0.38], // Coral for Circle
|
|
21
|
+
[0.13, 0.55, 0.45], // Forest Green for Square
|
|
22
|
+
[0.25, 0.32, 0.71], // Royal Blue for Triangle
|
|
23
|
+
[0.96, 0.76, 0.19], // Amber Gold for Diamond
|
|
24
|
+
[0.74, 0.24, 0.45], // Deep Rose for Pentagon
|
|
25
|
+
[0.18, 0.55, 0.56], // Teal for Hexagon
|
|
26
|
+
[0.85, 0.45, 0.28], // Terracotta for Star
|
|
27
|
+
[0.58, 0.44, 0.86], // Periwinkle for Cross
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
// Position points in a horizontal line
|
|
31
|
+
const startX = spacing / 2
|
|
32
|
+
const centerY = spaceSize / 2
|
|
33
|
+
for (let i = 0; i < pointCount; i++) {
|
|
34
|
+
// Position: horizontal line, centered
|
|
35
|
+
pointPositions[i * 2] = startX + i * spacing
|
|
36
|
+
pointPositions[i * 2 + 1] = centerY
|
|
37
|
+
|
|
38
|
+
// Color: distinct color for each shape
|
|
39
|
+
const color = shapeColors[i] || [1.0, 1.0, 1.0] // fallback to white if undefined
|
|
40
|
+
pointColors[i * 4] = color[0] // R
|
|
41
|
+
pointColors[i * 4 + 1] = color[1] // G
|
|
42
|
+
pointColors[i * 4 + 2] = color[2] // B
|
|
43
|
+
pointColors[i * 4 + 3] = 1.0 // A
|
|
44
|
+
|
|
45
|
+
// Shape: cycle through all available shapes
|
|
46
|
+
pointShapes[i] = i as PointShape
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Create graph with minimal configuration
|
|
50
|
+
const graph = new Graph(div, {
|
|
51
|
+
spaceSize,
|
|
52
|
+
pointSize: spacing / 2,
|
|
53
|
+
enableSimulation: false,
|
|
54
|
+
scalePointsOnZoom: true,
|
|
55
|
+
renderHoveredPointRing: true,
|
|
56
|
+
hoveredPointRingColor: '#ffffff',
|
|
57
|
+
rescalePositions: false,
|
|
58
|
+
enableDrag: true,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Set data
|
|
62
|
+
graph.setPointPositions(pointPositions)
|
|
63
|
+
graph.setPointColors(pointColors)
|
|
64
|
+
graph.setPointShapes(pointShapes)
|
|
65
|
+
|
|
66
|
+
graph.render()
|
|
67
|
+
|
|
68
|
+
const destroy = (): void => {
|
|
69
|
+
graph.destroy()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { div, graph, destroy }
|
|
73
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Graph, PointShape } from '@cosmos.gl/graph'
|
|
2
|
+
|
|
3
|
+
// Import all PNG icons
|
|
4
|
+
import boxUrl from './icons/box.png'
|
|
5
|
+
import toolboxUrl from './icons/toolbox.png'
|
|
6
|
+
import swiftUrl from './icons/swift.png'
|
|
7
|
+
import legoUrl from './icons/lego.png'
|
|
8
|
+
import sUrl from './icons/s.png'
|
|
9
|
+
|
|
10
|
+
// Helper function to convert PNG URL to ImageData
|
|
11
|
+
const pngUrlToImageData = (pngUrl: string): Promise<ImageData> => {
|
|
12
|
+
return new Promise<ImageData>((resolve, reject) => {
|
|
13
|
+
const img = new Image()
|
|
14
|
+
|
|
15
|
+
img.onload = (): void => {
|
|
16
|
+
const canvas = document.createElement('canvas')
|
|
17
|
+
const ctx = canvas.getContext('2d')
|
|
18
|
+
if (!ctx) {
|
|
19
|
+
reject(new Error('Could not get 2D context'))
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
canvas.width = img.width
|
|
24
|
+
canvas.height = img.height
|
|
25
|
+
ctx.drawImage(img, 0, 0)
|
|
26
|
+
|
|
27
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
|
28
|
+
resolve(imageData)
|
|
29
|
+
}
|
|
30
|
+
img.onerror = (): void => reject(new Error(`Failed to load image: ${pngUrl}`))
|
|
31
|
+
img.src = pngUrl
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const loadPngImages = (pngUrls: string[]): Promise<ImageData[]> => {
|
|
36
|
+
return Promise.all(pngUrls.map(pngUrlToImageData))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Define node types for Xcode dependency graph
|
|
40
|
+
enum NodeType {
|
|
41
|
+
App = 0, // Main app target (swift icon)
|
|
42
|
+
Framework = 1, // Framework (box icon)
|
|
43
|
+
Library = 2, // Static library (toolbox icon)
|
|
44
|
+
Bundle = 3, // Bundle (lego icon)
|
|
45
|
+
Target = 4 // Build target (s icon)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface DependencyNode {
|
|
49
|
+
id: number;
|
|
50
|
+
name: string;
|
|
51
|
+
type: NodeType;
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
dependencies: number[];
|
|
55
|
+
size: number;
|
|
56
|
+
color: [number, number, number, number];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const imageExample = (): {div: HTMLDivElement; graph: Graph; destroy?: () => void } => {
|
|
60
|
+
// Create container div
|
|
61
|
+
const div = document.createElement('div')
|
|
62
|
+
div.style.height = '100vh'
|
|
63
|
+
div.style.width = '100%'
|
|
64
|
+
div.style.display = 'flex'
|
|
65
|
+
div.style.flexDirection = 'column'
|
|
66
|
+
|
|
67
|
+
// Create main graph container
|
|
68
|
+
const graphContainer = document.createElement('div')
|
|
69
|
+
graphContainer.style.height = '100vh'
|
|
70
|
+
graphContainer.style.width = '100%'
|
|
71
|
+
graphContainer.style.position = 'absolute'
|
|
72
|
+
graphContainer.style.overflow = 'hidden'
|
|
73
|
+
div.appendChild(graphContainer)
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const spaceSize = 4096
|
|
77
|
+
|
|
78
|
+
const nodes: DependencyNode[] = [
|
|
79
|
+
// Main app target (center)
|
|
80
|
+
{ id: 0, name: 'MyApp', type: NodeType.App, x: 2048, y: 2048, dependencies: [1, 2, 3, 14], size: 60, color: [0.2, 0.6, 1.0, 1.0] },
|
|
81
|
+
|
|
82
|
+
// Frameworks (first ring around center)
|
|
83
|
+
{ id: 1, name: 'CoreData', type: NodeType.Framework, x: 1024, y: 2048, dependencies: [4, 5], size: 50, color: [0.8, 0.4, 0.2, 1.0] },
|
|
84
|
+
{ id: 2, name: 'UIKit', type: NodeType.Framework, x: 2048, y: 1024, dependencies: [6, 15], size: 50, color: [0.8, 0.4, 0.2, 1.0] },
|
|
85
|
+
{ id: 3, name: 'Network', type: NodeType.Framework, x: 3072, y: 2048, dependencies: [7, 8], size: 50, color: [0.8, 0.4, 0.2, 1.0] },
|
|
86
|
+
|
|
87
|
+
// Libraries (second ring)
|
|
88
|
+
{ id: 4, name: 'SQLite', type: NodeType.Library, x: 512, y: 2048, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
89
|
+
{ id: 5, name: 'Foundation', type: NodeType.Library, x: 1024, y: 1024, dependencies: [16], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
90
|
+
{ id: 6, name: 'CoreGraphics', type: NodeType.Library, x: 2048, y: 512, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
91
|
+
{ id: 7, name: 'Security', type: NodeType.Library, x: 3072, y: 1024, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
92
|
+
{ id: 8, name: 'CFNetwork', type: NodeType.Library, x: 3584, y: 2048, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
93
|
+
|
|
94
|
+
// Additional frameworks (first ring)
|
|
95
|
+
{ id: 9, name: 'Analytics', type: NodeType.Framework, x: 2048, y: 3072, dependencies: [10, 17], size: 50, color: [0.8, 0.4, 0.2, 1.0] },
|
|
96
|
+
{ id: 10, name: 'Firebase', type: NodeType.Library, x: 2048, y: 3840, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
97
|
+
|
|
98
|
+
// Test targets (outer ring)
|
|
99
|
+
{ id: 11, name: 'Tests', type: NodeType.Target, x: 512, y: 1024, dependencies: [0], size: 50, color: [0.4, 0.6, 1.0, 1.0] },
|
|
100
|
+
{ id: 12, name: 'UITests', type: NodeType.Target, x: 3584, y: 1024, dependencies: [0, 2], size: 45, color: [0.4, 0.6, 1.0, 1.0] },
|
|
101
|
+
{ id: 13, name: 'Widget', type: NodeType.Target, x: 3584, y: 3072, dependencies: [1, 2], size: 45, color: [0.4, 0.6, 1.0, 1.0] },
|
|
102
|
+
|
|
103
|
+
// Additional components
|
|
104
|
+
{ id: 14, name: 'Localization', type: NodeType.Framework, x: 1536, y: 3072, dependencies: [18], size: 50, color: [0.8, 0.4, 0.2, 1.0] },
|
|
105
|
+
{ id: 15, name: 'CoreAnimation', type: NodeType.Library, x: 2560, y: 512, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
106
|
+
{ id: 16, name: 'CoreFoundation', type: NodeType.Library, x: 1024, y: 512, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
107
|
+
{ id: 17, name: 'Crashlytics', type: NodeType.Library, x: 1536, y: 3584, dependencies: [], size: 45, color: [0.6, 0.8, 0.4, 1.0] },
|
|
108
|
+
{ id: 18, name: 'LocalizationBundle', type: NodeType.Bundle, x: 1792, y: 3584, dependencies: [], size: 45, color: [1.0, 0.4, 1.0, 1.0] },
|
|
109
|
+
|
|
110
|
+
// More test targets
|
|
111
|
+
{ id: 19, name: 'UnitTests', type: NodeType.Target, x: 512, y: 3072, dependencies: [0, 1], size: 45, color: [0.4, 0.6, 1.0, 1.0] },
|
|
112
|
+
{ id: 20, name: 'IntegrationTests', type: NodeType.Target, x: 512, y: 3584, dependencies: [0, 3], size: 45, color: [0.4, 0.6, 1.0, 1.0] },
|
|
113
|
+
|
|
114
|
+
// Bundle resources
|
|
115
|
+
{ id: 21, name: 'Resources', type: NodeType.Bundle, x: 2304, y: 3072, dependencies: [0], size: 50, color: [1.0, 0.4, 1.0, 1.0] },
|
|
116
|
+
{ id: 22, name: 'Assets', type: NodeType.Bundle, x: 2560, y: 3584, dependencies: [0, 21], size: 50, color: [1.0, 0.4, 1.0, 1.0] },
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
const pointCount = nodes.length
|
|
120
|
+
const pointPositions = new Float32Array(pointCount * 2)
|
|
121
|
+
const pointColors = new Float32Array(pointCount * 4)
|
|
122
|
+
const pointShapes = new Float32Array(pointCount)
|
|
123
|
+
const pointSizes = new Float32Array(pointCount)
|
|
124
|
+
const imageIndices = new Float32Array(pointCount)
|
|
125
|
+
|
|
126
|
+
// Create links array for dependencies
|
|
127
|
+
const links: number[] = []
|
|
128
|
+
const linkArrows: boolean[] = []
|
|
129
|
+
const linkColors: number[] = []
|
|
130
|
+
|
|
131
|
+
// Set up nodes based on the dependency structure
|
|
132
|
+
for (const node of nodes) {
|
|
133
|
+
const i = node.id
|
|
134
|
+
|
|
135
|
+
// Set positions
|
|
136
|
+
pointPositions[i * 2] = node.x
|
|
137
|
+
pointPositions[i * 2 + 1] = node.y
|
|
138
|
+
|
|
139
|
+
// Set node properties - use None shape for all images except targets (s icon)
|
|
140
|
+
pointShapes[i] = node.type === NodeType.Target ? PointShape.Hexagon : PointShape.None
|
|
141
|
+
pointSizes[i] = node.size
|
|
142
|
+
imageIndices[i] = node.type
|
|
143
|
+
|
|
144
|
+
// Set colors
|
|
145
|
+
pointColors[i * 4] = node.color[0]
|
|
146
|
+
pointColors[i * 4 + 1] = node.color[1]
|
|
147
|
+
pointColors[i * 4 + 2] = node.color[2]
|
|
148
|
+
pointColors[i * 4 + 3] = node.color[3]
|
|
149
|
+
|
|
150
|
+
// Add dependency links
|
|
151
|
+
for (const depId of node.dependencies) {
|
|
152
|
+
links.push(i, depId)
|
|
153
|
+
linkArrows.push(true)
|
|
154
|
+
|
|
155
|
+
// Add colorful link colors based on source node type
|
|
156
|
+
const sourceType = node.type
|
|
157
|
+
let linkColor: [number, number, number, number]
|
|
158
|
+
|
|
159
|
+
switch (sourceType) {
|
|
160
|
+
case NodeType.App:
|
|
161
|
+
linkColor = [0.2, 0.8, 1.0, 0.8] // Bright blue
|
|
162
|
+
break
|
|
163
|
+
case NodeType.Framework:
|
|
164
|
+
linkColor = [1.0, 0.6, 0.2, 0.8] // Orange
|
|
165
|
+
break
|
|
166
|
+
case NodeType.Library:
|
|
167
|
+
linkColor = [0.4, 1.0, 0.4, 0.8] // Green
|
|
168
|
+
break
|
|
169
|
+
case NodeType.Bundle:
|
|
170
|
+
linkColor = [1.0, 0.4, 1.0, 0.8] // Magenta
|
|
171
|
+
break
|
|
172
|
+
case NodeType.Target:
|
|
173
|
+
linkColor = [0.8, 0.4, 1.0, 0.8] // Purple
|
|
174
|
+
break
|
|
175
|
+
default:
|
|
176
|
+
linkColor = [0.7, 0.7, 0.7, 0.8] // Gray
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Add RGBA values for this link
|
|
180
|
+
linkColors.push(linkColor[0], linkColor[1], linkColor[2], linkColor[3])
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Create graph with static positioning
|
|
185
|
+
const graph = new Graph(graphContainer, {
|
|
186
|
+
spaceSize,
|
|
187
|
+
enableSimulation: false,
|
|
188
|
+
enableDrag: false,
|
|
189
|
+
linkArrows: true,
|
|
190
|
+
curvedLinks: true,
|
|
191
|
+
pointSize: 50,
|
|
192
|
+
linkWidth: 3,
|
|
193
|
+
hoveredPointRingColor: 'white',
|
|
194
|
+
renderHoveredPointRing: true,
|
|
195
|
+
|
|
196
|
+
// Add click handler for point and background selection
|
|
197
|
+
onPointClick: (pointIndex: number): void => {
|
|
198
|
+
// Use built-in functionality to select the clicked point and its neighbors
|
|
199
|
+
graph.selectPointByIndex(pointIndex, true)
|
|
200
|
+
},
|
|
201
|
+
onBackgroundClick: (): void => {
|
|
202
|
+
// Clear selection when clicking on background
|
|
203
|
+
graph.unselectPoints()
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
// Load images asynchronously and set them when ready
|
|
208
|
+
loadPngImages([swiftUrl, boxUrl, toolboxUrl, legoUrl, sUrl]).then((imageDataArray) => {
|
|
209
|
+
// Set images and their indices
|
|
210
|
+
graph.setImageData(imageDataArray)
|
|
211
|
+
graph.setPointImageIndices(imageIndices)
|
|
212
|
+
graph.render()
|
|
213
|
+
}).catch((error) => {
|
|
214
|
+
console.error('Error loading images:', error)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
// Set all data
|
|
218
|
+
graph.setPointPositions(pointPositions)
|
|
219
|
+
graph.setPointColors(pointColors)
|
|
220
|
+
graph.setPointShapes(pointShapes)
|
|
221
|
+
graph.setPointSizes(pointSizes)
|
|
222
|
+
|
|
223
|
+
// Set links if we have any dependencies
|
|
224
|
+
if (links.length > 0) {
|
|
225
|
+
graph.setLinks(new Float32Array(links))
|
|
226
|
+
graph.setLinkArrows(linkArrows)
|
|
227
|
+
graph.setLinkColors(new Float32Array(linkColors))
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
graph.render()
|
|
231
|
+
|
|
232
|
+
const destroy = (): void => {
|
|
233
|
+
graph.destroy()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return { div, graph, destroy }
|
|
237
|
+
} catch (error) {
|
|
238
|
+
console.error('Error creating Xcode dependency graph:', error)
|
|
239
|
+
div.innerHTML = `
|
|
240
|
+
<div style="display: flex; align-items: center; justify-content: center; height: 100%; color: #ff0000; font-size: 18px;">
|
|
241
|
+
Error loading Xcode dependency graph: ${error instanceof Error ? error.message : 'Unknown error'}
|
|
242
|
+
</div>
|
|
243
|
+
`
|
|
244
|
+
throw error
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Meta } from '@storybook/html'
|
|
2
|
+
|
|
3
|
+
import { createStory, Story } from '@/graph/stories/create-story'
|
|
4
|
+
import { CosmosStoryProps } from './create-cosmos'
|
|
5
|
+
import { allShapes } from './shapes/all-shapes'
|
|
6
|
+
import { imageExample } from './shapes/image-example'
|
|
7
|
+
|
|
8
|
+
import allShapesStoryRaw from './shapes/all-shapes/index?raw'
|
|
9
|
+
import imageExampleStoryRaw from './shapes/image-example/index?raw'
|
|
10
|
+
|
|
11
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
12
|
+
const meta: Meta<CosmosStoryProps> = {
|
|
13
|
+
title: 'Examples/Shapes',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const AllShapes: Story = {
|
|
17
|
+
...createStory(allShapes),
|
|
18
|
+
name: 'All Point Shapes',
|
|
19
|
+
parameters: {
|
|
20
|
+
sourceCode: [
|
|
21
|
+
{ name: 'Story', code: allShapesStoryRaw },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const ImageExample: Story = {
|
|
27
|
+
...createStory(imageExample),
|
|
28
|
+
name: 'Image Points Example',
|
|
29
|
+
parameters: {
|
|
30
|
+
sourceCode: [
|
|
31
|
+
{ name: 'Story', code: imageExampleStoryRaw },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line import/no-default-export
|
|
37
|
+
export default meta
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Graph, GraphConfigInterface } from '@cosmos.gl/graph'
|
|
2
|
+
|
|
3
|
+
export const testLumaMigration = (): { graph: Graph; div: HTMLDivElement; destroy?: () => void } => {
|
|
4
|
+
const div = document.createElement('div')
|
|
5
|
+
div.style.height = '100vh'
|
|
6
|
+
div.style.width = '100%'
|
|
7
|
+
|
|
8
|
+
const config: GraphConfigInterface = {
|
|
9
|
+
spaceSize: 4096,
|
|
10
|
+
backgroundColor: '#f25a8a', // '#2d313a',
|
|
11
|
+
pointColor: '#f069b4',
|
|
12
|
+
pointSize: 40,
|
|
13
|
+
scalePointsOnZoom: true,
|
|
14
|
+
simulationGravity: 0,
|
|
15
|
+
// simulationCenter: 1,
|
|
16
|
+
simulationRepulsion: 10,
|
|
17
|
+
// simulationCluster: 0.05, // Cluster force strength
|
|
18
|
+
simulationRepulsionFromMouse: 100,
|
|
19
|
+
enableRightClickRepulsion: true,
|
|
20
|
+
curvedLinks: false,
|
|
21
|
+
fitViewDelay: 1000,
|
|
22
|
+
fitViewPadding: 0.3,
|
|
23
|
+
rescalePositions: true,
|
|
24
|
+
enableDrag: true,
|
|
25
|
+
renderHoveredPointRing: true,
|
|
26
|
+
hoveredPointCursor: 'pointer',
|
|
27
|
+
hoveredPointRingColor: 'orange',
|
|
28
|
+
focusedPointIndex: 0,
|
|
29
|
+
focusedPointRingColor: 'blue',
|
|
30
|
+
enableSimulation: true,
|
|
31
|
+
linkArrows: true,
|
|
32
|
+
linkArrowsSizeScale: 2,
|
|
33
|
+
linkColor: 'orange',
|
|
34
|
+
linkWidth: 2,
|
|
35
|
+
linkOpacity: 1,
|
|
36
|
+
linkGreyoutOpacity: 0.1,
|
|
37
|
+
hoveredLinkColor: 'red',
|
|
38
|
+
scaleLinksOnZoom: true,
|
|
39
|
+
// renderLinks: false,
|
|
40
|
+
onLinkMouseOver: linkIndex => {
|
|
41
|
+
console.log('Hovered link index: ', linkIndex)
|
|
42
|
+
},
|
|
43
|
+
// Test point interactions
|
|
44
|
+
onPointClick: pointIndex => {
|
|
45
|
+
console.log('Clicked point index: ', pointIndex)
|
|
46
|
+
},
|
|
47
|
+
onPointMouseOver: pointIndex => {
|
|
48
|
+
console.log('Hovered point index: ', pointIndex)
|
|
49
|
+
},
|
|
50
|
+
onBackgroundClick: () => {
|
|
51
|
+
// console.log('Clicked background')
|
|
52
|
+
// // const points = graph.getPointsInRect([[0, 0], [100, 100]])
|
|
53
|
+
// // console.log('Points: ', points)
|
|
54
|
+
// const polygonPath = [[0, 0], [100, 0], [100, 100], [0, 100]] as [number, number][]
|
|
55
|
+
// const points = graph?.getPointsInPolygon(polygonPath)
|
|
56
|
+
// console.log('Points: ', points)
|
|
57
|
+
},
|
|
58
|
+
onZoomEnd: () => {
|
|
59
|
+
// const sampledPointIndices = graph?.getSampledPoints().indices
|
|
60
|
+
// console.log('Sampled point indices: ', sampledPointIndices)
|
|
61
|
+
// if (sampledPointIndices) {
|
|
62
|
+
// graph?.selectPointsByIndices(sampledPointIndices)
|
|
63
|
+
// }
|
|
64
|
+
},
|
|
65
|
+
attribution: 'visualized with <a href="https://cosmograph.app/" style="color: var(--cosmosgl-attribution-color);" target="_blank">Cosmograph</a>',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Create graph
|
|
69
|
+
const graph = new Graph(div, config)
|
|
70
|
+
|
|
71
|
+
// Create a grid of points to test rendering with different colors and sizes
|
|
72
|
+
const pointCount = 100
|
|
73
|
+
const gridSize = Math.ceil(Math.sqrt(pointCount))
|
|
74
|
+
const pointPositions = new Float32Array(pointCount * 2)
|
|
75
|
+
const pointColors = new Float32Array(pointCount * 4) // RGBA for each point
|
|
76
|
+
const pointSizes = new Float32Array(pointCount) // Size for each point
|
|
77
|
+
const pointShapes = new Float32Array(pointCount) // Shape for each point
|
|
78
|
+
|
|
79
|
+
// Define a palette of colors (RGBA values normalized to 0-1)
|
|
80
|
+
const colorPalette = [
|
|
81
|
+
[1.0, 0.0, 0.0, 0.5], // Red
|
|
82
|
+
[0.0, 1.0, 0.0, 0.5], // Green
|
|
83
|
+
[0.0, 0.0, 1.0, 0.5], // Blue
|
|
84
|
+
[1.0, 1.0, 0.0, 0.5], // Yellow
|
|
85
|
+
[1.0, 0.0, 1.0, 0.5], // Magenta
|
|
86
|
+
[0.0, 1.0, 1.0, 0.5], // Cyan
|
|
87
|
+
[1.0, 0.5, 0.0, 0.5], // Orange
|
|
88
|
+
[0.5, 0.0, 1.0, 0.5], // Purple
|
|
89
|
+
[0.94, 0.41, 0.71, 0.5], // Pink (#f069b4)
|
|
90
|
+
[0.95, 0.35, 0.54, 0.5], // Rose (#f25a8a)
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
// Size range: 10 to 60
|
|
94
|
+
const minSize = 10
|
|
95
|
+
const maxSize = 60
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < pointCount; i++) {
|
|
98
|
+
// Position in grid
|
|
99
|
+
const x = (i % gridSize) * 100 - (gridSize * 50)
|
|
100
|
+
const y = Math.floor(i / gridSize) * 100 - (gridSize * 50)
|
|
101
|
+
pointPositions[i * 2] = x
|
|
102
|
+
pointPositions[i * 2 + 1] = y
|
|
103
|
+
|
|
104
|
+
// Assign color from palette (cycling through colors)
|
|
105
|
+
const colorIndex = i % colorPalette.length
|
|
106
|
+
const color = colorPalette[colorIndex]!
|
|
107
|
+
pointColors[i * 4] = color[0]! // R
|
|
108
|
+
pointColors[i * 4 + 1] = color[1]! // G
|
|
109
|
+
pointColors[i * 4 + 2] = color[2]! // B
|
|
110
|
+
pointColors[i * 4 + 3] = color[3]! // A
|
|
111
|
+
|
|
112
|
+
// Assign size (varying sizes, could be based on position, index, or random)
|
|
113
|
+
// Using a pattern: larger points in center, smaller at edges
|
|
114
|
+
const centerX = (gridSize - 1) / 2
|
|
115
|
+
const centerY = (gridSize - 1) / 2
|
|
116
|
+
const pointX = i % gridSize
|
|
117
|
+
const pointY = Math.floor(i / gridSize)
|
|
118
|
+
const distFromCenter = Math.sqrt(
|
|
119
|
+
Math.pow(pointX - centerX, 2) + Math.pow(pointY - centerY, 2)
|
|
120
|
+
)
|
|
121
|
+
const maxDist = Math.sqrt(Math.pow(centerX, 2) + Math.pow(centerY, 2))
|
|
122
|
+
// Size decreases from center to edge, with some variation
|
|
123
|
+
const normalizedDist = distFromCenter / maxDist
|
|
124
|
+
const baseSize = minSize + (maxSize - minSize) * (1 - normalizedDist)
|
|
125
|
+
// Add some variation based on index for more visual interest
|
|
126
|
+
const variation = (i % 3) * 5 // Add 0, 5, or 10 pixels variation
|
|
127
|
+
pointSizes[i] = Math.max(minSize, Math.min(maxSize, baseSize + variation))
|
|
128
|
+
|
|
129
|
+
// Assign shape (cycling through available shapes: Circle, Square, Triangle, Diamond, Pentagon, Hexagon, Star, Cross)
|
|
130
|
+
// Shape values: 0 = Circle, 1 = Square, 2 = Triangle, 3 = Diamond, 4 = Pentagon, 5 = Hexagon, 6 = Star, 7 = Cross, 8 = None
|
|
131
|
+
const shapeIndex = i % 8 // Cycle through shapes 0-7 (excluding None)
|
|
132
|
+
pointShapes[i] = shapeIndex
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
graph.setPointPositions(pointPositions)
|
|
136
|
+
graph.setPointColors(pointColors)
|
|
137
|
+
graph.setPointSizes(pointSizes)
|
|
138
|
+
graph.setPointShapes(pointShapes)
|
|
139
|
+
|
|
140
|
+
// Create cluster assignments - group points into clusters based on their shape
|
|
141
|
+
// Points with the same shape will be in the same cluster
|
|
142
|
+
const pointClusters: (number | undefined)[] = []
|
|
143
|
+
const numShapes = 8 // Number of different shapes (0-7)
|
|
144
|
+
for (let i = 0; i < pointCount; i++) {
|
|
145
|
+
const shapeIndex = i % numShapes
|
|
146
|
+
// Assign each shape group to a cluster (cluster index = shape index)
|
|
147
|
+
pointClusters.push(shapeIndex)
|
|
148
|
+
}
|
|
149
|
+
// graph.setPointClusters(pointClusters)
|
|
150
|
+
|
|
151
|
+
// Optionally set explicit cluster positions (centered around the grid)
|
|
152
|
+
// If not set, clusters will use centermass (average position of points in cluster)
|
|
153
|
+
const clusterPositions: (number | undefined)[] = []
|
|
154
|
+
for (let clusterIndex = 0; clusterIndex < numShapes; clusterIndex++) {
|
|
155
|
+
// Position clusters in a circle around the center
|
|
156
|
+
const angle = (clusterIndex / numShapes) * Math.PI * 2
|
|
157
|
+
const radius = gridSize * 30 // Distance from center
|
|
158
|
+
const x = Math.cos(angle) * radius
|
|
159
|
+
const y = Math.sin(angle) * radius
|
|
160
|
+
clusterPositions.push(x, y)
|
|
161
|
+
}
|
|
162
|
+
// graph.setClusterPositions(clusterPositions)
|
|
163
|
+
|
|
164
|
+
// Create links to test link rendering
|
|
165
|
+
const links = new Float32Array((pointCount - 1) * 2)
|
|
166
|
+
for (let i = 0; i < pointCount - 1; i++) {
|
|
167
|
+
links[i * 2] = i
|
|
168
|
+
links[i * 2 + 1] = i + 1
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
graph.setLinks(links)
|
|
172
|
+
|
|
173
|
+
graph.render()
|
|
174
|
+
graph.trackPointPositionsByIndices([0, 1])
|
|
175
|
+
|
|
176
|
+
// Dynamic update: change links 5s after initial rendering
|
|
177
|
+
// setTimeout(() => {
|
|
178
|
+
// if (!graph) return
|
|
179
|
+
// // Create a simple star topology: node 0 connected to all others
|
|
180
|
+
// const dynamicLinks = new Float32Array((pointCount - 1) * 2)
|
|
181
|
+
// for (let i = 1; i < pointCount; i++) {
|
|
182
|
+
// dynamicLinks[(i - 1) * 2] = 0
|
|
183
|
+
// dynamicLinks[(i - 1) * 2 + 1] = i
|
|
184
|
+
// }
|
|
185
|
+
// graph.setLinks(dynamicLinks)
|
|
186
|
+
// graph.setConfig({ renderLinks: true })
|
|
187
|
+
// graph.render()
|
|
188
|
+
// }, 5000)
|
|
189
|
+
|
|
190
|
+
const destroy = (): void => {
|
|
191
|
+
graph.destroy()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return { div, graph, destroy }
|
|
195
|
+
}
|