@cosmos.gl/graph 2.6.0 → 2.6.2-rc.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/dist/config.d.ts +3 -0
- package/dist/index.d.ts +48 -6
- package/dist/index.js +1346 -1289
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +15 -15
- package/dist/index.min.js.map +1 -1
- package/package.json +5 -1
- package/.eslintrc +0 -147
- package/.github/SECURITY.md +0 -19
- package/.github/dco.yml +0 -4
- package/.github/workflows/github_pages.yml +0 -54
- package/.storybook/main.ts +0 -26
- package/.storybook/manager-head.html +0 -1
- package/.storybook/manager.ts +0 -14
- package/.storybook/preview.ts +0 -29
- package/.storybook/style.css +0 -3
- package/CHARTER.md +0 -69
- package/CODE_OF_CONDUCT.md +0 -178
- package/CONTRIBUTING.md +0 -22
- package/GOVERNANCE.md +0 -21
- package/cosmos-2-0-migration-notes.md +0 -98
- package/cosmos_awesome.md +0 -96
- package/dist/stories/beginners/basic-set-up/data-gen.d.ts +0 -4
- package/dist/stories/beginners/basic-set-up/index.d.ts +0 -5
- package/dist/stories/beginners/link-hovering/data-generator.d.ts +0 -19
- package/dist/stories/beginners/link-hovering/index.d.ts +0 -5
- package/dist/stories/beginners/pinned-points/data-gen.d.ts +0 -5
- package/dist/stories/beginners/pinned-points/index.d.ts +0 -5
- package/dist/stories/beginners/point-labels/data.d.ts +0 -13
- package/dist/stories/beginners/point-labels/index.d.ts +0 -9
- package/dist/stories/beginners/point-labels/labels.d.ts +0 -8
- package/dist/stories/beginners/quick-start.d.ts +0 -5
- package/dist/stories/beginners/remove-points/config.d.ts +0 -2
- package/dist/stories/beginners/remove-points/data-gen.d.ts +0 -4
- package/dist/stories/beginners/remove-points/index.d.ts +0 -5
- package/dist/stories/beginners.stories.d.ts +0 -11
- package/dist/stories/clusters/polygon-selection/index.d.ts +0 -6
- package/dist/stories/clusters/polygon-selection/polygon.d.ts +0 -20
- package/dist/stories/clusters/radial.d.ts +0 -5
- package/dist/stories/clusters/with-labels.d.ts +0 -6
- package/dist/stories/clusters/worm.d.ts +0 -5
- package/dist/stories/clusters.stories.d.ts +0 -9
- package/dist/stories/create-cluster-labels.d.ts +0 -4
- package/dist/stories/create-cosmos.d.ts +0 -16
- package/dist/stories/create-story.d.ts +0 -16
- package/dist/stories/experiments/full-mesh.d.ts +0 -5
- package/dist/stories/experiments/mesh-with-holes.d.ts +0 -5
- package/dist/stories/experiments.stories.d.ts +0 -7
- package/dist/stories/generate-mesh-data.d.ts +0 -12
- package/dist/stories/geospatial/moscow-metro-stations/index.d.ts +0 -15
- package/dist/stories/geospatial/moscow-metro-stations/moscow-metro-coords.d.ts +0 -1
- package/dist/stories/geospatial/moscow-metro-stations/point-colors.d.ts +0 -1
- package/dist/stories/geospatial.stories.d.ts +0 -6
- package/dist/stories/shapes/all-shapes/index.d.ts +0 -5
- package/dist/stories/shapes/image-example/index.d.ts +0 -5
- package/dist/stories/shapes.stories.d.ts +0 -7
- package/logo.svg +0 -3
- package/rollup.config.js +0 -70
- package/src/config.ts +0 -734
- package/src/declaration.d.ts +0 -12
- package/src/graph/utils/error-message.ts +0 -23
- package/src/helper.ts +0 -74
- package/src/index.ts +0 -1635
- package/src/modules/Clusters/calculate-centermass.frag +0 -9
- package/src/modules/Clusters/calculate-centermass.vert +0 -26
- package/src/modules/Clusters/force-cluster.frag +0 -39
- package/src/modules/Clusters/index.ts +0 -200
- package/src/modules/Drag/index.ts +0 -33
- package/src/modules/FPSMonitor/css.ts +0 -53
- package/src/modules/FPSMonitor/index.ts +0 -28
- package/src/modules/ForceCenter/calculate-centermass.frag +0 -9
- package/src/modules/ForceCenter/calculate-centermass.vert +0 -18
- package/src/modules/ForceCenter/force-center.frag +0 -27
- package/src/modules/ForceCenter/index.ts +0 -104
- package/src/modules/ForceGravity/force-gravity.frag +0 -27
- package/src/modules/ForceGravity/index.ts +0 -33
- package/src/modules/ForceLink/force-spring.ts +0 -73
- package/src/modules/ForceLink/index.ts +0 -149
- package/src/modules/ForceManyBody/calculate-level.frag +0 -9
- package/src/modules/ForceManyBody/calculate-level.vert +0 -25
- package/src/modules/ForceManyBody/force-centermass.frag +0 -52
- package/src/modules/ForceManyBody/force-level.frag +0 -121
- package/src/modules/ForceManyBody/index.ts +0 -223
- package/src/modules/ForceManyBody/quadtree-frag-shader.ts +0 -90
- package/src/modules/ForceManyBodyQuadtree/calculate-level.frag +0 -9
- package/src/modules/ForceManyBodyQuadtree/calculate-level.vert +0 -25
- package/src/modules/ForceManyBodyQuadtree/index.ts +0 -157
- package/src/modules/ForceManyBodyQuadtree/quadtree-frag-shader.ts +0 -93
- package/src/modules/ForceMouse/force-mouse.frag +0 -24
- package/src/modules/ForceMouse/index.ts +0 -32
- package/src/modules/GraphData/index.ts +0 -384
- package/src/modules/Lines/draw-curve-line.frag +0 -46
- package/src/modules/Lines/draw-curve-line.vert +0 -194
- package/src/modules/Lines/geometry.ts +0 -18
- package/src/modules/Lines/hovered-line-index.frag +0 -27
- package/src/modules/Lines/hovered-line-index.vert +0 -8
- package/src/modules/Lines/index.ts +0 -273
- package/src/modules/Points/atlas-utils.ts +0 -137
- package/src/modules/Points/drag-point.frag +0 -20
- package/src/modules/Points/draw-highlighted.frag +0 -16
- package/src/modules/Points/draw-highlighted.vert +0 -86
- package/src/modules/Points/draw-points.frag +0 -243
- package/src/modules/Points/draw-points.vert +0 -127
- package/src/modules/Points/fill-sampled-points.frag +0 -9
- package/src/modules/Points/fill-sampled-points.vert +0 -29
- package/src/modules/Points/find-hovered-point.frag +0 -9
- package/src/modules/Points/find-hovered-point.vert +0 -57
- package/src/modules/Points/find-points-on-area-selection.frag +0 -48
- package/src/modules/Points/find-points-on-polygon-selection.frag +0 -65
- package/src/modules/Points/index.ts +0 -968
- package/src/modules/Points/track-positions.frag +0 -18
- package/src/modules/Points/update-position.frag +0 -37
- package/src/modules/Shared/buffer.ts +0 -37
- package/src/modules/Shared/clear.frag +0 -7
- package/src/modules/Shared/quad.vert +0 -12
- package/src/modules/Store/index.ts +0 -173
- package/src/modules/Zoom/index.ts +0 -148
- package/src/modules/core-module.ts +0 -28
- package/src/stories/1. welcome.mdx +0 -81
- package/src/stories/2. configuration.mdx +0 -113
- package/src/stories/3. api-reference.mdx +0 -591
- package/src/stories/beginners/basic-set-up/data-gen.ts +0 -33
- package/src/stories/beginners/basic-set-up/index.ts +0 -163
- package/src/stories/beginners/basic-set-up/style.css +0 -35
- package/src/stories/beginners/link-hovering/data-generator.ts +0 -198
- package/src/stories/beginners/link-hovering/index.ts +0 -61
- package/src/stories/beginners/link-hovering/style.css +0 -73
- package/src/stories/beginners/pinned-points/data-gen.ts +0 -153
- package/src/stories/beginners/pinned-points/index.ts +0 -61
- package/src/stories/beginners/point-labels/data.ts +0 -73
- package/src/stories/beginners/point-labels/index.ts +0 -65
- package/src/stories/beginners/point-labels/labels.ts +0 -46
- package/src/stories/beginners/point-labels/style.css +0 -16
- package/src/stories/beginners/quick-start.ts +0 -50
- package/src/stories/beginners/remove-points/config.ts +0 -25
- package/src/stories/beginners/remove-points/data-gen.ts +0 -30
- package/src/stories/beginners/remove-points/index.ts +0 -92
- package/src/stories/beginners/remove-points/style.css +0 -31
- package/src/stories/beginners.stories.ts +0 -131
- package/src/stories/clusters/polygon-selection/index.ts +0 -51
- package/src/stories/clusters/polygon-selection/polygon.ts +0 -143
- package/src/stories/clusters/polygon-selection/style.css +0 -8
- package/src/stories/clusters/radial.ts +0 -24
- package/src/stories/clusters/with-labels.ts +0 -53
- package/src/stories/clusters/worm.ts +0 -40
- package/src/stories/clusters.stories.ts +0 -77
- package/src/stories/create-cluster-labels.ts +0 -50
- package/src/stories/create-cosmos.ts +0 -68
- package/src/stories/create-story.ts +0 -51
- package/src/stories/experiments/full-mesh.ts +0 -13
- package/src/stories/experiments/mesh-with-holes.ts +0 -13
- package/src/stories/experiments.stories.ts +0 -43
- package/src/stories/generate-mesh-data.ts +0 -125
- package/src/stories/geospatial/moscow-metro-stations/index.ts +0 -62
- package/src/stories/geospatial/moscow-metro-stations/moscow-metro-coords.ts +0 -1
- package/src/stories/geospatial/moscow-metro-stations/point-colors.ts +0 -46
- package/src/stories/geospatial/moscow-metro-stations/style.css +0 -30
- package/src/stories/geospatial.stories.ts +0 -30
- package/src/stories/shapes/all-shapes/index.ts +0 -69
- 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 +0 -238
- package/src/stories/shapes.stories.ts +0 -37
- package/src/variables.ts +0 -68
- package/tsconfig.json +0 -41
- package/vite.config.ts +0 -54
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { scaleLinear, scaleSequential } from 'd3-scale'
|
|
2
|
-
import { interpolateWarm } from 'd3-scale-chromatic'
|
|
3
|
-
import { getRgbaColor } from '@cosmos.gl/graph'
|
|
4
|
-
|
|
5
|
-
function getRandom (min: number, max: number): number {
|
|
6
|
-
return Math.random() * (max - min) + min
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function getPositionOnCircle (radius: number, angle: number, center: number): [number, number] {
|
|
10
|
-
const x = center + radius * Math.cos(angle)
|
|
11
|
-
const y = center + radius * Math.sin(angle)
|
|
12
|
-
return [x, y]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type MeshData = {
|
|
16
|
-
pointPositions: Float32Array;
|
|
17
|
-
pointColors: Float32Array;
|
|
18
|
-
pointSizes: Float32Array;
|
|
19
|
-
|
|
20
|
-
links: Float32Array;
|
|
21
|
-
linkColors: Float32Array;
|
|
22
|
-
linkWidths: Float32Array;
|
|
23
|
-
// linkStrength: Float32Array;
|
|
24
|
-
|
|
25
|
-
pointClusters: number[];
|
|
26
|
-
clusterPositions: number[];
|
|
27
|
-
clusterStrength: Float32Array;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function generateMeshData (
|
|
31
|
-
n: number,
|
|
32
|
-
m: number,
|
|
33
|
-
nClusters: number,
|
|
34
|
-
wholeness: number,
|
|
35
|
-
radialness = [10, 1000]
|
|
36
|
-
): MeshData {
|
|
37
|
-
const pointColorScale = scaleSequential(interpolateWarm)
|
|
38
|
-
pointColorScale.domain([0, nClusters])
|
|
39
|
-
const radius = scaleLinear(radialness)
|
|
40
|
-
radius.domain([0, nClusters])
|
|
41
|
-
|
|
42
|
-
const pointPositions = new Float32Array(n * m * 2)
|
|
43
|
-
const links: number[] = []
|
|
44
|
-
const pointClusters = new Array(n * m)
|
|
45
|
-
const clusterPositions = new Array(nClusters * 2)
|
|
46
|
-
const clusterStrength = new Float32Array(n * m)
|
|
47
|
-
const pointColors = new Float32Array(n * m * 4)
|
|
48
|
-
const pointSizes = new Float32Array(n * m)
|
|
49
|
-
|
|
50
|
-
// The maximum texture size can vary between devices and WebGL versions
|
|
51
|
-
// The space size should be less than the maximum texture size to ensure better visual quality of the generated mesh.
|
|
52
|
-
const gl = document.createElement('canvas').getContext('webgl')
|
|
53
|
-
const spaceSize = (gl?.getParameter(gl.MAX_TEXTURE_SIZE) ?? 16384) / 2
|
|
54
|
-
gl?.getExtension('WEBGL_lose_context')?.loseContext()
|
|
55
|
-
|
|
56
|
-
for (let clusterIndex = 0; clusterIndex < nClusters; clusterIndex += 1) {
|
|
57
|
-
const [x, y] = getPositionOnCircle(radius(clusterIndex), 15 * Math.PI * (clusterIndex / nClusters), spaceSize / 2)
|
|
58
|
-
clusterPositions[clusterIndex * 2] = x
|
|
59
|
-
clusterPositions[clusterIndex * 2 + 1] = y
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
for (let pointIndex = 0; pointIndex < n * m; pointIndex += 1) {
|
|
63
|
-
const x = spaceSize * getRandom(0.495, 0.505)
|
|
64
|
-
const y = spaceSize * getRandom(0.495, 0.505)
|
|
65
|
-
pointPositions[pointIndex * 2] = x
|
|
66
|
-
pointPositions[pointIndex * 2 + 1] = y
|
|
67
|
-
|
|
68
|
-
pointClusters[pointIndex] = pointIndex % nClusters
|
|
69
|
-
clusterStrength[pointIndex] = (nClusters - (pointIndex % nClusters)) / nClusters
|
|
70
|
-
const pointColor = pointColorScale(pointIndex % nClusters)
|
|
71
|
-
const rgba = getRgbaColor(pointColor)
|
|
72
|
-
pointColors[pointIndex * 4] = rgba[0]
|
|
73
|
-
pointColors[pointIndex * 4 + 1] = rgba[1]
|
|
74
|
-
pointColors[pointIndex * 4 + 2] = rgba[2]
|
|
75
|
-
pointColors[pointIndex * 4 + 3] = rgba[3]
|
|
76
|
-
|
|
77
|
-
pointSizes[pointIndex] = getRandom(1, 5)
|
|
78
|
-
|
|
79
|
-
const nextPointIndex = pointIndex + 1
|
|
80
|
-
const bottomPointIndex = pointIndex + n
|
|
81
|
-
const pointLine = Math.floor(pointIndex / n)
|
|
82
|
-
const nextPointLine = Math.floor(nextPointIndex / n)
|
|
83
|
-
const bottomPointLine = Math.floor(bottomPointIndex / n)
|
|
84
|
-
|
|
85
|
-
if (pointLine === nextPointLine && Math.random() < wholeness) {
|
|
86
|
-
links.push(pointIndex)
|
|
87
|
-
links.push(nextPointIndex)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (bottomPointLine < m && Math.random() < wholeness) {
|
|
91
|
-
links.push(pointIndex)
|
|
92
|
-
links.push(bottomPointIndex)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const linkColors = new Float32Array(links.length / 2 * 4)
|
|
97
|
-
const linkWidths = new Float32Array(links.length / 2)
|
|
98
|
-
// const linkStrength = new Float32Array(links.length / 2)
|
|
99
|
-
for (let i = 0; i < links.length / 2; i++) {
|
|
100
|
-
const sourcePointIndex = links[i * 2] as number
|
|
101
|
-
const rgba = getRgbaColor(pointColorScale(sourcePointIndex % nClusters))
|
|
102
|
-
linkColors[i * 4 + 0] = rgba[0]
|
|
103
|
-
linkColors[i * 4 + 1] = rgba[1]
|
|
104
|
-
linkColors[i * 4 + 2] = rgba[2]
|
|
105
|
-
linkColors[i * 4 + 3] = 0.9
|
|
106
|
-
|
|
107
|
-
linkWidths[i] = getRandom(0.4, 0.8)
|
|
108
|
-
// linkStrength[i] = (n * m - sourcePointIndex) / (n * m)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
pointPositions,
|
|
113
|
-
pointColors,
|
|
114
|
-
pointSizes,
|
|
115
|
-
|
|
116
|
-
links: new Float32Array(links),
|
|
117
|
-
linkColors,
|
|
118
|
-
linkWidths,
|
|
119
|
-
// linkStrength,
|
|
120
|
-
|
|
121
|
-
pointClusters,
|
|
122
|
-
clusterStrength,
|
|
123
|
-
clusterPositions,
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Graph } from '@cosmos.gl/graph'
|
|
2
|
-
import { moscowMetroCoords } from './moscow-metro-coords'
|
|
3
|
-
import { getPointColors } from './point-colors'
|
|
4
|
-
import './style.css'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This example demonstrates the importance of rescaling positions by Cosmos.
|
|
8
|
-
* The Moscow Metro station coordinates are are normalized (0-1 range in both dimensions).
|
|
9
|
-
* By default, cosmos.gl rescales these positions to fit the canvas.
|
|
10
|
-
* When disabling rescaling (`rescalePositions: false`):
|
|
11
|
-
* - Points render using raw coordinates
|
|
12
|
-
* - The entire graph occupies a tiny 1x1 area in WebGL's clip space (-1 to 1)
|
|
13
|
-
* - This causes visual artifacts due to WebGL's floating-point precision limitations
|
|
14
|
-
* - Points cluster in the center and may exhibit rendering glitches
|
|
15
|
-
*/
|
|
16
|
-
export const moscowMetroStations = (): {graph: Graph; div: HTMLDivElement} => {
|
|
17
|
-
const div = document.createElement('div')
|
|
18
|
-
div.className = 'app'
|
|
19
|
-
|
|
20
|
-
const graphDiv = document.createElement('div')
|
|
21
|
-
graphDiv.className = 'graph'
|
|
22
|
-
div.appendChild(graphDiv)
|
|
23
|
-
|
|
24
|
-
const actionsDiv = document.createElement('div')
|
|
25
|
-
actionsDiv.className = 'actions'
|
|
26
|
-
div.appendChild(actionsDiv)
|
|
27
|
-
|
|
28
|
-
let rescalePositions = true
|
|
29
|
-
|
|
30
|
-
const graph = new Graph(graphDiv, {
|
|
31
|
-
backgroundColor: '#2d313a',
|
|
32
|
-
scalePointsOnZoom: false,
|
|
33
|
-
rescalePositions,
|
|
34
|
-
pointDefaultColor: '#FEE08B',
|
|
35
|
-
enableSimulation: false,
|
|
36
|
-
enableDrag: false,
|
|
37
|
-
fitViewOnInit: true,
|
|
38
|
-
attribution: 'visualized with <a href="https://cosmograph.app/" style="color: var(--cosmosgl-attribution-color);" target="_blank">Cosmograph</a>',
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const pointColors = getPointColors(moscowMetroCoords)
|
|
42
|
-
|
|
43
|
-
graph.setPointPositions(new Float32Array(moscowMetroCoords))
|
|
44
|
-
graph.setPointColors(pointColors)
|
|
45
|
-
graph.render()
|
|
46
|
-
|
|
47
|
-
const disableEnableRescaleButton = document.createElement('div')
|
|
48
|
-
disableEnableRescaleButton.className = 'action'
|
|
49
|
-
disableEnableRescaleButton.textContent = 'Disable Rescale'
|
|
50
|
-
actionsDiv.appendChild(disableEnableRescaleButton)
|
|
51
|
-
|
|
52
|
-
disableEnableRescaleButton.addEventListener('click', () => {
|
|
53
|
-
rescalePositions = !rescalePositions
|
|
54
|
-
disableEnableRescaleButton.textContent = rescalePositions ? 'Disable Rescale' : 'Enable Rescale'
|
|
55
|
-
graph.setConfig({ rescalePositions })
|
|
56
|
-
graph.setPointPositions(new Float32Array(moscowMetroCoords))
|
|
57
|
-
graph.render()
|
|
58
|
-
graph.fitView()
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
return { div, graph }
|
|
62
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const moscowMetroCoords = [0.6048172222222222, 0.8100822222222221, 0.6048466666666666, 0.8100211111111111, 0.6047641666666667, 0.8099794444444445, 0.6046672222222222, 0.8099377777777779, 0.6046313888888889, 0.8098894444444444, 0.6046005555555556, 0.8098627777777778, 0.6045797222222222, 0.8098277777777778, 0.6045522222222223, 0.8098094444444445, 0.6045200000000001, 0.8097761111111111, 0.6044905555555555, 0.809765, 0.6044722222222223, 0.8097288888888888, 0.6044547222222222, 0.8096961111111111, 0.6044286111111111, 0.8096422222222223, 0.604385, 0.8095927777777777, 0.6043441666666667, 0.8095738888888888, 0.6043311111111112, 0.8095016666666666, 0.6042591666666667, 0.8094033333333334, 0.6041833333333333, 0.8093172222222222, 0.6041202777777778, 0.8092427777777778, 0.6040902777777778, 0.8091438888888888, 0.6040052777777778, 0.8090722222222223, 0.6039555555555556, 0.809015, 0.603910125, 0.8088964833333334, 0.6039827833333333, 0.8088124555555556, 0.6040537, 0.8087146833333334, 0.6040783888888889, 0.8086688666666666, 0.6041465694444444, 0.8086257777777778, 0.6041172222222222, 0.8104394444444444, 0.6041011111111112, 0.8103655555555556, 0.6041002777777777, 0.8103049999999999, 0.6041297222222222, 0.8102211111111111, 0.604161111111111, 0.8101055555555556, 0.6042091666666667, 0.8100283333333334, 0.6042580555555556, 0.8100016666666666, 0.6043277777777778, 0.8099427777777778, 0.6043986111111112, 0.8098705555555555, 0.6044327777777778, 0.809833888888889, 0.6044624999999999, 0.8098038888888889, 0.6044972222222222, 0.8097655555555556, 0.6045263888888889, 0.809675, 0.6045491666666667, 0.809613888888889, 0.6046044444444445, 0.8094855555555556, 0.6046225, 0.8094166666666667, 0.6046216666666667, 0.809325, 0.6045797222222222, 0.809195, 0.604601111111111, 0.8090877777777779, 0.6046372222222222, 0.8090077777777778, 0.6047080555555555, 0.8089622222222222, 0.6047738888888889, 0.8089488888888888, 0.6048455555555555, 0.8089649999999999, 0.6049055555555556, 0.80907, 0.6037622222222222, 0.8103127777777778, 0.6037838888888889, 0.8102538888888888, 0.6038394444444445, 0.8101966666666667, 0.6038477777777778, 0.81014, 0.6038975, 0.8100211111111111, 0.6039113888888888, 0.8097594444444444, 0.6039355555555556, 0.8096711111111111, 0.6040163888888889, 0.8096150000000001, 0.604085, 0.8096088888888889, 0.6042172222222223, 0.8096455555555555, 0.6043458333333334, 0.80969, 0.6043952777777778, 0.8097077777777778, 0.6044613888888889, 0.8097344444444445, 0.6045044444444444, 0.8097588888888888, 0.6046047222222223, 0.8097644444444444, 0.6046683333333334, 0.80985, 0.6047325, 0.8098983333333334, 0.60478, 0.8099072222222222, 0.6048627777777777, 0.8099366666666666, 0.6049483333333333, 0.8099322222222223, 0.6049980555555556, 0.8099711111111112, 0.6049961111111111, 0.8100522222222222, 0.6040163888888889, 0.8096150000000001, 0.6040752777777778, 0.8096444444444444, 0.6041202777777778, 0.8096644444444444, 0.6041602777777778, 0.8096877777777778, 0.6042083333333333, 0.8097000000000001, 0.6042622222222223, 0.8096661111111112, 0.6043008333333333, 0.8096599999999999, 0.6042608333333334, 0.8097127777777777, 0.6042799999999999, 0.8097233333333334, 0.604348611111111, 0.8096866666666668, 0.6043958333333334, 0.8097155555555556, 0.6044463888888889, 0.8097322222222222, 0.6044680555555555, 0.8097361111111111, 0.6043455555555556, 0.8096922222222221, 0.6043816666666667, 0.809785, 0.6044011111111112, 0.8098688888888889, 0.6044522222222223, 0.8098883333333333, 0.6045327777777778, 0.8098877777777778, 0.6045969444444445, 0.80986, 0.6046097222222222, 0.8097611111111112, 0.6045880555555556, 0.8096766666666667, 0.6045497222222223, 0.8096211111111111, 0.6045119444444444, 0.8096061111111112, 0.6044697222222223, 0.8096094444444445, 0.6044208333333333, 0.8096427777777778, 0.6046147222222221, 0.8104844444444445, 0.6046233333333333, 0.8103855555555555, 0.6045908333333334, 0.8103066666666666, 0.6045508333333334, 0.8102494444444445, 0.6045586111111111, 0.8101172222222223, 0.6045527777777778, 0.8100488888888888, 0.604545, 0.8099644444444445, 0.6045327777777778, 0.8098955555555556, 0.6045330555555556, 0.8098516666666667, 0.6045483333333334, 0.8098116666666666, 0.6045369444444444, 0.8097516666666666, 0.6045205555555555, 0.8096733333333332, 0.6044755555555555, 0.8096144444444445, 0.6044674999999999, 0.8095544444444444, 0.6044058333333333, 0.8094872222222221, 0.6043702777777779, 0.8093761111111112, 0.6043408333333333, 0.8093222222222222, 0.6043177777777777, 0.8092788888888889, 0.6042791666666667, 0.8092061111111112, 0.6042380555555555, 0.8091266666666667, 0.6042188888888889, 0.8090738888888889, 0.6041894444444444, 0.808995, 0.6042591666666667, 0.8089238888888889, 0.6043169444444445, 0.8088944444444445, 0.60399, 0.8103372222222223, 0.6039988888888889, 0.8102805555555557, 0.6039911111111111, 0.8101483333333335, 0.6039866666666667, 0.810101111111111, 0.6040669444444444, 0.8100477777777778, 0.6041486111111111, 0.8099638888888888, 0.60422, 0.809875, 0.6042966666666666, 0.8098544444444444, 0.6043369444444445, 0.8098055555555554, 0.6043875, 0.8097844444444444, 0.6044663888888889, 0.8098055555555554, 0.6045163888888889, 0.8097811111111112, 0.6045369444444444, 0.8097516666666666, 0.6045894444444444, 0.8096677777777779, 0.6046275, 0.8096216666666667, 0.6046858333333334, 0.809585, 0.6048100000000001, 0.8094933333333333, 0.6049044444444445, 0.8094755555555556, 0.6049813888888889, 0.8095388888888888, 0.6050502777777779, 0.8095311111111111, 0.6051458333333333, 0.8094516666666667, 0.6051563888888889, 0.8093638888888889, 0.6051616666666667, 0.8093016666666668, 0.6037075, 0.8090772222222221, 0.6037644444444444, 0.8091088888888889, 0.6038058333333334, 0.8091533333333334, 0.6038636111111111, 0.8091627777777777, 0.6039366666666667, 0.8092194444444445, 0.6040252777777777, 0.8092827777777779, 0.6041202777777778, 0.8093866666666666, 0.6041622222222223, 0.8094305555555555, 0.60421, 0.8094827777777778, 0.6041583333333334, 0.8095811111111112, 0.6042172222222223, 0.8096455555555555, 0.6042552777777778, 0.8097083333333334, 0.6045205555555555, 0.8096733333333332, 0.6045952777777778, 0.8096727777777779, 0.6046733333333333, 0.8097066666666666, 0.6047752777777777, 0.8097355555555555, 0.6048611111111111, 0.8097644444444444, 0.6049627777777777, 0.8097283333333334, 0.6050461111111111, 0.8097316666666666, 0.6051772222222223, 0.809695, 0.6044083333333333, 0.8105444444444444, 0.6044538888888888, 0.8104655555555556, 0.6044575, 0.8103516666666667, 0.6044163888888889, 0.8102627777777778, 0.6043736111111111, 0.8101950000000001, 0.6043791666666667, 0.8100977777777778, 0.6043936111111111, 0.8100383333333332, 0.6044125, 0.8099594444444445, 0.6044475, 0.8098944444444445, 0.6044963888888889, 0.8098377777777779, 0.6044713888888888, 0.8098022222222222, 0.6044644444444445, 0.8097283333333334, 0.6044944444444444, 0.809655, 0.6045127777777778, 0.8096000000000001, 0.6045080555555556, 0.8094927777777777, 0.6045066666666666, 0.80935, 0.6044733333333333, 0.8092911111111112, 0.6044597222222222, 0.8092372222222223, 0.60444, 0.80918, 0.6044630555555556, 0.8091138888888889, 0.6044694444444445, 0.8090133333333334, 0.6044566666666666, 0.8089577777777778, 0.6044455555555556, 0.8088605555555556, 0.604435, 0.8087933333333333, 0.6043802777777778, 0.8087183333333333, 0.604300925, 0.8103611111111112, 0.6043364194444444, 0.8103101833333333, 0.6043729166666667, 0.8102555555555556, 0.6043736111111111, 0.8101950000000001, 0.6044113888888889, 0.8101266666666667, 0.6044522222222223, 0.8100738888888889, 0.6044894444444444, 0.8099744444444444, 0.6044863888888888, 0.8098977777777777, 0.6045, 0.8098266666666667, 0.6045533333333334, 0.8098155555555555, 0.604603611111111, 0.8097583333333335, 0.6046719444444444, 0.8097016666666667, 0.6046313888888889, 0.8096283333333334, 0.6046555555555555, 0.8095477777777779, 0.6046808333333333, 0.8094855555555556, 0.6047972222222222, 0.8094077777777777, 0.6048694444444445, 0.8093938888888889, 0.6048938888888888, 0.8093100000000001, 0.6048625, 0.8092205555555555, 0.6048419444444444, 0.8091666666666667, 0.6048433333333334, 0.8090744444444444, 0.6048436111111111, 0.8090061111111112, 0.6048480555555555, 0.8089577777777778, 0.6046638888888889, 0.8099461111111111, 0.6047305916666667, 0.8098905111111111, 0.6047409638888889, 0.8098040999999999, 0.6047754138888889, 0.8097426111111111, 0.6048057666666666, 0.8096208222222223, 0.6048011111111111, 0.8094833333333333, 0.6047972222222222, 0.8094111111111112, 0.604736111111111, 0.8093583333333334, 0.6046794444444444, 0.8093083333333333, 0.6045797222222222, 0.809195, 0.6044983333333332, 0.809185, 0.6044397222222222, 0.8091833333333333, 0.6043669444444445, 0.8092016666666666, 0.6042775, 0.809215, 0.6042272222222221, 0.8092783333333333, 0.6041805555555555, 0.809321111111111, 0.6041252777777777, 0.80938, 0.6040672222222222, 0.809428888888889, 0.6040325000000001, 0.8095294444444445, 0.6040158333333333, 0.8096133333333333, 0.6040572222222222, 0.8097177777777778, 0.6040855555555555, 0.8097694444444444, 0.6041233333333333, 0.8098544444444444, 0.6042552777777778, 0.8097083333333334, 0.6042388888888889, 0.8097594444444444, 0.6042241666666667, 0.8098711111111112, 0.6042591666666667, 0.8099255555555556, 0.6043252777777778, 0.8099544444444444, 0.6044111111111111, 0.8099644444444445, 0.6043227777777778, 0.8088911111111111, 0.6043802777777778, 0.8087894444444444, 0.6043797222222222, 0.8087166666666668, 0.6043183333333333, 0.8086005555555555, 0.6042861111111111, 0.8085861111111111, 0.6042522222222222, 0.8085655555555555, 0.6042105555555556, 0.8085444444444445, 0.6043858333333334, 0.8101055555555556, 0.6044197222222222, 0.8101211111111111, 0.6044691666666667, 0.8101211111111111, 0.6045191666666667, 0.8101211111111111, 0.6045508333333334, 0.8101333333333334, 0.6045691666666667, 0.8101622222222223, 0.6043594444444444, 0.8102622222222221, 0.6044250000000001, 0.8102644444444445, 0.6045591666666666, 0.8102555555555556, 0.6046258333333333, 0.8102222222222223, 0.604723888888889, 0.8101666666666666, 0.6048247222222222, 0.8100955555555557, 0.60485, 0.8100216666666666, 0.604841111111111, 0.8099366666666666, 0.6048475, 0.8098411111111111, 0.6048508333333333, 0.8097722222222223, 0.6048177777777778, 0.8096727777777779, 0.6048005555555556, 0.8096233333333334, 0.6047669444444443, 0.8095772222222223, 0.6047161111111111, 0.8095461111111111, 0.6047161111111111, 0.8095461111111111, 0.6046197222222222, 0.8094794444444444, 0.6045786111111111, 0.8094350000000001, 0.6044969444444445, 0.8093888888888888, 0.6044583333333333, 0.8093888888888888, 0.604405, 0.8094827777777778, 0.6043419444444444, 0.8095572222222223, 0.6042591666666667, 0.8096711111111111, 0.6042561111111111, 0.8097066666666666, 0.6042377777777778, 0.8097638888888888, 0.6041866666666666, 0.8098733333333333, 0.6041791666666667, 0.8099322222222223, 0.6041633333333334, 0.809995, 0.6041302777777777, 0.8100755555555555, 0.6041558333333333, 0.8101433333333334, 0.6042230555555556, 0.8102205555555555, 0.6043091666666667, 0.8102622222222221, 0.6048057666666666, 0.8096208222222223, 0.6048941666666666, 0.8095833333333333, 0.6049491666666666, 0.8095477777777779, 0.6050528055555555, 0.8094720555555556, 0.6051419444444445, 0.8094627777777779, 0.60522, 0.8095, 0.6052788888888888, 0.8094916666666667, 0.6053511111111111, 0.8094644444444444]
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Graph, PointShape } from '@cosmos.gl/graph'
|
|
2
|
-
|
|
3
|
-
export const allShapes = (): {div: HTMLDivElement; graph: Graph } => {
|
|
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
|
-
return { div, graph }
|
|
69
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,238 +0,0 @@
|
|
|
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 = async (): Promise<{div: HTMLDivElement; graph: Graph }> => {
|
|
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
|
-
const imageDataArray = await loadPngImages([swiftUrl, boxUrl, toolboxUrl, legoUrl, sUrl])
|
|
208
|
-
|
|
209
|
-
// Set images and their indices
|
|
210
|
-
graph.setImageData(imageDataArray)
|
|
211
|
-
graph.setPointImageIndices(imageIndices)
|
|
212
|
-
|
|
213
|
-
// Set all data
|
|
214
|
-
graph.setPointPositions(pointPositions)
|
|
215
|
-
graph.setPointColors(pointColors)
|
|
216
|
-
graph.setPointShapes(pointShapes)
|
|
217
|
-
graph.setPointSizes(pointSizes)
|
|
218
|
-
|
|
219
|
-
// Set links if we have any dependencies
|
|
220
|
-
if (links.length > 0) {
|
|
221
|
-
graph.setLinks(new Float32Array(links))
|
|
222
|
-
graph.setLinkArrows(linkArrows)
|
|
223
|
-
graph.setLinkColors(new Float32Array(linkColors))
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
graph.render()
|
|
227
|
-
|
|
228
|
-
return { div, graph }
|
|
229
|
-
} catch (error) {
|
|
230
|
-
console.error('Error creating Xcode dependency graph:', error)
|
|
231
|
-
div.innerHTML = `
|
|
232
|
-
<div style="display: flex; align-items: center; justify-content: center; height: 100%; color: #ff0000; font-size: 18px;">
|
|
233
|
-
Error loading Xcode dependency graph: ${error instanceof Error ? error.message : 'Unknown error'}
|
|
234
|
-
</div>
|
|
235
|
-
`
|
|
236
|
-
throw error
|
|
237
|
-
}
|
|
238
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|