@vitessce/gl 2.0.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.
@@ -0,0 +1,340 @@
1
+ export const colormaps = `#define GLSLIFY 1
2
+ vec4 plasma (float x_4) {
3
+ const float e0 = 0.0;
4
+ const vec4 v0 = vec4(0.050980392156862744,0.03137254901960784,0.5294117647058824,1);
5
+ const float e1 = 0.13;
6
+ const vec4 v1 = vec4(0.29411764705882354,0.011764705882352941,0.6313725490196078,1);
7
+ const float e2 = 0.25;
8
+ const vec4 v2 = vec4(0.49019607843137253,0.011764705882352941,0.6588235294117647,1);
9
+ const float e3 = 0.38;
10
+ const vec4 v3 = vec4(0.6588235294117647,0.13333333333333333,0.5882352941176471,1);
11
+ const float e4 = 0.5;
12
+ const vec4 v4 = vec4(0.796078431372549,0.27450980392156865,0.4745098039215686,1);
13
+ const float e5 = 0.63;
14
+ const vec4 v5 = vec4(0.8980392156862745,0.4196078431372549,0.36470588235294116,1);
15
+ const float e6 = 0.75;
16
+ const vec4 v6 = vec4(0.9725490196078431,0.5803921568627451,0.2549019607843137,1);
17
+ const float e7 = 0.88;
18
+ const vec4 v7 = vec4(0.9921568627450981,0.7647058823529411,0.1568627450980392,1);
19
+ const float e8 = 1.0;
20
+ const vec4 v8 = vec4(0.9411764705882353,0.9764705882352941,0.12941176470588237,1);
21
+ float a0 = smoothstep(e0,e1,x_4);
22
+ float a1 = smoothstep(e1,e2,x_4);
23
+ float a2 = smoothstep(e2,e3,x_4);
24
+ float a3 = smoothstep(e3,e4,x_4);
25
+ float a4 = smoothstep(e4,e5,x_4);
26
+ float a5 = smoothstep(e5,e6,x_4);
27
+ float a6 = smoothstep(e6,e7,x_4);
28
+ float a7 = smoothstep(e7,e8,x_4);
29
+ return max(mix(v0,v1,a0)*step(e0,x_4)*step(x_4,e1),
30
+ max(mix(v1,v2,a1)*step(e1,x_4)*step(x_4,e2),
31
+ max(mix(v2,v3,a2)*step(e2,x_4)*step(x_4,e3),
32
+ max(mix(v3,v4,a3)*step(e3,x_4)*step(x_4,e4),
33
+ max(mix(v4,v5,a4)*step(e4,x_4)*step(x_4,e5),
34
+ max(mix(v5,v6,a5)*step(e5,x_4)*step(x_4,e6),
35
+ max(mix(v6,v7,a6)*step(e6,x_4)*step(x_4,e7),mix(v7,v8,a7)*step(e7,x_4)*step(x_4,e8)
36
+ )))))));
37
+ }
38
+
39
+ vec4 viridis (float x_1) {
40
+ const float e0 = 0.0;
41
+ const vec4 v0 = vec4(0.26666666666666666,0.00392156862745098,0.32941176470588235,1);
42
+ const float e1 = 0.13;
43
+ const vec4 v1 = vec4(0.2784313725490196,0.17254901960784313,0.47843137254901963,1);
44
+ const float e2 = 0.25;
45
+ const vec4 v2 = vec4(0.23137254901960785,0.3176470588235294,0.5450980392156862,1);
46
+ const float e3 = 0.38;
47
+ const vec4 v3 = vec4(0.17254901960784313,0.44313725490196076,0.5568627450980392,1);
48
+ const float e4 = 0.5;
49
+ const vec4 v4 = vec4(0.12941176470588237,0.5647058823529412,0.5529411764705883,1);
50
+ const float e5 = 0.63;
51
+ const vec4 v5 = vec4(0.15294117647058825,0.6784313725490196,0.5058823529411764,1);
52
+ const float e6 = 0.75;
53
+ const vec4 v6 = vec4(0.3607843137254902,0.7843137254901961,0.38823529411764707,1);
54
+ const float e7 = 0.88;
55
+ const vec4 v7 = vec4(0.6666666666666666,0.8627450980392157,0.19607843137254902,1);
56
+ const float e8 = 1.0;
57
+ const vec4 v8 = vec4(0.9921568627450981,0.9058823529411765,0.1450980392156863,1);
58
+ float a0 = smoothstep(e0,e1,x_1);
59
+ float a1 = smoothstep(e1,e2,x_1);
60
+ float a2 = smoothstep(e2,e3,x_1);
61
+ float a3 = smoothstep(e3,e4,x_1);
62
+ float a4 = smoothstep(e4,e5,x_1);
63
+ float a5 = smoothstep(e5,e6,x_1);
64
+ float a6 = smoothstep(e6,e7,x_1);
65
+ float a7 = smoothstep(e7,e8,x_1);
66
+ return max(mix(v0,v1,a0)*step(e0,x_1)*step(x_1,e1),
67
+ max(mix(v1,v2,a1)*step(e1,x_1)*step(x_1,e2),
68
+ max(mix(v2,v3,a2)*step(e2,x_1)*step(x_1,e3),
69
+ max(mix(v3,v4,a3)*step(e3,x_1)*step(x_1,e4),
70
+ max(mix(v4,v5,a4)*step(e4,x_1)*step(x_1,e5),
71
+ max(mix(v5,v6,a5)*step(e5,x_1)*step(x_1,e6),
72
+ max(mix(v6,v7,a6)*step(e6,x_1)*step(x_1,e7),mix(v7,v8,a7)*step(e7,x_1)*step(x_1,e8)
73
+ )))))));
74
+ }
75
+
76
+ vec4 greys (float x_10) {
77
+ const float e0 = 0.0;
78
+ const vec4 v0 = vec4(0,0,0,1);
79
+ const float e1 = 1.0;
80
+ const vec4 v1 = vec4(1,1,1,1);
81
+ float a0 = smoothstep(e0,e1,x_10);
82
+ return mix(v0,v1,a0)*step(e0,x_10)*step(x_10,e1);
83
+ }
84
+
85
+ vec4 magma (float x_7) {
86
+ const float e0 = 0.0;
87
+ const vec4 v0 = vec4(0,0,0.01568627450980392,1);
88
+ const float e1 = 0.13;
89
+ const vec4 v1 = vec4(0.10980392156862745,0.06274509803921569,0.26666666666666666,1);
90
+ const float e2 = 0.25;
91
+ const vec4 v2 = vec4(0.30980392156862746,0.07058823529411765,0.4823529411764706,1);
92
+ const float e3 = 0.38;
93
+ const vec4 v3 = vec4(0.5058823529411764,0.1450980392156863,0.5058823529411764,1);
94
+ const float e4 = 0.5;
95
+ const vec4 v4 = vec4(0.7098039215686275,0.21176470588235294,0.47843137254901963,1);
96
+ const float e5 = 0.63;
97
+ const vec4 v5 = vec4(0.8980392156862745,0.3137254901960784,0.39215686274509803,1);
98
+ const float e6 = 0.75;
99
+ const vec4 v6 = vec4(0.984313725490196,0.5294117647058824,0.3803921568627451,1);
100
+ const float e7 = 0.88;
101
+ const vec4 v7 = vec4(0.996078431372549,0.7607843137254902,0.5294117647058824,1);
102
+ const float e8 = 1.0;
103
+ const vec4 v8 = vec4(0.9882352941176471,0.9921568627450981,0.7490196078431373,1);
104
+ float a0 = smoothstep(e0,e1,x_7);
105
+ float a1 = smoothstep(e1,e2,x_7);
106
+ float a2 = smoothstep(e2,e3,x_7);
107
+ float a3 = smoothstep(e3,e4,x_7);
108
+ float a4 = smoothstep(e4,e5,x_7);
109
+ float a5 = smoothstep(e5,e6,x_7);
110
+ float a6 = smoothstep(e6,e7,x_7);
111
+ float a7 = smoothstep(e7,e8,x_7);
112
+ return max(mix(v0,v1,a0)*step(e0,x_7)*step(x_7,e1),
113
+ max(mix(v1,v2,a1)*step(e1,x_7)*step(x_7,e2),
114
+ max(mix(v2,v3,a2)*step(e2,x_7)*step(x_7,e3),
115
+ max(mix(v3,v4,a3)*step(e3,x_7)*step(x_7,e4),
116
+ max(mix(v4,v5,a4)*step(e4,x_7)*step(x_7,e5),
117
+ max(mix(v5,v6,a5)*step(e5,x_7)*step(x_7,e6),
118
+ max(mix(v6,v7,a6)*step(e6,x_7)*step(x_7,e7),mix(v7,v8,a7)*step(e7,x_7)*step(x_7,e8)
119
+ )))))));
120
+ }
121
+
122
+ vec4 jet (float x_8) {
123
+ const float e0 = 0.0;
124
+ const vec4 v0 = vec4(0,0,0.5137254901960784,1);
125
+ const float e1 = 0.125;
126
+ const vec4 v1 = vec4(0,0.23529411764705882,0.6666666666666666,1);
127
+ const float e2 = 0.375;
128
+ const vec4 v2 = vec4(0.0196078431372549,1,1,1);
129
+ const float e3 = 0.625;
130
+ const vec4 v3 = vec4(1,1,0,1);
131
+ const float e4 = 0.875;
132
+ const vec4 v4 = vec4(0.9803921568627451,0,0,1);
133
+ const float e5 = 1.0;
134
+ const vec4 v5 = vec4(0.5019607843137255,0,0,1);
135
+ float a0 = smoothstep(e0,e1,x_8);
136
+ float a1 = smoothstep(e1,e2,x_8);
137
+ float a2 = smoothstep(e2,e3,x_8);
138
+ float a3 = smoothstep(e3,e4,x_8);
139
+ float a4 = smoothstep(e4,e5,x_8);
140
+ return max(mix(v0,v1,a0)*step(e0,x_8)*step(x_8,e1),
141
+ max(mix(v1,v2,a1)*step(e1,x_8)*step(x_8,e2),
142
+ max(mix(v2,v3,a2)*step(e2,x_8)*step(x_8,e3),
143
+ max(mix(v3,v4,a3)*step(e3,x_8)*step(x_8,e4),mix(v4,v5,a4)*step(e4,x_8)*step(x_8,e5)
144
+ ))));
145
+ }
146
+
147
+ vec4 bone (float x_11) {
148
+ const float e0 = 0.0;
149
+ const vec4 v0 = vec4(0,0,0,1);
150
+ const float e1 = 0.376;
151
+ const vec4 v1 = vec4(0.32941176470588235,0.32941176470588235,0.4549019607843137,1);
152
+ const float e2 = 0.753;
153
+ const vec4 v2 = vec4(0.6627450980392157,0.7843137254901961,0.7843137254901961,1);
154
+ const float e3 = 1.0;
155
+ const vec4 v3 = vec4(1,1,1,1);
156
+ float a0 = smoothstep(e0,e1,x_11);
157
+ float a1 = smoothstep(e1,e2,x_11);
158
+ float a2 = smoothstep(e2,e3,x_11);
159
+ return max(mix(v0,v1,a0)*step(e0,x_11)*step(x_11,e1),
160
+ max(mix(v1,v2,a1)*step(e1,x_11)*step(x_11,e2),mix(v2,v3,a2)*step(e2,x_11)*step(x_11,e3)
161
+ ));
162
+ }
163
+
164
+ vec4 copper (float x_6) {
165
+ const float e0 = 0.0;
166
+ const vec4 v0 = vec4(0,0,0,1);
167
+ const float e1 = 0.804;
168
+ const vec4 v1 = vec4(1,0.6274509803921569,0.4,1);
169
+ const float e2 = 1.0;
170
+ const vec4 v2 = vec4(1,0.7803921568627451,0.4980392156862745,1);
171
+ float a0 = smoothstep(e0,e1,x_6);
172
+ float a1 = smoothstep(e1,e2,x_6);
173
+ return max(mix(v0,v1,a0)*step(e0,x_6)*step(x_6,e1),mix(v1,v2,a1)*step(e1,x_6)*step(x_6,e2)
174
+ );
175
+ }
176
+
177
+ vec4 density (float x_5) {
178
+ const float e0 = 0.0;
179
+ const vec4 v0 = vec4(0.21176470588235294,0.054901960784313725,0.1411764705882353,1);
180
+ const float e1 = 0.13;
181
+ const vec4 v1 = vec4(0.34901960784313724,0.09019607843137255,0.3137254901960784,1);
182
+ const float e2 = 0.25;
183
+ const vec4 v2 = vec4(0.43137254901960786,0.17647058823529413,0.5176470588235295,1);
184
+ const float e3 = 0.38;
185
+ const vec4 v3 = vec4(0.47058823529411764,0.30196078431372547,0.6980392156862745,1);
186
+ const float e4 = 0.5;
187
+ const vec4 v4 = vec4(0.47058823529411764,0.44313725490196076,0.8352941176470589,1);
188
+ const float e5 = 0.63;
189
+ const vec4 v5 = vec4(0.45098039215686275,0.592156862745098,0.8941176470588236,1);
190
+ const float e6 = 0.75;
191
+ const vec4 v6 = vec4(0.5254901960784314,0.7254901960784313,0.8901960784313725,1);
192
+ const float e7 = 0.88;
193
+ const vec4 v7 = vec4(0.6941176470588235,0.8392156862745098,0.8901960784313725,1);
194
+ const float e8 = 1.0;
195
+ const vec4 v8 = vec4(0.9019607843137255,0.9450980392156862,0.9450980392156862,1);
196
+ float a0 = smoothstep(e0,e1,x_5);
197
+ float a1 = smoothstep(e1,e2,x_5);
198
+ float a2 = smoothstep(e2,e3,x_5);
199
+ float a3 = smoothstep(e3,e4,x_5);
200
+ float a4 = smoothstep(e4,e5,x_5);
201
+ float a5 = smoothstep(e5,e6,x_5);
202
+ float a6 = smoothstep(e6,e7,x_5);
203
+ float a7 = smoothstep(e7,e8,x_5);
204
+ return max(mix(v0,v1,a0)*step(e0,x_5)*step(x_5,e1),
205
+ max(mix(v1,v2,a1)*step(e1,x_5)*step(x_5,e2),
206
+ max(mix(v2,v3,a2)*step(e2,x_5)*step(x_5,e3),
207
+ max(mix(v3,v4,a3)*step(e3,x_5)*step(x_5,e4),
208
+ max(mix(v4,v5,a4)*step(e4,x_5)*step(x_5,e5),
209
+ max(mix(v5,v6,a5)*step(e5,x_5)*step(x_5,e6),
210
+ max(mix(v6,v7,a6)*step(e6,x_5)*step(x_5,e7),mix(v7,v8,a7)*step(e7,x_5)*step(x_5,e8)
211
+ )))))));
212
+ }
213
+
214
+ vec4 inferno (float x_3) {
215
+ const float e0 = 0.0;
216
+ const vec4 v0 = vec4(0,0,0.01568627450980392,1);
217
+ const float e1 = 0.13;
218
+ const vec4 v1 = vec4(0.12156862745098039,0.047058823529411764,0.2823529411764706,1);
219
+ const float e2 = 0.25;
220
+ const vec4 v2 = vec4(0.3333333333333333,0.058823529411764705,0.42745098039215684,1);
221
+ const float e3 = 0.38;
222
+ const vec4 v3 = vec4(0.5333333333333333,0.13333333333333333,0.41568627450980394,1);
223
+ const float e4 = 0.5;
224
+ const vec4 v4 = vec4(0.7294117647058823,0.21176470588235294,0.3333333333333333,1);
225
+ const float e5 = 0.63;
226
+ const vec4 v5 = vec4(0.8901960784313725,0.34901960784313724,0.2,1);
227
+ const float e6 = 0.75;
228
+ const vec4 v6 = vec4(0.9764705882352941,0.5490196078431373,0.0392156862745098,1);
229
+ const float e7 = 0.88;
230
+ const vec4 v7 = vec4(0.9764705882352941,0.788235294117647,0.19607843137254902,1);
231
+ const float e8 = 1.0;
232
+ const vec4 v8 = vec4(0.9882352941176471,1,0.6431372549019608,1);
233
+ float a0 = smoothstep(e0,e1,x_3);
234
+ float a1 = smoothstep(e1,e2,x_3);
235
+ float a2 = smoothstep(e2,e3,x_3);
236
+ float a3 = smoothstep(e3,e4,x_3);
237
+ float a4 = smoothstep(e4,e5,x_3);
238
+ float a5 = smoothstep(e5,e6,x_3);
239
+ float a6 = smoothstep(e6,e7,x_3);
240
+ float a7 = smoothstep(e7,e8,x_3);
241
+ return max(mix(v0,v1,a0)*step(e0,x_3)*step(x_3,e1),
242
+ max(mix(v1,v2,a1)*step(e1,x_3)*step(x_3,e2),
243
+ max(mix(v2,v3,a2)*step(e2,x_3)*step(x_3,e3),
244
+ max(mix(v3,v4,a3)*step(e3,x_3)*step(x_3,e4),
245
+ max(mix(v4,v5,a4)*step(e4,x_3)*step(x_3,e5),
246
+ max(mix(v5,v6,a5)*step(e5,x_3)*step(x_3,e6),
247
+ max(mix(v6,v7,a6)*step(e6,x_3)*step(x_3,e7),mix(v7,v8,a7)*step(e7,x_3)*step(x_3,e8)
248
+ )))))));
249
+ }
250
+
251
+ vec4 cool (float x_2) {
252
+ const float e0 = 0.0;
253
+ const vec4 v0 = vec4(0.49019607843137253,0,0.7019607843137254,1);
254
+ const float e1 = 0.13;
255
+ const vec4 v1 = vec4(0.4549019607843137,0,0.8549019607843137,1);
256
+ const float e2 = 0.25;
257
+ const vec4 v2 = vec4(0.3843137254901961,0.2901960784313726,0.9294117647058824,1);
258
+ const float e3 = 0.38;
259
+ const vec4 v3 = vec4(0.26666666666666666,0.5725490196078431,0.9058823529411765,1);
260
+ const float e4 = 0.5;
261
+ const vec4 v4 = vec4(0,0.8,0.7725490196078432,1);
262
+ const float e5 = 0.63;
263
+ const vec4 v5 = vec4(0,0.9686274509803922,0.5725490196078431,1);
264
+ const float e6 = 0.75;
265
+ const vec4 v6 = vec4(0,1,0.34509803921568627,1);
266
+ const float e7 = 0.88;
267
+ const vec4 v7 = vec4(0.1568627450980392,1,0.03137254901960784,1);
268
+ const float e8 = 1.0;
269
+ const vec4 v8 = vec4(0.5764705882352941,1,0,1);
270
+ float a0 = smoothstep(e0,e1,x_2);
271
+ float a1 = smoothstep(e1,e2,x_2);
272
+ float a2 = smoothstep(e2,e3,x_2);
273
+ float a3 = smoothstep(e3,e4,x_2);
274
+ float a4 = smoothstep(e4,e5,x_2);
275
+ float a5 = smoothstep(e5,e6,x_2);
276
+ float a6 = smoothstep(e6,e7,x_2);
277
+ float a7 = smoothstep(e7,e8,x_2);
278
+ return max(mix(v0,v1,a0)*step(e0,x_2)*step(x_2,e1),
279
+ max(mix(v1,v2,a1)*step(e1,x_2)*step(x_2,e2),
280
+ max(mix(v2,v3,a2)*step(e2,x_2)*step(x_2,e3),
281
+ max(mix(v3,v4,a3)*step(e3,x_2)*step(x_2,e4),
282
+ max(mix(v4,v5,a4)*step(e4,x_2)*step(x_2,e5),
283
+ max(mix(v5,v6,a5)*step(e5,x_2)*step(x_2,e6),
284
+ max(mix(v6,v7,a6)*step(e6,x_2)*step(x_2,e7),mix(v7,v8,a7)*step(e7,x_2)*step(x_2,e8)
285
+ )))))));
286
+ }
287
+
288
+ vec4 hot (float x_0) {
289
+ const float e0 = 0.0;
290
+ const vec4 v0 = vec4(0,0,0,1);
291
+ const float e1 = 0.3;
292
+ const vec4 v1 = vec4(0.9019607843137255,0,0,1);
293
+ const float e2 = 0.6;
294
+ const vec4 v2 = vec4(1,0.8235294117647058,0,1);
295
+ const float e3 = 1.0;
296
+ const vec4 v3 = vec4(1,1,1,1);
297
+ float a0 = smoothstep(e0,e1,x_0);
298
+ float a1 = smoothstep(e1,e2,x_0);
299
+ float a2 = smoothstep(e2,e3,x_0);
300
+ return max(mix(v0,v1,a0)*step(e0,x_0)*step(x_0,e1),
301
+ max(mix(v1,v2,a1)*step(e1,x_0)*step(x_0,e2),mix(v2,v3,a2)*step(e2,x_0)*step(x_0,e3)
302
+ ));
303
+ }
304
+
305
+ vec4 spring (float x_14) {
306
+ const float e0 = 0.0;
307
+ const vec4 v0 = vec4(1,0,1,1);
308
+ const float e1 = 1.0;
309
+ const vec4 v1 = vec4(1,1,0,1);
310
+ float a0 = smoothstep(e0,e1,x_14);
311
+ return mix(v0,v1,a0)*step(e0,x_14)*step(x_14,e1);
312
+ }
313
+
314
+ vec4 summer (float x_9) {
315
+ const float e0 = 0.0;
316
+ const vec4 v0 = vec4(0,0.5019607843137255,0.4,1);
317
+ const float e1 = 1.0;
318
+ const vec4 v1 = vec4(1,1,0.4,1);
319
+ float a0 = smoothstep(e0,e1,x_9);
320
+ return mix(v0,v1,a0)*step(e0,x_9)*step(x_9,e1);
321
+ }
322
+
323
+ vec4 autumn (float x_13) {
324
+ const float e0 = 0.0;
325
+ const vec4 v0 = vec4(1,0,0,1);
326
+ const float e1 = 1.0;
327
+ const vec4 v1 = vec4(1,1,0,1);
328
+ float a0 = smoothstep(e0,e1,x_13);
329
+ return mix(v0,v1,a0)*step(e0,x_13)*step(x_13,e1);
330
+ }
331
+
332
+ vec4 winter (float x_12) {
333
+ const float e0 = 0.0;
334
+ const vec4 v0 = vec4(0,0,1,1);
335
+ const float e1 = 1.0;
336
+ const vec4 v1 = vec4(0,1,0.5019607843137255,1);
337
+ float a0 = smoothstep(e0,e1,x_12);
338
+ return mix(v0,v1,a0)*step(e0,x_12)*step(x_12,e1);
339
+ }
340
+ `;
@@ -0,0 +1,109 @@
1
+ import { colormaps } from './glsl';
2
+ /**
3
+ * No change to the vertex shader from the base BitmapLayer.
4
+ * Reference: https://github.com/visgl/deck.gl/blob/8.2-release/modules/layers/src/bitmap-layer/bitmap-layer-vertex.js
5
+ */
6
+ export const vertexShader = `
7
+ #define SHADER_NAME heatmap-bitmap-layer-vertex-shader
8
+
9
+ attribute vec2 texCoords;
10
+ attribute vec3 positions;
11
+ attribute vec3 positions64Low;
12
+
13
+ varying vec2 vTexCoord;
14
+
15
+ const vec3 pickingColor = vec3(1.0, 0.0, 0.0);
16
+
17
+ void main(void) {
18
+ geometry.worldPosition = positions;
19
+ geometry.uv = texCoords;
20
+ geometry.pickingColor = pickingColor;
21
+
22
+ gl_Position = project_position_to_clipspace(positions, positions64Low, vec3(0.0), geometry.position);
23
+ DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
24
+
25
+ vTexCoord = texCoords;
26
+
27
+ vec4 color = vec4(0.0);
28
+ DECKGL_FILTER_COLOR(color, geometry);
29
+ }
30
+ `;
31
+ /**
32
+ * Fragment shader adapted to perform aggregation and
33
+ * take color scale functions + sliders into account.
34
+ * Reference: https://github.com/visgl/deck.gl/blob/8.2-release/modules/layers/src/bitmap-layer/bitmap-layer-fragment.js
35
+ * Reference: https://github.com/hms-dbmi/viv/blob/06231ae02cac1ff57ba458c71e9bc59ed2fc4f8b/src/layers/XRLayer/xr-layer-fragment-colormap.webgl1.glsl
36
+ */
37
+ export const fragmentShader = `
38
+ #define SHADER_NAME heatmap-bitmap-layer-fragment-shader
39
+
40
+ #ifdef GL_ES
41
+ precision mediump float;
42
+ #endif
43
+
44
+ ${colormaps}
45
+
46
+ // The texture (GL.LUMINANCE & Uint8Array).
47
+ uniform sampler2D uBitmapTexture;
48
+
49
+ // What are the dimensions of the texture (width, height)?
50
+ uniform vec2 uTextureSize;
51
+
52
+ // How many consecutive pixels should be aggregated together along each axis?
53
+ uniform vec2 uAggSize;
54
+
55
+ // What are the values of the color scale sliders?
56
+ uniform vec2 uColorScaleRange;
57
+
58
+ // The texture coordinate, varying (interpolated between values set by the vertex shader).
59
+ varying vec2 vTexCoord;
60
+
61
+ void main(void) {
62
+ // Compute 1 pixel in texture coordinates
63
+ vec2 onePixel = vec2(1.0, 1.0) / uTextureSize;
64
+
65
+ vec2 viewCoord = vec2(floor(vTexCoord.x * uTextureSize.x), floor(vTexCoord.y * uTextureSize.y));
66
+
67
+ // Compute (x % aggSizeX, y % aggSizeY).
68
+ // These values will be the number of values to the left / above the current position to consider.
69
+ vec2 modAggSize = vec2(-1.0 * mod(viewCoord.x, uAggSize.x), -1.0 * mod(viewCoord.y, uAggSize.y));
70
+
71
+ // Take the sum of values along each axis.
72
+ float intensitySum = 0.0;
73
+ vec2 offsetPixels = vec2(0.0, 0.0);
74
+
75
+ for(int i = 0; i < 16; i++) {
76
+ // Check to break outer loop early.
77
+ // Uniforms cannot be used as conditions in GLSL for loops.
78
+ if(float(i) >= uAggSize.y) {
79
+ // Done in the y direction.
80
+ break;
81
+ }
82
+
83
+ offsetPixels = vec2(offsetPixels.x, (modAggSize.y + float(i)) * onePixel.y);
84
+
85
+ for(int j = 0; j < 16; j++) {
86
+ // Check to break inner loop early.
87
+ // Uniforms cannot be used as conditions in GLSL for loops.
88
+ if(float(j) >= uAggSize.x) {
89
+ // Done in the x direction.
90
+ break;
91
+ }
92
+
93
+ offsetPixels = vec2((modAggSize.x + float(j)) * onePixel.x, offsetPixels.y);
94
+ intensitySum += texture2D(uBitmapTexture, vTexCoord + offsetPixels).r;
95
+ }
96
+ }
97
+
98
+ // Compute the mean value.
99
+ float intensityMean = intensitySum / (uAggSize.x * uAggSize.y);
100
+
101
+ // Re-scale using the color scale slider values.
102
+ float scaledIntensityMean = (intensityMean - uColorScaleRange[0]) / max(0.005, (uColorScaleRange[1] - uColorScaleRange[0]));
103
+
104
+ gl_FragColor = COLORMAP_FUNC(clamp(scaledIntensityMean, 0.0, 1.0));
105
+
106
+ geometry.uv = vTexCoord;
107
+ DECKGL_FILTER_COLOR(gl_FragColor, geometry);
108
+ }
109
+ `;
@@ -0,0 +1,27 @@
1
+ import GL from '@luma.gl/constants'; // eslint-disable-line import/no-extraneous-dependencies
2
+ // Image texture dimensions
3
+ export const TILE_SIZE = 4096;
4
+ // Reshaped data texture dimensions
5
+ export const DATA_TEXTURE_SIZE = 4096;
6
+ export const MIN_ROW_AGG = 1;
7
+ export const MAX_ROW_AGG = 16;
8
+ export const COLOR_BAR_SIZE = 20;
9
+ export const AXIS_LABEL_TEXT_SIZE = 11;
10
+ export const AXIS_TITLE_TEXT_SIZE = 15;
11
+ export const AXIS_MIN_SIZE = 12;
12
+ export const AXIS_MAX_SIZE = 120;
13
+ export const AXIS_MARGIN = 3;
14
+ export const AXIS_PADDING = 10;
15
+ export const THEME_TO_TEXT_COLOR = {
16
+ dark: [224, 224, 224],
17
+ light: [64, 64, 64],
18
+ };
19
+ export const AXIS_FONT_FAMILY = "-apple-system, 'Helvetica Neue', Arial, sans-serif";
20
+ export const PIXELATED_TEXTURE_PARAMETERS = {
21
+ // NEAREST for integer data to prevent interpolation.
22
+ [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
23
+ [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
24
+ // CLAMP_TO_EDGE to remove tile artifacts.
25
+ [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
26
+ [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
27
+ };
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ // Selection Layers
2
+ export { getSelectionLayers } from './selection-utils';
3
+ // Heatmap Layers
4
+ export { default as HeatmapBitmapLayer } from './HeatmapBitmapLayer';
5
+ export { default as PixelatedBitmapLayer } from './PixelatedBitmapLayer';
6
+ export { default as HeatmapCompositeTextLayer } from './HeatmapCompositeTextLayer';
7
+ export { default as PaddedExpressionHeatmapBitmapLayer } from './PaddedExpressionHeatmapBitmapLayer';
8
+ export { GLSL_COLORMAPS, GLSL_COLORMAP_DEFAULT, DEFAULT_GL_OPTIONS, SELECTION_TYPE, } from './constants';
9
+ // Layer extensions
10
+ export { default as ScaledExpressionExtension } from './ScaledExpressionExtension';
11
+ export { default as SelectionExtension } from './SelectionExtension';
12
+ export { default as BitmaskLayer } from './BitmaskLayer';
13
+ export { TILE_SIZE, MAX_ROW_AGG, MIN_ROW_AGG, COLOR_BAR_SIZE, AXIS_MARGIN, DATA_TEXTURE_SIZE, PIXELATED_TEXTURE_PARAMETERS, AXIS_LABEL_TEXT_SIZE, AXIS_FONT_FAMILY, AXIS_PADDING, AXIS_MIN_SIZE, AXIS_MAX_SIZE, } from './heatmap-constants';
14
+ export * as viv from './viv';
15
+ export * as luma from './luma';
16
+ export * as deck from './deck';
17
+ export { GLOBAL_LABELS, DEFAULT_CELLS_LAYER, DEFAULT_MOLECULES_LAYER, DEFAULT_NEIGHBORHOODS_LAYER, DEFAULT_RASTER_DOMAIN_TYPE, DEFAULT_RASTER_LAYER_PROPS, DEFAULT_LAYER_TYPE_ORDERING, square, initializeLayerChannels, initializeRasterLayersAndChannels, getSourceFromLoader, isRgb, } from './spatial';
@@ -0,0 +1,109 @@
1
+ import { Matrix4 } from 'math.gl';
2
+ import { getChannelStats } from './viv';
3
+ async function getSingleSelectionStats2D({ loader, selection }) {
4
+ const data = Array.isArray(loader) ? loader[loader.length - 1] : loader;
5
+ const raster = await data.getRaster({ selection });
6
+ const selectionStats = getChannelStats(raster.data);
7
+ const { domain, contrastLimits: slider } = selectionStats;
8
+ return { domain, slider };
9
+ }
10
+ async function getSingleSelectionStats3D({ loader, selection }) {
11
+ const lowResSource = loader[loader.length - 1];
12
+ const { shape, labels } = lowResSource;
13
+ // eslint-disable-next-line no-bitwise
14
+ const sizeZ = shape[labels.indexOf('z')] >> (loader.length - 1);
15
+ const raster0 = await lowResSource.getRaster({
16
+ selection: { ...selection, z: 0 },
17
+ });
18
+ const rasterMid = await lowResSource.getRaster({
19
+ selection: { ...selection, z: Math.floor(sizeZ / 2) },
20
+ });
21
+ const rasterTop = await lowResSource.getRaster({
22
+ selection: { ...selection, z: Math.max(0, sizeZ - 1) },
23
+ });
24
+ const stats0 = getChannelStats(raster0.data);
25
+ const statsMid = getChannelStats(rasterMid.data);
26
+ const statsTop = getChannelStats(rasterTop.data);
27
+ return {
28
+ domain: [
29
+ Math.min(stats0.domain[0], statsMid.domain[0], statsTop.domain[0]),
30
+ Math.max(stats0.domain[1], statsMid.domain[1], statsTop.domain[1]),
31
+ ],
32
+ slider: [
33
+ Math.min(stats0.contrastLimits[0], statsMid.contrastLimits[0], statsTop.contrastLimits[0]),
34
+ Math.max(stats0.contrastLimits[1], statsMid.contrastLimits[1], statsTop.contrastLimits[1]),
35
+ ],
36
+ };
37
+ }
38
+ /**
39
+ * Get bounding cube for a given loader i.e [[0, width], [0, height], [0, depth]]
40
+ * @param {Object} loader PixelSource|PixelSource[]
41
+ * @param {[]} selection Selection for stats.
42
+ * @param {boolean} use3d Whether or not to get 3d stats.
43
+ * @returns {Object} { domains, sliders }
44
+ */
45
+ export const getSingleSelectionStats = async ({ loader, selection, use3d }) => {
46
+ const getStats = use3d
47
+ ? getSingleSelectionStats3D
48
+ : getSingleSelectionStats2D;
49
+ return getStats({ loader, selection });
50
+ };
51
+ export const getMultiSelectionStats = async ({ loader, selections, use3d }) => {
52
+ const stats = await Promise.all(selections.map(selection => getSingleSelectionStats({ loader, selection, use3d })));
53
+ const domains = stats.map(stat => stat.domain);
54
+ const sliders = stats.map(stat => stat.slider);
55
+ return { domains, sliders };
56
+ };
57
+ /**
58
+ * Get physical size scaling Matrix4
59
+ * @param {Object} loader PixelSource
60
+ * @returns {Object} matrix
61
+ */
62
+ export function getPhysicalSizeScalingMatrix(loader) {
63
+ const { x, y, z } = loader?.meta?.physicalSizes ?? {};
64
+ if (x?.size && y?.size && z?.size) {
65
+ const min = Math.min(z.size, x.size, y.size);
66
+ const ratio = [x.size / min, y.size / min, z.size / min];
67
+ return new Matrix4().scale(ratio);
68
+ }
69
+ return new Matrix4().identity();
70
+ }
71
+ /**
72
+ * Get bounding cube for a given loader
73
+ * @param {Object} loader PixelSource|PixelSource[]
74
+ * @returns {Array} [0, width], [0, height], [0, depth]]
75
+ */
76
+ export function getBoundingCube(loader) {
77
+ const source = Array.isArray(loader) ? loader[0] : loader;
78
+ const { shape, labels } = source;
79
+ const physicalSizeScalingMatrix = getPhysicalSizeScalingMatrix(source);
80
+ const xSlice = [0, physicalSizeScalingMatrix[0] * shape[labels.indexOf('x')]];
81
+ const ySlice = [0, physicalSizeScalingMatrix[5] * shape[labels.indexOf('y')]];
82
+ const zSlice = [
83
+ 0,
84
+ physicalSizeScalingMatrix[10] * shape[labels.indexOf('z')],
85
+ ];
86
+ return [xSlice, ySlice, zSlice];
87
+ }
88
+ export function abbreviateNumber(value) {
89
+ // Return an abbreviated representation of value, in 5 characters or less.
90
+ const maxLength = 5;
91
+ let maxNaiveDigits = maxLength;
92
+ /* eslint-disable no-plusplus */
93
+ if (!Number.isInteger(value)) {
94
+ --maxNaiveDigits;
95
+ } // Wasted on "."
96
+ if (value < 1) {
97
+ --maxNaiveDigits;
98
+ } // Wasted on "0."
99
+ /* eslint-disable no-plusplus */
100
+ const naive = Intl.NumberFormat('en-US', {
101
+ maximumSignificantDigits: maxNaiveDigits,
102
+ useGrouping: false,
103
+ }).format(value);
104
+ if (naive.length <= maxLength)
105
+ return naive;
106
+ // "e+9" consumes 3 characters, so if we even had two significant digits,
107
+ // it would take take us to six characters, including the decimal point.
108
+ return value.toExponential(0);
109
+ }
package/dist/luma.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as GL } from '@luma.gl/constants';
2
+ export { Texture2D } from '@luma.gl/core';