@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.
Files changed (169) hide show
  1. package/dist/config.d.ts +3 -0
  2. package/dist/index.d.ts +48 -6
  3. package/dist/index.js +1346 -1289
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +15 -15
  6. package/dist/index.min.js.map +1 -1
  7. package/package.json +5 -1
  8. package/.eslintrc +0 -147
  9. package/.github/SECURITY.md +0 -19
  10. package/.github/dco.yml +0 -4
  11. package/.github/workflows/github_pages.yml +0 -54
  12. package/.storybook/main.ts +0 -26
  13. package/.storybook/manager-head.html +0 -1
  14. package/.storybook/manager.ts +0 -14
  15. package/.storybook/preview.ts +0 -29
  16. package/.storybook/style.css +0 -3
  17. package/CHARTER.md +0 -69
  18. package/CODE_OF_CONDUCT.md +0 -178
  19. package/CONTRIBUTING.md +0 -22
  20. package/GOVERNANCE.md +0 -21
  21. package/cosmos-2-0-migration-notes.md +0 -98
  22. package/cosmos_awesome.md +0 -96
  23. package/dist/stories/beginners/basic-set-up/data-gen.d.ts +0 -4
  24. package/dist/stories/beginners/basic-set-up/index.d.ts +0 -5
  25. package/dist/stories/beginners/link-hovering/data-generator.d.ts +0 -19
  26. package/dist/stories/beginners/link-hovering/index.d.ts +0 -5
  27. package/dist/stories/beginners/pinned-points/data-gen.d.ts +0 -5
  28. package/dist/stories/beginners/pinned-points/index.d.ts +0 -5
  29. package/dist/stories/beginners/point-labels/data.d.ts +0 -13
  30. package/dist/stories/beginners/point-labels/index.d.ts +0 -9
  31. package/dist/stories/beginners/point-labels/labels.d.ts +0 -8
  32. package/dist/stories/beginners/quick-start.d.ts +0 -5
  33. package/dist/stories/beginners/remove-points/config.d.ts +0 -2
  34. package/dist/stories/beginners/remove-points/data-gen.d.ts +0 -4
  35. package/dist/stories/beginners/remove-points/index.d.ts +0 -5
  36. package/dist/stories/beginners.stories.d.ts +0 -11
  37. package/dist/stories/clusters/polygon-selection/index.d.ts +0 -6
  38. package/dist/stories/clusters/polygon-selection/polygon.d.ts +0 -20
  39. package/dist/stories/clusters/radial.d.ts +0 -5
  40. package/dist/stories/clusters/with-labels.d.ts +0 -6
  41. package/dist/stories/clusters/worm.d.ts +0 -5
  42. package/dist/stories/clusters.stories.d.ts +0 -9
  43. package/dist/stories/create-cluster-labels.d.ts +0 -4
  44. package/dist/stories/create-cosmos.d.ts +0 -16
  45. package/dist/stories/create-story.d.ts +0 -16
  46. package/dist/stories/experiments/full-mesh.d.ts +0 -5
  47. package/dist/stories/experiments/mesh-with-holes.d.ts +0 -5
  48. package/dist/stories/experiments.stories.d.ts +0 -7
  49. package/dist/stories/generate-mesh-data.d.ts +0 -12
  50. package/dist/stories/geospatial/moscow-metro-stations/index.d.ts +0 -15
  51. package/dist/stories/geospatial/moscow-metro-stations/moscow-metro-coords.d.ts +0 -1
  52. package/dist/stories/geospatial/moscow-metro-stations/point-colors.d.ts +0 -1
  53. package/dist/stories/geospatial.stories.d.ts +0 -6
  54. package/dist/stories/shapes/all-shapes/index.d.ts +0 -5
  55. package/dist/stories/shapes/image-example/index.d.ts +0 -5
  56. package/dist/stories/shapes.stories.d.ts +0 -7
  57. package/logo.svg +0 -3
  58. package/rollup.config.js +0 -70
  59. package/src/config.ts +0 -734
  60. package/src/declaration.d.ts +0 -12
  61. package/src/graph/utils/error-message.ts +0 -23
  62. package/src/helper.ts +0 -74
  63. package/src/index.ts +0 -1635
  64. package/src/modules/Clusters/calculate-centermass.frag +0 -9
  65. package/src/modules/Clusters/calculate-centermass.vert +0 -26
  66. package/src/modules/Clusters/force-cluster.frag +0 -39
  67. package/src/modules/Clusters/index.ts +0 -200
  68. package/src/modules/Drag/index.ts +0 -33
  69. package/src/modules/FPSMonitor/css.ts +0 -53
  70. package/src/modules/FPSMonitor/index.ts +0 -28
  71. package/src/modules/ForceCenter/calculate-centermass.frag +0 -9
  72. package/src/modules/ForceCenter/calculate-centermass.vert +0 -18
  73. package/src/modules/ForceCenter/force-center.frag +0 -27
  74. package/src/modules/ForceCenter/index.ts +0 -104
  75. package/src/modules/ForceGravity/force-gravity.frag +0 -27
  76. package/src/modules/ForceGravity/index.ts +0 -33
  77. package/src/modules/ForceLink/force-spring.ts +0 -73
  78. package/src/modules/ForceLink/index.ts +0 -149
  79. package/src/modules/ForceManyBody/calculate-level.frag +0 -9
  80. package/src/modules/ForceManyBody/calculate-level.vert +0 -25
  81. package/src/modules/ForceManyBody/force-centermass.frag +0 -52
  82. package/src/modules/ForceManyBody/force-level.frag +0 -121
  83. package/src/modules/ForceManyBody/index.ts +0 -223
  84. package/src/modules/ForceManyBody/quadtree-frag-shader.ts +0 -90
  85. package/src/modules/ForceManyBodyQuadtree/calculate-level.frag +0 -9
  86. package/src/modules/ForceManyBodyQuadtree/calculate-level.vert +0 -25
  87. package/src/modules/ForceManyBodyQuadtree/index.ts +0 -157
  88. package/src/modules/ForceManyBodyQuadtree/quadtree-frag-shader.ts +0 -93
  89. package/src/modules/ForceMouse/force-mouse.frag +0 -24
  90. package/src/modules/ForceMouse/index.ts +0 -32
  91. package/src/modules/GraphData/index.ts +0 -384
  92. package/src/modules/Lines/draw-curve-line.frag +0 -46
  93. package/src/modules/Lines/draw-curve-line.vert +0 -194
  94. package/src/modules/Lines/geometry.ts +0 -18
  95. package/src/modules/Lines/hovered-line-index.frag +0 -27
  96. package/src/modules/Lines/hovered-line-index.vert +0 -8
  97. package/src/modules/Lines/index.ts +0 -273
  98. package/src/modules/Points/atlas-utils.ts +0 -137
  99. package/src/modules/Points/drag-point.frag +0 -20
  100. package/src/modules/Points/draw-highlighted.frag +0 -16
  101. package/src/modules/Points/draw-highlighted.vert +0 -86
  102. package/src/modules/Points/draw-points.frag +0 -243
  103. package/src/modules/Points/draw-points.vert +0 -127
  104. package/src/modules/Points/fill-sampled-points.frag +0 -9
  105. package/src/modules/Points/fill-sampled-points.vert +0 -29
  106. package/src/modules/Points/find-hovered-point.frag +0 -9
  107. package/src/modules/Points/find-hovered-point.vert +0 -57
  108. package/src/modules/Points/find-points-on-area-selection.frag +0 -48
  109. package/src/modules/Points/find-points-on-polygon-selection.frag +0 -65
  110. package/src/modules/Points/index.ts +0 -968
  111. package/src/modules/Points/track-positions.frag +0 -18
  112. package/src/modules/Points/update-position.frag +0 -37
  113. package/src/modules/Shared/buffer.ts +0 -37
  114. package/src/modules/Shared/clear.frag +0 -7
  115. package/src/modules/Shared/quad.vert +0 -12
  116. package/src/modules/Store/index.ts +0 -173
  117. package/src/modules/Zoom/index.ts +0 -148
  118. package/src/modules/core-module.ts +0 -28
  119. package/src/stories/1. welcome.mdx +0 -81
  120. package/src/stories/2. configuration.mdx +0 -113
  121. package/src/stories/3. api-reference.mdx +0 -591
  122. package/src/stories/beginners/basic-set-up/data-gen.ts +0 -33
  123. package/src/stories/beginners/basic-set-up/index.ts +0 -163
  124. package/src/stories/beginners/basic-set-up/style.css +0 -35
  125. package/src/stories/beginners/link-hovering/data-generator.ts +0 -198
  126. package/src/stories/beginners/link-hovering/index.ts +0 -61
  127. package/src/stories/beginners/link-hovering/style.css +0 -73
  128. package/src/stories/beginners/pinned-points/data-gen.ts +0 -153
  129. package/src/stories/beginners/pinned-points/index.ts +0 -61
  130. package/src/stories/beginners/point-labels/data.ts +0 -73
  131. package/src/stories/beginners/point-labels/index.ts +0 -65
  132. package/src/stories/beginners/point-labels/labels.ts +0 -46
  133. package/src/stories/beginners/point-labels/style.css +0 -16
  134. package/src/stories/beginners/quick-start.ts +0 -50
  135. package/src/stories/beginners/remove-points/config.ts +0 -25
  136. package/src/stories/beginners/remove-points/data-gen.ts +0 -30
  137. package/src/stories/beginners/remove-points/index.ts +0 -92
  138. package/src/stories/beginners/remove-points/style.css +0 -31
  139. package/src/stories/beginners.stories.ts +0 -131
  140. package/src/stories/clusters/polygon-selection/index.ts +0 -51
  141. package/src/stories/clusters/polygon-selection/polygon.ts +0 -143
  142. package/src/stories/clusters/polygon-selection/style.css +0 -8
  143. package/src/stories/clusters/radial.ts +0 -24
  144. package/src/stories/clusters/with-labels.ts +0 -53
  145. package/src/stories/clusters/worm.ts +0 -40
  146. package/src/stories/clusters.stories.ts +0 -77
  147. package/src/stories/create-cluster-labels.ts +0 -50
  148. package/src/stories/create-cosmos.ts +0 -68
  149. package/src/stories/create-story.ts +0 -51
  150. package/src/stories/experiments/full-mesh.ts +0 -13
  151. package/src/stories/experiments/mesh-with-holes.ts +0 -13
  152. package/src/stories/experiments.stories.ts +0 -43
  153. package/src/stories/generate-mesh-data.ts +0 -125
  154. package/src/stories/geospatial/moscow-metro-stations/index.ts +0 -62
  155. package/src/stories/geospatial/moscow-metro-stations/moscow-metro-coords.ts +0 -1
  156. package/src/stories/geospatial/moscow-metro-stations/point-colors.ts +0 -46
  157. package/src/stories/geospatial/moscow-metro-stations/style.css +0 -30
  158. package/src/stories/geospatial.stories.ts +0 -30
  159. package/src/stories/shapes/all-shapes/index.ts +0 -69
  160. package/src/stories/shapes/image-example/icons/box.png +0 -0
  161. package/src/stories/shapes/image-example/icons/lego.png +0 -0
  162. package/src/stories/shapes/image-example/icons/s.png +0 -0
  163. package/src/stories/shapes/image-example/icons/swift.png +0 -0
  164. package/src/stories/shapes/image-example/icons/toolbox.png +0 -0
  165. package/src/stories/shapes/image-example/index.ts +0 -238
  166. package/src/stories/shapes.stories.ts +0 -37
  167. package/src/variables.ts +0 -68
  168. package/tsconfig.json +0 -41
  169. package/vite.config.ts +0 -54
