@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.
Files changed (186) hide show
  1. package/.eslintrc +147 -0
  2. package/.github/SECURITY.md +13 -0
  3. package/.github/dco.yml +4 -0
  4. package/.github/workflows/github_pages.yml +54 -0
  5. package/.storybook/main.ts +26 -0
  6. package/.storybook/manager-head.html +1 -0
  7. package/.storybook/manager.ts +14 -0
  8. package/.storybook/preview.ts +29 -0
  9. package/.storybook/style.css +3 -0
  10. package/CHARTER.md +69 -0
  11. package/CODE_OF_CONDUCT.md +178 -0
  12. package/CONTRIBUTING.md +22 -0
  13. package/GOVERNANCE.md +21 -0
  14. package/cosmos-2-0-migration-notes.md +98 -0
  15. package/cosmos_awesome.md +96 -0
  16. package/dist/config.d.ts +5 -9
  17. package/dist/graph/utils/error-message.d.ts +1 -1
  18. package/dist/helper.d.ts +39 -2
  19. package/dist/index-FUIgayhu.js +19827 -0
  20. package/dist/index-FUIgayhu.js.map +1 -0
  21. package/dist/index.d.ts +17 -64
  22. package/dist/index.js +14 -14654
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.min.js +1062 -475
  25. package/dist/index.min.js.map +1 -1
  26. package/dist/modules/Clusters/index.d.ts +11 -3
  27. package/dist/modules/ForceCenter/index.d.ts +10 -3
  28. package/dist/modules/ForceGravity/index.d.ts +5 -1
  29. package/dist/modules/ForceLink/index.d.ts +8 -5
  30. package/dist/modules/ForceManyBody/index.d.ts +16 -7
  31. package/dist/modules/ForceMouse/index.d.ts +5 -1
  32. package/dist/modules/GraphData/index.d.ts +0 -1
  33. package/dist/modules/Lines/index.d.ts +11 -5
  34. package/dist/modules/Points/index.d.ts +31 -13
  35. package/dist/modules/Store/index.d.ts +93 -0
  36. package/dist/modules/core-module.d.ts +3 -3
  37. package/dist/stories/beginners/basic-set-up/data-gen.d.ts +4 -0
  38. package/dist/stories/beginners/basic-set-up/index.d.ts +6 -0
  39. package/dist/stories/beginners/link-hovering/data-generator.d.ts +19 -0
  40. package/dist/stories/beginners/link-hovering/index.d.ts +6 -0
  41. package/dist/stories/beginners/point-labels/data.d.ts +13 -0
  42. package/dist/stories/beginners/point-labels/index.d.ts +10 -0
  43. package/dist/stories/beginners/point-labels/labels.d.ts +8 -0
  44. package/dist/stories/beginners/quick-start.d.ts +6 -0
  45. package/dist/stories/beginners/remove-points/config.d.ts +2 -0
  46. package/dist/stories/beginners/remove-points/data-gen.d.ts +4 -0
  47. package/dist/stories/beginners/remove-points/index.d.ts +6 -0
  48. package/dist/stories/beginners.stories.d.ts +10 -0
  49. package/dist/stories/clusters/polygon-selection/index.d.ts +6 -0
  50. package/dist/stories/clusters/polygon-selection/polygon.d.ts +20 -0
  51. package/dist/stories/clusters/radial.d.ts +6 -0
  52. package/dist/stories/clusters/with-labels.d.ts +6 -0
  53. package/dist/stories/clusters/worm.d.ts +6 -0
  54. package/dist/stories/clusters.stories.d.ts +9 -0
  55. package/dist/stories/create-cluster-labels.d.ts +4 -0
  56. package/dist/stories/create-cosmos.d.ts +17 -0
  57. package/dist/stories/create-story.d.ts +16 -0
  58. package/dist/stories/experiments/full-mesh.d.ts +6 -0
  59. package/dist/stories/experiments/mesh-with-holes.d.ts +6 -0
  60. package/dist/stories/experiments.stories.d.ts +7 -0
  61. package/dist/stories/generate-mesh-data.d.ts +12 -0
  62. package/dist/stories/geospatial/moscow-metro-stations/index.d.ts +16 -0
  63. package/dist/stories/geospatial/moscow-metro-stations/moscow-metro-coords.d.ts +1 -0
  64. package/dist/stories/geospatial/moscow-metro-stations/point-colors.d.ts +1 -0
  65. package/dist/stories/geospatial.stories.d.ts +6 -0
  66. package/dist/stories/shapes/all-shapes/index.d.ts +6 -0
  67. package/dist/stories/shapes/image-example/index.d.ts +6 -0
  68. package/dist/stories/shapes.stories.d.ts +7 -0
  69. package/dist/stories/test-luma-migration.d.ts +6 -0
  70. package/dist/stories/test.stories.d.ts +6 -0
  71. package/dist/webgl-device-B9ewDj5L.js +3923 -0
  72. package/dist/webgl-device-B9ewDj5L.js.map +1 -0
  73. package/logo.svg +3 -0
  74. package/package.json +5 -7
  75. package/rollup.config.js +70 -0
  76. package/src/config.ts +728 -0
  77. package/src/declaration.d.ts +12 -0
  78. package/src/graph/utils/error-message.ts +23 -0
  79. package/src/helper.ts +113 -0
  80. package/src/index.ts +1769 -0
  81. package/src/modules/Clusters/calculate-centermass.frag +12 -0
  82. package/src/modules/Clusters/calculate-centermass.vert +38 -0
  83. package/src/modules/Clusters/force-cluster.frag +55 -0
  84. package/src/modules/Clusters/index.ts +578 -0
  85. package/src/modules/Drag/index.ts +33 -0
  86. package/src/modules/FPSMonitor/css.ts +53 -0
  87. package/src/modules/FPSMonitor/index.ts +28 -0
  88. package/src/modules/ForceCenter/calculate-centermass.frag +9 -0
  89. package/src/modules/ForceCenter/calculate-centermass.vert +26 -0
  90. package/src/modules/ForceCenter/force-center.frag +37 -0
  91. package/src/modules/ForceCenter/index.ts +284 -0
  92. package/src/modules/ForceGravity/force-gravity.frag +40 -0
  93. package/src/modules/ForceGravity/index.ts +107 -0
  94. package/src/modules/ForceLink/force-spring.ts +89 -0
  95. package/src/modules/ForceLink/index.ts +293 -0
  96. package/src/modules/ForceManyBody/calculate-level.frag +9 -0
  97. package/src/modules/ForceManyBody/calculate-level.vert +37 -0
  98. package/src/modules/ForceManyBody/force-centermass.frag +61 -0
  99. package/src/modules/ForceManyBody/force-level.frag +138 -0
  100. package/src/modules/ForceManyBody/index.ts +525 -0
  101. package/src/modules/ForceManyBody/quadtree-frag-shader.ts +89 -0
  102. package/src/modules/ForceManyBodyQuadtree/calculate-level.frag +9 -0
  103. package/src/modules/ForceManyBodyQuadtree/calculate-level.vert +25 -0
  104. package/src/modules/ForceManyBodyQuadtree/index.ts +157 -0
  105. package/src/modules/ForceManyBodyQuadtree/quadtree-frag-shader.ts +93 -0
  106. package/src/modules/ForceMouse/force-mouse.frag +35 -0
  107. package/src/modules/ForceMouse/index.ts +102 -0
  108. package/src/modules/GraphData/index.ts +383 -0
  109. package/src/modules/Lines/draw-curve-line.frag +59 -0
  110. package/src/modules/Lines/draw-curve-line.vert +248 -0
  111. package/src/modules/Lines/geometry.ts +18 -0
  112. package/src/modules/Lines/hovered-line-index.frag +43 -0
  113. package/src/modules/Lines/hovered-line-index.vert +13 -0
  114. package/src/modules/Lines/index.ts +661 -0
  115. package/src/modules/Points/atlas-utils.ts +137 -0
  116. package/src/modules/Points/drag-point.frag +34 -0
  117. package/src/modules/Points/draw-highlighted.frag +44 -0
  118. package/src/modules/Points/draw-highlighted.vert +145 -0
  119. package/src/modules/Points/draw-points.frag +259 -0
  120. package/src/modules/Points/draw-points.vert +203 -0
  121. package/src/modules/Points/fill-sampled-points.frag +12 -0
  122. package/src/modules/Points/fill-sampled-points.vert +51 -0
  123. package/src/modules/Points/find-hovered-point.frag +15 -0
  124. package/src/modules/Points/find-hovered-point.vert +90 -0
  125. package/src/modules/Points/find-points-on-area-selection.frag +88 -0
  126. package/src/modules/Points/find-points-on-polygon-selection.frag +89 -0
  127. package/src/modules/Points/index.ts +2292 -0
  128. package/src/modules/Points/track-positions.frag +30 -0
  129. package/src/modules/Points/update-position.frag +39 -0
  130. package/src/modules/Shared/buffer.ts +39 -0
  131. package/src/modules/Shared/clear.frag +10 -0
  132. package/src/modules/Shared/quad.vert +13 -0
  133. package/src/modules/Store/index.ts +283 -0
  134. package/src/modules/Zoom/index.ts +148 -0
  135. package/src/modules/core-module.ts +28 -0
  136. package/src/stories/1. welcome.mdx +75 -0
  137. package/src/stories/2. configuration.mdx +111 -0
  138. package/src/stories/3. api-reference.mdx +591 -0
  139. package/src/stories/beginners/basic-set-up/data-gen.ts +33 -0
  140. package/src/stories/beginners/basic-set-up/index.ts +167 -0
  141. package/src/stories/beginners/basic-set-up/style.css +35 -0
  142. package/src/stories/beginners/link-hovering/data-generator.ts +198 -0
  143. package/src/stories/beginners/link-hovering/index.ts +65 -0
  144. package/src/stories/beginners/link-hovering/style.css +73 -0
  145. package/src/stories/beginners/point-labels/data.ts +73 -0
  146. package/src/stories/beginners/point-labels/index.ts +69 -0
  147. package/src/stories/beginners/point-labels/labels.ts +46 -0
  148. package/src/stories/beginners/point-labels/style.css +16 -0
  149. package/src/stories/beginners/quick-start.ts +54 -0
  150. package/src/stories/beginners/remove-points/config.ts +25 -0
  151. package/src/stories/beginners/remove-points/data-gen.ts +30 -0
  152. package/src/stories/beginners/remove-points/index.ts +96 -0
  153. package/src/stories/beginners/remove-points/style.css +31 -0
  154. package/src/stories/beginners.stories.ts +130 -0
  155. package/src/stories/clusters/polygon-selection/index.ts +52 -0
  156. package/src/stories/clusters/polygon-selection/polygon.ts +143 -0
  157. package/src/stories/clusters/polygon-selection/style.css +8 -0
  158. package/src/stories/clusters/radial.ts +24 -0
  159. package/src/stories/clusters/with-labels.ts +54 -0
  160. package/src/stories/clusters/worm.ts +40 -0
  161. package/src/stories/clusters.stories.ts +77 -0
  162. package/src/stories/create-cluster-labels.ts +50 -0
  163. package/src/stories/create-cosmos.ts +72 -0
  164. package/src/stories/create-story.ts +51 -0
  165. package/src/stories/experiments/full-mesh.ts +13 -0
  166. package/src/stories/experiments/mesh-with-holes.ts +13 -0
  167. package/src/stories/experiments.stories.ts +43 -0
  168. package/src/stories/generate-mesh-data.ts +125 -0
  169. package/src/stories/geospatial/moscow-metro-stations/index.ts +66 -0
  170. package/src/stories/geospatial/moscow-metro-stations/moscow-metro-coords.ts +1 -0
  171. package/src/stories/geospatial/moscow-metro-stations/point-colors.ts +46 -0
  172. package/src/stories/geospatial/moscow-metro-stations/style.css +30 -0
  173. package/src/stories/geospatial.stories.ts +30 -0
  174. package/src/stories/shapes/all-shapes/index.ts +73 -0
  175. package/src/stories/shapes/image-example/icons/box.png +0 -0
  176. package/src/stories/shapes/image-example/icons/lego.png +0 -0
  177. package/src/stories/shapes/image-example/icons/s.png +0 -0
  178. package/src/stories/shapes/image-example/icons/swift.png +0 -0
  179. package/src/stories/shapes/image-example/icons/toolbox.png +0 -0
  180. package/src/stories/shapes/image-example/index.ts +246 -0
  181. package/src/stories/shapes.stories.ts +37 -0
  182. package/src/stories/test-luma-migration.ts +195 -0
  183. package/src/stories/test.stories.ts +25 -0
  184. package/src/variables.ts +68 -0
  185. package/tsconfig.json +41 -0
  186. package/vite.config.ts +52 -0
@@ -0,0 +1,203 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ in vec2 pointIndices;
7
+ in float size;
8
+ in vec4 color;
9
+ in float shape;
10
+ in float imageIndex;
11
+ in float imageSize;
12
+
13
+ uniform sampler2D positionsTexture;
14
+ uniform sampler2D pointGreyoutStatus;
15
+ uniform sampler2D imageAtlasCoords;
16
+
17
+ #ifdef USE_UNIFORM_BUFFERS
18
+ layout(std140) uniform drawVertexUniforms {
19
+ float ratio;
20
+ mat4 transformationMatrix;
21
+ float pointsTextureSize;
22
+ float sizeScale;
23
+ float spaceSize;
24
+ vec2 screenSize;
25
+ vec4 greyoutColor;
26
+ vec4 backgroundColor;
27
+ float scalePointsOnZoom;
28
+ float maxPointSize;
29
+ float isDarkenGreyout;
30
+ float skipSelected;
31
+ float skipUnselected;
32
+ float hasImages;
33
+ float imageCount;
34
+ float imageAtlasCoordsTextureSize;
35
+ } drawVertex;
36
+
37
+ #define ratio drawVertex.ratio
38
+ #define transformationMatrix drawVertex.transformationMatrix
39
+ #define pointsTextureSize drawVertex.pointsTextureSize
40
+ #define sizeScale drawVertex.sizeScale
41
+ #define spaceSize drawVertex.spaceSize
42
+ #define screenSize drawVertex.screenSize
43
+ #define greyoutColor drawVertex.greyoutColor
44
+ #define backgroundColor drawVertex.backgroundColor
45
+ #define scalePointsOnZoom drawVertex.scalePointsOnZoom
46
+ #define maxPointSize drawVertex.maxPointSize
47
+ #define isDarkenGreyout drawVertex.isDarkenGreyout
48
+ #define skipSelected drawVertex.skipSelected
49
+ #define skipUnselected drawVertex.skipUnselected
50
+ #define hasImages drawVertex.hasImages
51
+ #define imageCount drawVertex.imageCount
52
+ #define imageAtlasCoordsTextureSize drawVertex.imageAtlasCoordsTextureSize
53
+ #else
54
+ uniform float ratio;
55
+ uniform mat3 transformationMatrix;
56
+ uniform float pointsTextureSize;
57
+ uniform float sizeScale;
58
+ uniform float spaceSize;
59
+ uniform vec2 screenSize;
60
+ uniform vec4 greyoutColor;
61
+ uniform vec4 backgroundColor;
62
+ uniform float scalePointsOnZoom;
63
+ uniform float maxPointSize;
64
+ uniform float isDarkenGreyout;
65
+ uniform float skipSelected;
66
+ uniform float skipUnselected;
67
+ uniform float hasImages;
68
+ uniform float imageCount;
69
+ uniform float imageAtlasCoordsTextureSize;
70
+ #endif
71
+
72
+ out float pointShape;
73
+ out float isGreyedOut;
74
+ out vec4 shapeColor;
75
+ out vec4 imageAtlasUV;
76
+ out float shapeSize;
77
+ out float imageSizeVarying;
78
+ out float overallSize;
79
+
80
+ float calculatePointSize(float size) {
81
+ float pSize;
82
+
83
+ if (scalePointsOnZoom > 0.0) {
84
+ pSize = size * ratio * transformationMatrix[0][0];
85
+ } else {
86
+ pSize = size * ratio * min(5.0, max(1.0, transformationMatrix[0][0] * 0.01));
87
+ }
88
+
89
+ return min(pSize, maxPointSize * ratio);
90
+ }
91
+
92
+ void main() {
93
+ // Check greyout status for selective rendering
94
+ vec4 greyoutStatus = texture(pointGreyoutStatus, (pointIndices + 0.5) / pointsTextureSize);
95
+ isGreyedOut = greyoutStatus.r;
96
+ float isSelected = (greyoutStatus.r == 0.0) ? 1.0 : 0.0;
97
+
98
+ // Discard point based on rendering mode
99
+ if (skipSelected > 0.0 && isSelected > 0.0) {
100
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Move off-screen
101
+ gl_PointSize = 0.0;
102
+ return;
103
+ }
104
+ if (skipUnselected > 0.0 && isSelected <= 0.0) {
105
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Move off-screen
106
+ gl_PointSize = 0.0;
107
+ return;
108
+ }
109
+
110
+ // Position
111
+ vec4 pointPosition = texture(positionsTexture, (pointIndices + 0.5) / pointsTextureSize);
112
+ vec2 point = pointPosition.rg;
113
+
114
+ // Transform point position to normalized device coordinates
115
+ // Convert from space coordinates [0, spaceSize] to normalized [-1, 1]
116
+ vec2 normalizedPosition = 2.0 * point / spaceSize - 1.0;
117
+
118
+ // Apply aspect ratio correction - this is needed to map the square space to the rectangular screen
119
+ // The transformation matrix handles zoom/pan, but we need this to handle aspect ratio
120
+ normalizedPosition *= spaceSize / screenSize;
121
+
122
+ #ifdef USE_UNIFORM_BUFFERS
123
+ mat3 transformMat3 = mat3(transformationMatrix);
124
+ vec3 finalPosition = transformMat3 * vec3(normalizedPosition, 1);
125
+ #else
126
+ vec3 finalPosition = transformationMatrix * vec3(normalizedPosition, 1);
127
+ #endif
128
+ gl_Position = vec4(finalPosition.rg, 0, 1);
129
+
130
+ // Calculate sizes for shape and image
131
+ float shapeSizeValue = calculatePointSize(size * sizeScale);
132
+ float imageSizeValue = calculatePointSize(imageSize * sizeScale);
133
+
134
+ // Use the larger of the two sizes for the overall point size
135
+ float overallSizeValue = max(shapeSizeValue, imageSizeValue);
136
+ gl_PointSize = overallSizeValue;
137
+
138
+ // Pass size information to fragment shader
139
+ shapeSize = shapeSizeValue;
140
+ imageSizeVarying = imageSizeValue;
141
+ overallSize = overallSizeValue;
142
+
143
+ shapeColor = color;
144
+ pointShape = shape;
145
+
146
+ // Adjust alpha of selected points
147
+ if (isGreyedOut > 0.0) {
148
+ if (greyoutColor[0] != -1.0) {
149
+ shapeColor = greyoutColor;
150
+ } else {
151
+ // If greyoutColor is not set, make color lighter or darker based on isDarkenGreyout
152
+ float blendFactor = 0.65; // Controls how much to modify (0.0 = original, 1.0 = target color)
153
+
154
+ #ifdef USE_UNIFORM_BUFFERS
155
+ if (isDarkenGreyout > 0.0) {
156
+ // Darken the color
157
+ shapeColor.rgb = mix(shapeColor.rgb, vec3(0.2), blendFactor);
158
+ } else {
159
+ // Lighten the color
160
+ shapeColor.rgb = mix(shapeColor.rgb, max(backgroundColor.rgb, vec3(0.8)), blendFactor);
161
+ }
162
+ #else
163
+ if (isDarkenGreyout > 0.0) {
164
+ // Darken the color
165
+ shapeColor.rgb = mix(shapeColor.rgb, vec3(0.2), blendFactor);
166
+ } else {
167
+ // Lighten the color
168
+ shapeColor.rgb = mix(shapeColor.rgb, max(backgroundColor.rgb, vec3(0.8)), blendFactor);
169
+ }
170
+ #endif
171
+ }
172
+ }
173
+
174
+ #ifdef USE_UNIFORM_BUFFERS
175
+ if (hasImages <= 0.0 || imageIndex < 0.0 || imageIndex >= imageCount) {
176
+ imageAtlasUV = vec4(-1.0);
177
+ } else {
178
+ // Calculate image atlas UV coordinates based on imageIndex
179
+ float atlasCoordIndex = imageIndex;
180
+ // Calculate the position in the texture grid
181
+ float texX = mod(atlasCoordIndex, imageAtlasCoordsTextureSize);
182
+ float texY = floor(atlasCoordIndex / imageAtlasCoordsTextureSize);
183
+ // Convert to texture coordinates (0.0 to 1.0)
184
+ vec2 atlasCoordTexCoord = (vec2(texX, texY) + 0.5) / imageAtlasCoordsTextureSize;
185
+ vec4 atlasCoords = texture(imageAtlasCoords, atlasCoordTexCoord);
186
+ imageAtlasUV = atlasCoords;
187
+ }
188
+ #else
189
+ if (hasImages <= 0.0 || imageIndex < 0.0 || imageIndex >= imageCount) {
190
+ imageAtlasUV = vec4(-1.0);
191
+ } else {
192
+ // Calculate image atlas UV coordinates based on imageIndex
193
+ float atlasCoordIndex = imageIndex;
194
+ // Calculate the position in the texture grid
195
+ float texX = mod(atlasCoordIndex, imageAtlasCoordsTextureSize);
196
+ float texY = floor(atlasCoordIndex / imageAtlasCoordsTextureSize);
197
+ // Convert to texture coordinates (0.0 to 1.0)
198
+ vec2 atlasCoordTexCoord = (vec2(texX, texY) + 0.5) / imageAtlasCoordsTextureSize;
199
+ vec4 atlasCoords = texture(imageAtlasCoords, atlasCoordTexCoord);
200
+ imageAtlasUV = atlasCoords;
201
+ }
202
+ #endif
203
+ }
@@ -0,0 +1,12 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ in vec4 rgba;
7
+
8
+ out vec4 fragColor;
9
+
10
+ void main() {
11
+ fragColor = rgba;
12
+ }
@@ -0,0 +1,51 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ in vec2 pointIndices;
7
+
8
+ uniform sampler2D positionsTexture;
9
+
10
+ #ifdef USE_UNIFORM_BUFFERS
11
+ layout(std140) uniform fillSampledPointsUniforms {
12
+ float pointsTextureSize;
13
+ mat4 transformationMatrix;
14
+ float spaceSize;
15
+ vec2 screenSize;
16
+ } fillSampledPoints;
17
+
18
+ #define pointsTextureSize fillSampledPoints.pointsTextureSize
19
+ #define transformationMatrix fillSampledPoints.transformationMatrix
20
+ #define spaceSize fillSampledPoints.spaceSize
21
+ #define screenSize fillSampledPoints.screenSize
22
+ #else
23
+ uniform float pointsTextureSize;
24
+ uniform float spaceSize;
25
+ uniform vec2 screenSize;
26
+ uniform mat3 transformationMatrix;
27
+ #endif
28
+
29
+ out vec4 rgba;
30
+
31
+ void main() {
32
+ vec4 pointPosition = texture(positionsTexture, (pointIndices + 0.5) / pointsTextureSize);
33
+ vec2 p = 2.0 * pointPosition.rg / spaceSize - 1.0;
34
+ p *= spaceSize / screenSize;
35
+ #ifdef USE_UNIFORM_BUFFERS
36
+ // Convert mat4 to mat3 for vec3 multiplication
37
+ mat3 transformMat3 = mat3(transformationMatrix);
38
+ vec3 final = transformMat3 * vec3(p, 1);
39
+ #else
40
+ vec3 final = transformationMatrix * vec3(p, 1);
41
+ #endif
42
+
43
+ vec2 pointScreenPosition = (final.xy + 1.0) * screenSize / 2.0;
44
+ float index = pointIndices.g * pointsTextureSize + pointIndices.r;
45
+ rgba = vec4(index, 1.0, pointPosition.xy);
46
+ float i = (pointScreenPosition.x + 0.5) / screenSize.x;
47
+ float j = (pointScreenPosition.y + 0.5) / screenSize.y;
48
+ gl_Position = vec4(2.0 * vec2(i, j) - 1.0, 0.0, 1.0);
49
+
50
+ gl_PointSize = 1.0;
51
+ }
@@ -0,0 +1,15 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ in vec4 rgba;
7
+
8
+ out vec4 fragColor;
9
+
10
+ void main() {
11
+ if (rgba.g <= 0.0) {
12
+ discard;
13
+ }
14
+ fragColor = rgba;
15
+ }
@@ -0,0 +1,90 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ in vec2 pointIndices;
7
+ in float size;
8
+
9
+ uniform sampler2D positionsTexture;
10
+
11
+ #ifdef USE_UNIFORM_BUFFERS
12
+ layout(std140) uniform findHoveredPointUniforms {
13
+ float pointsTextureSize;
14
+ float sizeScale;
15
+ float spaceSize;
16
+ vec2 screenSize;
17
+ float ratio;
18
+ mat4 transformationMatrix;
19
+ vec2 mousePosition;
20
+ float scalePointsOnZoom;
21
+ float maxPointSize;
22
+ } findHoveredPoint;
23
+
24
+ #define pointsTextureSize findHoveredPoint.pointsTextureSize
25
+ #define sizeScale findHoveredPoint.sizeScale
26
+ #define spaceSize findHoveredPoint.spaceSize
27
+ #define screenSize findHoveredPoint.screenSize
28
+ #define ratio findHoveredPoint.ratio
29
+ #define transformationMatrix findHoveredPoint.transformationMatrix
30
+ #define mousePosition findHoveredPoint.mousePosition
31
+ #define scalePointsOnZoom findHoveredPoint.scalePointsOnZoom
32
+ #define maxPointSize findHoveredPoint.maxPointSize
33
+ #else
34
+ uniform float pointsTextureSize;
35
+ uniform float sizeScale;
36
+ uniform float spaceSize;
37
+ uniform vec2 screenSize;
38
+ uniform float ratio;
39
+ uniform mat3 transformationMatrix;
40
+ uniform vec2 mousePosition;
41
+ uniform float scalePointsOnZoom;
42
+ uniform float maxPointSize;
43
+ #endif
44
+
45
+ out vec4 rgba;
46
+
47
+ float calculatePointSize(float size) {
48
+ float pSize;
49
+
50
+ if (scalePointsOnZoom > 0.0) {
51
+ pSize = size * ratio * transformationMatrix[0][0];
52
+ } else {
53
+ pSize = size * ratio * min(5.0, max(1.0, transformationMatrix[0][0] * 0.01));
54
+ }
55
+
56
+ return min(pSize, maxPointSize * ratio);
57
+ }
58
+
59
+ float euclideanDistance (float x1, float x2, float y1, float y2) {
60
+ return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
61
+ }
62
+
63
+ void main() {
64
+ vec4 pointPosition = texture(positionsTexture, (pointIndices + 0.5) / pointsTextureSize);
65
+ vec2 point = pointPosition.rg;
66
+
67
+ vec2 normalizedPosition = 2.0 * point / spaceSize - 1.0;
68
+ normalizedPosition *= spaceSize / screenSize;
69
+
70
+ #ifdef USE_UNIFORM_BUFFERS
71
+ mat3 transformMat3 = mat3(transformationMatrix);
72
+ vec3 finalPosition = transformMat3 * vec3(normalizedPosition, 1);
73
+ #else
74
+ vec3 finalPosition = transformationMatrix * vec3(normalizedPosition, 1);
75
+ #endif
76
+
77
+ float pointRadius = 0.5 * calculatePointSize(size * sizeScale);
78
+ vec2 pointScreenPosition = (finalPosition.xy + 1.0) * screenSize / 2.0;
79
+
80
+ rgba = vec4(0.0);
81
+ gl_Position = vec4(0.5, 0.5, 0.0, 1.0);
82
+
83
+ if (euclideanDistance(pointScreenPosition.x, mousePosition.x, pointScreenPosition.y, mousePosition.y) < pointRadius / ratio) {
84
+ float index = pointIndices.g * pointsTextureSize + pointIndices.r;
85
+ rgba = vec4(index, size, pointPosition.xy);
86
+ gl_Position = vec4(-0.5, -0.5, 0.0, 1.0);
87
+ }
88
+
89
+ gl_PointSize = 1.0;
90
+ }
@@ -0,0 +1,88 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ uniform sampler2D positionsTexture;
7
+ uniform sampler2D pointSize;
8
+
9
+ #ifdef USE_UNIFORM_BUFFERS
10
+ layout(std140) uniform findPointsOnAreaSelectionUniforms {
11
+ float sizeScale;
12
+ float spaceSize;
13
+ vec2 screenSize;
14
+ float ratio;
15
+ mat4 transformationMatrix;
16
+ vec2 selection0;
17
+ vec2 selection1;
18
+ float scalePointsOnZoom;
19
+ float maxPointSize;
20
+ } findPointsOnAreaSelection;
21
+
22
+ #define sizeScale findPointsOnAreaSelection.sizeScale
23
+ #define spaceSize findPointsOnAreaSelection.spaceSize
24
+ #define screenSize findPointsOnAreaSelection.screenSize
25
+ #define ratio findPointsOnAreaSelection.ratio
26
+ #define transformationMatrix findPointsOnAreaSelection.transformationMatrix
27
+ #define selection0 findPointsOnAreaSelection.selection0
28
+ #define selection1 findPointsOnAreaSelection.selection1
29
+ #define scalePointsOnZoom findPointsOnAreaSelection.scalePointsOnZoom
30
+ #define maxPointSize findPointsOnAreaSelection.maxPointSize
31
+ #else
32
+ uniform float sizeScale;
33
+ uniform float spaceSize;
34
+ uniform vec2 screenSize;
35
+ uniform float ratio;
36
+ uniform mat3 transformationMatrix;
37
+ uniform vec2 selection0;
38
+ uniform vec2 selection1;
39
+ uniform float scalePointsOnZoom;
40
+ uniform float maxPointSize;
41
+ #endif
42
+
43
+ in vec2 textureCoords;
44
+
45
+ out vec4 fragColor;
46
+
47
+ float pointSizeF(float size) {
48
+ float pSize;
49
+ // Extract top-left element from mat4 (or use mat3 conversion)
50
+ #ifdef USE_UNIFORM_BUFFERS
51
+ float scale = transformationMatrix[0][0]; // mat4 first element
52
+ #else
53
+ float scale = transformationMatrix[0][0]; // mat3 first element
54
+ #endif
55
+ if (scalePointsOnZoom > 0.0) {
56
+ pSize = size * ratio * scale;
57
+ } else {
58
+ pSize = size * ratio * min(5.0, max(1.0, scale * 0.01));
59
+ }
60
+ return min(pSize, maxPointSize * ratio);
61
+ }
62
+
63
+ void main() {
64
+ vec4 pointPosition = texture(positionsTexture, textureCoords);
65
+ vec2 p = 2.0 * pointPosition.rg / spaceSize - 1.0;
66
+ p *= spaceSize / screenSize;
67
+ #ifdef USE_UNIFORM_BUFFERS
68
+ // Convert mat4 to mat3 for vec3 multiplication
69
+ mat3 transformMat3 = mat3(transformationMatrix);
70
+ vec3 final = transformMat3 * vec3(p, 1);
71
+ #else
72
+ vec3 final = transformationMatrix * vec3(p, 1);
73
+ #endif
74
+
75
+ vec4 pSize = texture(pointSize, textureCoords);
76
+ float size = pSize.r * sizeScale;
77
+
78
+ float left = 2.0 * (selection0.x - 0.5 * pointSizeF(size)) / screenSize.x - 1.0;
79
+ float right = 2.0 * (selection1.x + 0.5 * pointSizeF(size)) / screenSize.x - 1.0;
80
+ float top = 2.0 * (selection0.y - 0.5 * pointSizeF(size)) / screenSize.y - 1.0;
81
+ float bottom = 2.0 * (selection1.y + 0.5 * pointSizeF(size)) / screenSize.y - 1.0;
82
+
83
+ fragColor = vec4(0.0, 0.0, pointPosition.r, pointPosition.g);
84
+ if (final.x >= left && final.x <= right && final.y >= top && final.y <= bottom) {
85
+ fragColor.r = 1.0;
86
+ }
87
+ }
88
+
@@ -0,0 +1,89 @@
1
+ #version 300 es
2
+ #ifdef GL_ES
3
+ precision highp float;
4
+ #endif
5
+
6
+ uniform sampler2D positionsTexture;
7
+ uniform sampler2D polygonPathTexture; // Texture containing polygon path points
8
+
9
+ #ifdef USE_UNIFORM_BUFFERS
10
+ layout(std140) uniform findPointsOnPolygonSelectionUniforms {
11
+ float spaceSize;
12
+ vec2 screenSize;
13
+ mat4 transformationMatrix;
14
+ float polygonPathLength;
15
+ } findPointsOnPolygonSelection;
16
+
17
+ #define spaceSize findPointsOnPolygonSelection.spaceSize
18
+ #define screenSize findPointsOnPolygonSelection.screenSize
19
+ #define transformationMatrix findPointsOnPolygonSelection.transformationMatrix
20
+ #define polygonPathLength int(findPointsOnPolygonSelection.polygonPathLength)
21
+ #else
22
+ uniform int polygonPathLength;
23
+ uniform float spaceSize;
24
+ uniform vec2 screenSize;
25
+ uniform mat3 transformationMatrix;
26
+ #endif
27
+
28
+ in vec2 textureCoords;
29
+
30
+ out vec4 fragColor;
31
+
32
+ // Get a point from the polygon path texture at a specific index
33
+ vec2 getPolygonPoint(sampler2D pathTexture, int index, int pathLength) {
34
+ if (index >= pathLength) return vec2(0.0);
35
+
36
+ // Calculate texture coordinates for the index
37
+ int textureSize = int(ceil(sqrt(float(pathLength))));
38
+ int x = index - (index / textureSize) * textureSize;
39
+ int y = index / textureSize;
40
+
41
+ vec2 texCoord = (vec2(float(x), float(y)) + 0.5) / float(textureSize);
42
+ vec4 pathData = texture(pathTexture, texCoord);
43
+
44
+ return pathData.xy;
45
+ }
46
+
47
+ // Point-in-polygon algorithm using ray casting
48
+ bool pointInPolygon(vec2 point, sampler2D pathTexture, int pathLength) {
49
+ bool inside = false;
50
+
51
+ for (int i = 0; i < 2048; i++) {
52
+ if (i >= pathLength) break;
53
+
54
+ int j = int(mod(float(i + 1), float(pathLength)));
55
+
56
+ vec2 pi = getPolygonPoint(pathTexture, i, pathLength);
57
+ vec2 pj = getPolygonPoint(pathTexture, j, pathLength);
58
+
59
+ if (((pi.y > point.y) != (pj.y > point.y)) &&
60
+ (point.x < (pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x)) {
61
+ inside = !inside;
62
+ }
63
+ }
64
+
65
+ return inside;
66
+ }
67
+
68
+ void main() {
69
+ vec4 pointPosition = texture(positionsTexture, textureCoords);
70
+ vec2 p = 2.0 * pointPosition.rg / spaceSize - 1.0;
71
+ p *= spaceSize / screenSize;
72
+ #ifdef USE_UNIFORM_BUFFERS
73
+ // Convert mat4 to mat3 for vec3 multiplication
74
+ mat3 transformMat3 = mat3(transformationMatrix);
75
+ vec3 final = transformMat3 * vec3(p, 1);
76
+ #else
77
+ vec3 final = transformationMatrix * vec3(p, 1);
78
+ #endif
79
+
80
+ // Convert to screen coordinates for polygon check
81
+ vec2 screenPos = (final.xy + 1.0) * screenSize / 2.0;
82
+
83
+ fragColor = vec4(0.0, 0.0, pointPosition.r, pointPosition.g);
84
+
85
+ // Check if point center is inside the polygon
86
+ if (pointInPolygon(screenPos, polygonPathTexture, polygonPathLength)) {
87
+ fragColor.r = 1.0;
88
+ }
89
+ }