@@ -1,163 +0,0 @@
1
- import { Graph } from '@cosmos.gl/graph'
2
- import { generateData } from './data-gen'
3
- import './style.css'
4
-
5
- export const basicSetUp = (): { graph: Graph; div: HTMLDivElement} => {
6
- const div = document.createElement('div')
7
- div.className = 'app'
8
-
9
- const graphDiv = document.createElement('div')
10
- graphDiv.className = 'graph'
11
- div.appendChild(graphDiv)
12
-
13
- const actionsDiv = document.createElement('div')
14
- actionsDiv.className = 'actions'
15
- div.appendChild(actionsDiv)
16
-
17
- const actionsHeader = document.createElement('div')
18
- actionsHeader.className = 'actions-header'
19
- actionsHeader.textContent = 'Actions'
20
- actionsDiv.appendChild(actionsHeader)
21
-
22
- const graph = new Graph(graphDiv, {
23
- spaceSize: 4096,
24
- backgroundColor: '#2d313a',
25
- pointSize: 4,
26
- pointDefaultColor: '#4B5BBF',
27
- linkWidth: 0.6,
28
- scalePointsOnZoom: true,
29
- linkColor: '#5F74C2',
30
- linkArrows: false,
31
- linkGreyoutOpacity: 0,
32
- curvedLinks: true,
33
- renderHoveredPointRing: true,
34
- hoveredPointRingColor: '#4B5BBF',
35
- enableDrag: true,
36
- simulationLinkDistance: 1,
37
- simulationLinkSpring: 2,
38
- simulationRepulsion: 0.2,
39
- simulationGravity: 0.1,
40
- simulationDecay: 100000,
41
- onPointClick: (index: number): void => {
42
- graph.selectPointByIndex(index)
43
- graph.zoomToPointByIndex(index)
44
- console.log('Clicked point index: ', index)
45
- },
46
- onBackgroundClick: (): void => {
47
- graph.unselectPoints()
48
- console.log('Clicked background')
49
- },
50
- attribution: 'visualized with <a href="https://cosmograph.app/" style="color: var(--cosmosgl-attribution-color);" target="_blank">Cosmograph</a>',
51
- })
52
-
53
- const { pointPositions, links } = generateData()
54
- graph.setPointPositions(pointPositions)
55
- graph.setLinks(links)
56
-
57
- graph.zoom(0.9)
58
- graph.render()
59
-
60
- /* ~ Demo Actions ~ */
61
- // Start / Pause
62
- let isPaused = false
63
- const pauseButton = document.createElement('div')
64
- pauseButton.className = 'action'
65
- pauseButton.textContent = 'Pause'
66
- actionsDiv.appendChild(pauseButton)
67
-
68
- function pause (): void {
69
- isPaused = true
70
- pauseButton.textContent = 'Start'
71
- graph.pause()
72
- }
73
-
74
- function unpause (): void {
75
- isPaused = false
76
- pauseButton.textContent = 'Pause'
77
- // if the graph is at 100% progress, start the graph
78
- if (graph.progress === 1) {
79
- graph.start()
80
- } else {
81
- graph.unpause()
82
- }
83
- }
84
-
85
- function togglePause (): void {
86
- if (isPaused) unpause()
87
- else pause()
88
- }
89
-
90
- pauseButton.addEventListener('click', togglePause)
91
- graph.setConfig({
92
- onSimulationEnd: (): void => {
93
- pause()
94
- },
95
- })
96
-
97
- // Zoom and Select
98
- function getRandomPointIndex (): number {
99
- return Math.floor((Math.random() * pointPositions.length) / 2)
100
- }
101
-
102
- function getRandomInRange ([min, max]: [number, number]): number {
103
- return Math.random() * (max - min) + min
104
- }
105
-
106
- function fitView (): void {
107
- graph.fitView()
108
- }
109
-
110
- function zoomIn (): void {
111
- const pointIndex = getRandomPointIndex()
112
- graph.zoomToPointByIndex(pointIndex)
113
- graph.selectPointByIndex(pointIndex)
114
- pause()
115
- }
116
-
117
- function selectPoint (): void {
118
- const pointIndex = getRandomPointIndex()
119
- graph.selectPointByIndex(pointIndex)
120
- graph.fitView()
121
- pause()
122
- }
123
-
124
- function selectPointsInArea (): void {
125
- const w = div.clientWidth
126
- const h = div.clientHeight
127
- const left = getRandomInRange([w / 4, w / 2])
128
- const right = getRandomInRange([left, (w * 3) / 4])
129
- const top = getRandomInRange([h / 4, h / 2])
130
- const bottom = getRandomInRange([top, (h * 3) / 4])
131
- pause()
132
- graph.selectPointsInRect([
133
- [left, top],
134
- [right, bottom],
135
- ])
136
- }
137
-
138
- const fitViewButton = document.createElement('div')
139
- fitViewButton.className = 'action'
140
- fitViewButton.textContent = 'Fit View'
141
- fitViewButton.addEventListener('click', fitView)
142
- actionsDiv.appendChild(fitViewButton)
143
-
144
- const zoomButton = document.createElement('div')
145
- zoomButton.className = 'action'
146
- zoomButton.textContent = 'Zoom to a point'
147
- zoomButton.addEventListener('click', zoomIn)
148
- actionsDiv.appendChild(zoomButton)
149
-
150
- const selectPointButton = document.createElement('div')
151
- selectPointButton.className = 'action'
152
- selectPointButton.textContent = 'Select a point'
153
- selectPointButton.addEventListener('click', selectPoint)
154
- actionsDiv.appendChild(selectPointButton)
155
-
156
- const selectPointsInAreaButton = document.createElement('div')
157
- selectPointsInAreaButton.className = 'action'
158
- selectPointsInAreaButton.textContent = 'Select points in a rectangular area'
159
- selectPointsInAreaButton.addEventListener('click', selectPointsInArea)
160
- actionsDiv.appendChild(selectPointsInAreaButton)
161
-
162
- return { div, graph }
163
- }
@@ -1,35 +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
- .actions-header {
25
- font-weight: bold;
26
- margin-bottom: 2px;
27
- }
28
-
29
- .action {
30
- margin-left: 2px;
31
- font-size: 10pt;
32
- text-decoration: underline;
33
- cursor: pointer;
34
- user-select: none;
35
- }
@@ -1,198 +0,0 @@
1
- interface Point {
2
- id: number;
3
- }
4
-
5
- interface Link {
6
- source: number;
7
- target: number;
8
- }
9
-
10
- interface NetworkData {
11
- pointPositions: Float32Array;
12
- pointColors: Float32Array;
13
- pointSizes: Float32Array;
14
- links: Float32Array;
15
- linkColors: Float32Array;
16
- linkWidths: Float32Array;
17
- points: Point[];
18
- connections: Link[];
19
- }
20
-
21
- function hslToRgb (hue: number, saturation: number, lightness: number): [number, number, number] {
22
- const c = (1 - Math.abs(2 * lightness - 1)) * saturation
23
- const x = c * (1 - Math.abs(((hue / 60) % 2) - 1))
24
- const m = lightness - c / 2
25
-
26
- let r, g, b
27
- if (hue >= 0 && hue < 60) {
28
- r = c; g = x; b = 0
29
- } else if (hue >= 60 && hue < 120) {
30
- r = x; g = c; b = 0
31
- } else if (hue >= 120 && hue < 180) {
32
- r = 0; g = c; b = x
33
- } else if (hue >= 180 && hue < 240) {
34
- r = 0; g = x; b = c
35
- } else if (hue >= 240 && hue < 300) {
36
- r = x; g = 0; b = c
37
- } else {
38
- r = c; g = 0; b = x
39
- }
40
-
41
- return [r + m, g + m, b + m]
42
- }
43
-
44
- function generatePoints (count: number): Point[] {
45
- const points: Point[] = []
46
- for (let i = 0; i < count; i++) {
47
- points.push({ id: i })
48
- }
49
- return points
50
- }
51
-
52
- function generateConnections (points: Point[]): Link[] {
53
- const connections: Link[] = []
54
- const pointCount = points.length
55
-
56
- // Sequential connections
57
- for (let i = 0; i < pointCount; i++) {
58
- const nextId1 = (i + 1) % pointCount
59
- const nextId2 = (i + 2) % pointCount
60
- connections.push({ source: i, target: nextId1 })
61
- if (i % 2 === 0) {
62
- connections.push({ source: i, target: nextId2 })
63
- }
64
- }
65
-
66
- // Hub connections
67
- const hubPoints = [0, 10, 20, 30, 40, 50, 60, 70]
68
- hubPoints.forEach(hub => {
69
- for (let i = 1; i <= 5; i++) {
70
- const targetId = (hub + i * 3) % pointCount
71
- if (targetId !== hub) {
72
- connections.push({ source: hub, target: targetId })
73
- }
74
- }
75
- })
76
-
77
- // Cross connections
78
- for (let i = 0; i < pointCount / 2; i++) {
79
- const oppositeId = i + Math.floor(pointCount / 2)
80
- if (i % 3 === 0) {
81
- connections.push({ source: i, target: oppositeId })
82
- }
83
- }
84
-
85
- // Random connections
86
- for (let i = 0; i < 30; i++) {
87
- const source = Math.floor(Math.random() * pointCount)
88
- const target = Math.floor(Math.random() * pointCount)
89
- if (source !== target) {
90
- const exists = connections.some(conn =>
91
- (conn.source === source && conn.target === target) ||
92
- (conn.source === target && conn.target === source)
93
- )
94
- if (!exists) {
95
- connections.push({ source, target })
96
- }
97
- }
98
- }
99
-
100
- return connections
101
- }
102
-
103
- function generatePointPositions (points: Point[]): Float32Array {
104
- const radius = 100
105
- const positions = new Float32Array(points.length * 2)
106
-
107
- points.forEach((point, i) => {
108
- const angle = (i / points.length) * Math.PI * 2
109
- const pointRadius = radius + (Math.random() - 0.5) * 20
110
-
111
- positions[i * 2] = Math.cos(angle) * pointRadius
112
- positions[i * 2 + 1] = Math.sin(angle) * pointRadius
113
- })
114
-
115
- return positions
116
- }
117
-
118
- function generatePointColors (points: Point[]): Float32Array {
119
- const colors = new Float32Array(points.length * 4)
120
-
121
- points.forEach((point, i) => {
122
- const hue = (point.id / points.length) * 360
123
- const [r, g, b] = hslToRgb(hue, 0.8, 0.6)
124
-
125
- colors[i * 4] = r
126
- colors[i * 4 + 1] = g
127
- colors[i * 4 + 2] = b
128
- colors[i * 4 + 3] = 1.0
129
- })
130
-
131
- return colors
132
- }
133
-
134
- function generatePointSizes (points: Point[]): Float32Array {
135
- const sizes = new Float32Array(points.length)
136
- sizes.fill(10)
137
- return sizes
138
- }
139
-
140
- function generateLinkData (connections: Link[], points: Point[]): {
141
- links: Float32Array;
142
- linkColors: Float32Array;
143
- linkWidths: Float32Array;
144
- } {
145
- const links = new Float32Array(connections.length * 2)
146
- const linkColors = new Float32Array(connections.length * 4)
147
- const linkWidths = new Float32Array(connections.length)
148
-
149
- connections.forEach((connection, i) => {
150
- links[i * 2] = connection.source
151
- links[i * 2 + 1] = connection.target
152
-
153
- // Color links based on average hue of connected points
154
- const sourceHue = (connection.source / points.length) * 360
155
- const targetHue = (connection.target / points.length) * 360
156
-
157
- let avgHue
158
- const hueDiff = Math.abs(targetHue - sourceHue)
159
- if (hueDiff > 180) {
160
- avgHue = ((sourceHue + targetHue + 360) / 2) % 360
161
- } else {
162
- avgHue = (sourceHue + targetHue) / 2
163
- }
164
-
165
- const [r, g, b] = hslToRgb(avgHue, 0.7, 0.5)
166
-
167
- linkColors[i * 4] = r
168
- linkColors[i * 4 + 1] = g
169
- linkColors[i * 4 + 2] = b
170
- linkColors[i * 4 + 3] = 0.9
171
-
172
- linkWidths[i] = 2
173
- })
174
-
175
- return { links, linkColors, linkWidths }
176
- }
177
-
178
- export function generateData (pointCount: number = 500): NetworkData {
179
- const points = generatePoints(pointCount)
180
- const connections = generateConnections(points)
181
-
182
- const pointPositions = generatePointPositions(points)
183
- const pointColors = generatePointColors(points)
184
- const pointSizes = generatePointSizes(points)
185
-
186
- const { links, linkColors, linkWidths } = generateLinkData(connections, points)
187
-
188
- return {
189
- pointPositions,
190
- pointColors,
191
- pointSizes,
192
- links,
193
- linkColors,
194
- linkWidths,
195
- points,
196
- connections,
197
- }
198
- }
@@ -1,61 +0,0 @@
1
- import { Graph, GraphConfigInterface } from '@cosmos.gl/graph'
2
- import { generateData } from './data-generator'
3
- import './style.css'
4
-
5
- export const linkHovering = (): { div: HTMLDivElement; graph: Graph } => {
6
- const data = generateData()
7
- const infoPanel = document.createElement('div')
8
-
9
- // Create div container
10
- const div = document.createElement('div')
11
- div.style.height = '100vh'
12
- div.style.width = '100%'
13
- div.style.position = 'relative'
14
-
15
- // Configure graph
16
- const config: GraphConfigInterface = {
17
- backgroundColor: '#2d313a',
18
- scalePointsOnZoom: true,
19
- linkArrows: false,
20
- curvedLinks: true,
21
- enableSimulation: false,
22
- hoveredLinkWidthIncrease: 4,
23
- attribution: 'visualized with <a href="https://cosmograph.app/" style="color: var(--cosmosgl-attribution-color);" target="_blank">Cosmograph</a>',
24
-
25
- onLinkMouseOver: (linkIndex: number) => {
26
- infoPanel.style.display = 'block'
27
- infoPanel.textContent = `Link ${linkIndex}`
28
- },
29
-
30
- onLinkMouseOut: () => {
31
- infoPanel.style.display = 'none'
32
- },
33
- }
34
-
35
- // Create graph instance
36
- const graph = new Graph(div, config)
37
-
38
- // Set data
39
- graph.setPointPositions(data.pointPositions)
40
- graph.setPointColors(data.pointColors)
41
- graph.setPointSizes(data.pointSizes)
42
- graph.setLinks(data.links)
43
- graph.setLinkColors(data.linkColors)
44
- graph.setLinkWidths(data.linkWidths)
45
-
46
- // Render graph
47
- graph.zoom(0.9)
48
- graph.render()
49
-
50
- infoPanel.style.cssText = `
51
- position: absolute;
52
- top: 20px;
53
- left: 20px;
54
- color: white;
55
- font-size: 14px;
56
- display: none;
57
- `
58
- div.appendChild(infoPanel)
59
-
60
- return { div, graph }
61
- }
@@ -1,73 +0,0 @@
1
- /* Enhanced styling for the link hovering demo */
2
-
3
- .company-network {
4
- background: radial-gradient(circle at 50% 50%, #1a1a2e 0%, #0a0a0a 100%);
5
- position: relative;
6
- overflow: hidden;
7
- }
8
-
9
- .info-panel {
10
- backdrop-filter: blur(12px);
11
- transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
12
- }
13
-
14
- .info-panel:hover {
15
- transform: translateY(-2px);
16
- box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6), 0 8px 24px rgba(0, 0, 0, 0.4);
17
- }
18
-
19
- .relationship-type-indicator {
20
- display: inline-block;
21
- width: 12px;
22
- height: 12px;
23
- border-radius: 50%;
24
- margin-right: 8px;
25
- }
26
-
27
- .relationship-type-indicator.management {
28
- background: linear-gradient(45deg, #FFAD6B, #FF8A65);
29
- box-shadow: 0 2px 8px rgba(255, 173, 107, 0.4);
30
- }
31
-
32
- .relationship-type-indicator.collaboration {
33
- background: linear-gradient(45deg, #59C0FF, #42A5F5);
34
- box-shadow: 0 2px 8px rgba(89, 192, 255, 0.4);
35
- }
36
-
37
- .relationship-type-indicator.mentorship {
38
- background: linear-gradient(45deg, #6BD17B, #66BB6A);
39
- box-shadow: 0 2px 8px rgba(107, 209, 123, 0.4);
40
- }
41
-
42
- .relationship-type-indicator.friendship {
43
- background: linear-gradient(45deg, #FF61AD, #EC407A);
44
- box-shadow: 0 2px 8px rgba(255, 97, 173, 0.4);
45
- }
46
-
47
- .person-card {
48
- background: rgba(255, 255, 255, 0.03);
49
- border-radius: 8px;
50
- padding: 12px;
51
- margin: 6px 0;
52
- border-left: 3px solid transparent;
53
- border: 1px solid rgba(255, 255, 255, 0.06);
54
- transition: all 0.2s ease;
55
- }
56
-
57
- .person-card.highlighted {
58
- border-left-color: #59C0FF;
59
- background: rgba(89, 192, 255, 0.08);
60
- box-shadow: 0 4px 16px rgba(89, 192, 255, 0.15);
61
- }
62
-
63
- /* Modern color scheme variables */
64
- :root {
65
- --cosmos-orange: #FFAD6B;
66
- --cosmos-blue: #59C0FF;
67
- --cosmos-green: #6BD17B;
68
- --cosmos-pink: #FF61AD;
69
- --cosmos-gray: #C7CDD1;
70
- --cosmos-dark-bg: rgba(16, 20, 40, 0.95);
71
- --cosmos-card-bg: rgba(255, 255, 255, 0.03);
72
- --cosmos-border: rgba(255, 255, 255, 0.08);
73
- }
@@ -1,153 +0,0 @@
1
- // Note: This is vibe coding only - quick prototype code for demonstration purposes
2
-
3
- function getRandom (min: number, max: number): number {
4
- return Math.random() * (max - min) + min
5
- }
6
-
7
- function hslToRgb (hue: number, saturation: number, lightness: number): [number, number, number] {
8
- const c = (1 - Math.abs(2 * lightness - 1)) * saturation
9
- const x = c * (1 - Math.abs(((hue / 60) % 2) - 1))
10
- const m = lightness - c / 2
11
-
12
- let r, g, b
13
- if (hue >= 0 && hue < 60) {
14
- r = c; g = x; b = 0
15
- } else if (hue >= 60 && hue < 120) {
16
- r = x; g = c; b = 0
17
- } else if (hue >= 120 && hue < 180) {
18
- r = 0; g = c; b = x
19
- } else if (hue >= 180 && hue < 240) {
20
- r = 0; g = x; b = c
21
- } else if (hue >= 240 && hue < 300) {
22
- r = x; g = 0; b = c
23
- } else {
24
- r = c; g = 0; b = x
25
- }
26
-
27
- return [r + m, g + m, b + m]
28
- }
29
-
30
- export function generateData (numNodes = 60): { pointPositions: Float32Array; links: Float32Array; pointColors: Float32Array } {
31
- const pointPositions = new Float32Array(numNodes * 2)
32
- const pointColors = new Float32Array(numNodes * 4)
33
- const linksArray: number[] = []
34
-
35
- const centerX = 2048
36
- const centerY = 2048
37
- const circleRadius = 900
38
-
39
- // First, place 6 nodes in a perfect circle with equal spacing
40
- const numCircleNodes = 6
41
- for (let i = 0; i < numCircleNodes; i++) {
42
- const angle = (i / numCircleNodes) * Math.PI * 2
43
- const x = centerX + Math.cos(angle) * circleRadius
44
- const y = centerY + Math.sin(angle) * circleRadius
45
-
46
- pointPositions[i * 2] = x
47
- pointPositions[i * 2 + 1] = y
48
-
49
- // Color based on position - rainbow gradient
50
- const hue = (i / numNodes) * 360
51
- const [r, g, b] = hslToRgb(hue, 0.7, 0.6)
52
-
53
- pointColors[i * 4] = r
54
- pointColors[i * 4 + 1] = g
55
- pointColors[i * 4 + 2] = b
56
- pointColors[i * 4 + 3] = 1.0
57
- }
58
-
59
- // Create remaining nodes in clusters around the space
60
- const numClusters = 4
61
- const remainingNodes = numNodes - numCircleNodes
62
- const nodesPerCluster = Math.floor(remainingNodes / numClusters)
63
-
64
- for (let cluster = 0; cluster < numClusters; cluster++) {
65
- const clusterAngle = (cluster / numClusters) * Math.PI * 2
66
- const clusterRadius = 1200
67
- const clusterX = centerX + Math.cos(clusterAngle) * clusterRadius
68
- const clusterY = centerY + Math.sin(clusterAngle) * clusterRadius
69
-
70
- const startIndex = numCircleNodes + cluster * nodesPerCluster
71
- const endIndex = cluster === numClusters - 1 ? numNodes : startIndex + nodesPerCluster
72
-
73
- for (let i = startIndex; i < endIndex; i++) {
74
- // Position nodes in a small cluster
75
- const angle = (i - startIndex) / (endIndex - startIndex) * Math.PI * 2
76
- const radius = 300 + getRandom(-50, 50)
77
- const x = clusterX + Math.cos(angle) * radius * getRandom(0.7, 1.3)
78
- const y = clusterY + Math.sin(angle) * radius * getRandom(0.7, 1.3)
79
-
80
- pointPositions[i * 2] = x
81
- pointPositions[i * 2 + 1] = y
82
-
83
- // Color based on position - rainbow gradient
84
- const hue = (i / numNodes) * 360
85
- const [r, g, b] = hslToRgb(hue, 0.7, 0.6)
86
-
87
- pointColors[i * 4] = r
88
- pointColors[i * 4 + 1] = g
89
- pointColors[i * 4 + 2] = b
90
- pointColors[i * 4 + 3] = 1.0
91
- }
92
- }
93
-
94
- // Create links: connect the 6 circle nodes to form a ring
95
- for (let i = 0; i < numCircleNodes; i++) {
96
- const nextIndex = (i + 1) % numCircleNodes
97
- linksArray.push(i)
98
- linksArray.push(nextIndex)
99
- }
100
-
101
- // Connect circle nodes to nearby cluster nodes - more connections
102
- for (let i = 0; i < numCircleNodes; i++) {
103
- const circleAngle = (i / numCircleNodes) * Math.PI * 2
104
- // Find nearest cluster and connect to many nodes in it
105
- const nearestCluster = Math.floor((circleAngle / (Math.PI * 2)) * numClusters) % numClusters
106
- const clusterStart = numCircleNodes + nearestCluster * nodesPerCluster
107
- const clusterEnd = nearestCluster === numClusters - 1 ? numNodes : clusterStart + nodesPerCluster
108
- // Connect to many nodes in the nearest cluster
109
- for (let j = clusterStart; j < Math.min(clusterStart + Math.floor(nodesPerCluster * 0.6), clusterEnd); j++) {
110
- linksArray.push(i)
111
- linksArray.push(j)
112
- }
113
- // Also connect to some nodes in adjacent clusters
114
- const nextCluster = (nearestCluster + 1) % numClusters
115
- const nextClusterStart = numCircleNodes + nextCluster * nodesPerCluster
116
- const nextClusterEnd = nextCluster === numClusters - 1 ? numNodes : nextClusterStart + nodesPerCluster
117
- for (let j = nextClusterStart; j < Math.min(nextClusterStart + Math.floor(nodesPerCluster * 0.3), nextClusterEnd); j++) {
118
- linksArray.push(i)
119
- linksArray.push(j)
120
- }
121
- }
122
-
123
- // Connect nodes within clusters and some cross-cluster links
124
- for (let i = numCircleNodes; i < numNodes; i++) {
125
- const cluster = Math.floor((i - numCircleNodes) / nodesPerCluster)
126
- const clusterStart = numCircleNodes + cluster * nodesPerCluster
127
- const clusterEnd = cluster === numClusters - 1 ? numNodes : clusterStart + nodesPerCluster
128
-
129
- // Connect to nearby nodes in the same cluster
130
- for (let j = clusterStart; j < clusterEnd; j++) {
131
- if (i !== j && Math.abs(i - j) <= 3) {
132
- linksArray.push(i)
133
- linksArray.push(j)
134
- }
135
- }
136
-
137
- // Connect to nodes in adjacent clusters (sparse connections)
138
- if (i % 3 === 0) {
139
- const nextCluster = (cluster + 1) % numClusters
140
- const nextClusterStart = numCircleNodes + nextCluster * nodesPerCluster
141
- const nextClusterEnd = nextCluster === numClusters - 1 ? numNodes : nextClusterStart + nodesPerCluster
142
- const targetIndex = nextClusterStart + Math.floor(((i - clusterStart) % nodesPerCluster) * (nextClusterEnd - nextClusterStart) / nodesPerCluster)
143
- if (targetIndex < numNodes && targetIndex >= numCircleNodes) {
144
- linksArray.push(i)
145
- linksArray.push(targetIndex)
146
- }
147
- }
148
- }
149
-
150
- const links = new Float32Array(linksArray)
151
-
152
- return { pointPositions, links, pointColors }
153
- }