@vitessce/config 3.0.0 → 3.1.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/index.js +589 -83
- package/dist-tsc/VitessceAutoConfig.d.ts +13 -1
- package/dist-tsc/VitessceAutoConfig.d.ts.map +1 -1
- package/dist-tsc/VitessceAutoConfig.js +318 -87
- package/dist-tsc/VitessceAutoConfig.test.js +599 -71
- package/dist-tsc/VitessceConfig.d.ts +46 -0
- package/dist-tsc/VitessceConfig.d.ts.map +1 -1
- package/dist-tsc/VitessceConfig.js +353 -0
- package/dist-tsc/VitessceConfig.test.js +329 -1
- package/dist-tsc/constants.d.ts +247 -0
- package/dist-tsc/constants.d.ts.map +1 -0
- package/dist-tsc/constants.js +87 -0
- package/dist-tsc/index.d.ts +2 -1
- package/dist-tsc/index.js +2 -1
- package/package.json +4 -4
- package/src/VitessceAutoConfig.js +368 -99
- package/src/VitessceAutoConfig.test.js +626 -76
- package/src/VitessceConfig.js +393 -0
- package/src/VitessceConfig.test.js +339 -0
- package/src/constants.js +94 -0
- package/src/index.js +2 -1
|
@@ -12,6 +12,7 @@ export function hconcat(...views: (VitessceConfigView | VitessceConfigViewHConca
|
|
|
12
12
|
* @returns {VitessceConfigViewVConcat} A new vertical view concatenation instance.
|
|
13
13
|
*/
|
|
14
14
|
export function vconcat(...views: (VitessceConfigView | VitessceConfigViewHConcat | VitessceConfigViewVConcat)[]): VitessceConfigViewVConcat;
|
|
15
|
+
export function CL(value: any): CoordinationLevel;
|
|
15
16
|
/**
|
|
16
17
|
* Class representing a file within a Vitessce config dataset.
|
|
17
18
|
*/
|
|
@@ -94,6 +95,7 @@ export class VitessceConfigView {
|
|
|
94
95
|
view: {
|
|
95
96
|
component: string;
|
|
96
97
|
coordinationScopes: object;
|
|
98
|
+
coordinationScopesBy: undefined;
|
|
97
99
|
x: number;
|
|
98
100
|
y: number;
|
|
99
101
|
w: number;
|
|
@@ -106,6 +108,13 @@ export class VitessceConfigView {
|
|
|
106
108
|
* @returns {VitessceConfigView} This, to allow chaining.
|
|
107
109
|
*/
|
|
108
110
|
useCoordination(...args: VitessceConfigCoordinationScope[]): VitessceConfigView;
|
|
111
|
+
useComplexCoordination(scopes: any): VitessceConfigView;
|
|
112
|
+
/**
|
|
113
|
+
* Attach meta coordination scopes to this view.
|
|
114
|
+
* @param {VitessceConfigMetaCoordinationScope} metaScope A meta coordination scope instance.
|
|
115
|
+
* @returns {VitessceConfigView} This, to allow chaining.
|
|
116
|
+
*/
|
|
117
|
+
useMetaCoordination(metaScope: VitessceConfigMetaCoordinationScope): VitessceConfigView;
|
|
109
118
|
/**
|
|
110
119
|
* Set the x, y, w, h values for this view.
|
|
111
120
|
* @param {number} x The x-coordinate of the view in the layout.
|
|
@@ -159,6 +168,36 @@ export class VitessceConfigCoordinationScope {
|
|
|
159
168
|
*/
|
|
160
169
|
setValue(cValue: any): VitessceConfigCoordinationScope;
|
|
161
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Class representing a pair of coordination scopes,
|
|
173
|
+
* for metaCoordinationScopes and metaCoordinationScopesBy,
|
|
174
|
+
* respectively, in the coordination space.
|
|
175
|
+
*/
|
|
176
|
+
export class VitessceConfigMetaCoordinationScope {
|
|
177
|
+
/**
|
|
178
|
+
* Construct a new coordination scope instance.
|
|
179
|
+
* @param {string} metaScope The name of the coordination scope for metaCoordinationScopes.
|
|
180
|
+
* @param {string} metaByScope The name of the coordination scope for metaCoordinationScopesBy.
|
|
181
|
+
*/
|
|
182
|
+
constructor(metaScope: string, metaByScope: string);
|
|
183
|
+
metaScope: VitessceConfigCoordinationScope;
|
|
184
|
+
metaByScope: VitessceConfigCoordinationScope;
|
|
185
|
+
/**
|
|
186
|
+
* Attach coordination scopes to this meta scope.
|
|
187
|
+
* @param {...VitessceConfigCoordinationScope} args A variable number of
|
|
188
|
+
* coordination scope instances.
|
|
189
|
+
* @returns {VitessceConfigMetaCoordinationScope} This, to allow chaining.
|
|
190
|
+
*/
|
|
191
|
+
useCoordination(...args: VitessceConfigCoordinationScope[]): VitessceConfigMetaCoordinationScope;
|
|
192
|
+
useComplexCoordination(scopes: any): VitessceConfigMetaCoordinationScope;
|
|
193
|
+
/**
|
|
194
|
+
* Set the coordination value of the coordination scope.
|
|
195
|
+
* @param {any} cValue The value to set.
|
|
196
|
+
* @returns {VitessceConfigCoordinationScope} This, to allow chaining.
|
|
197
|
+
*/
|
|
198
|
+
setValue(cValue: any): VitessceConfigCoordinationScope;
|
|
199
|
+
cValue: any;
|
|
200
|
+
}
|
|
162
201
|
/**
|
|
163
202
|
* Class representing a Vitessce view config.
|
|
164
203
|
*/
|
|
@@ -232,6 +271,8 @@ export class VitessceConfig {
|
|
|
232
271
|
* @returns {VitessceConfigCoordinationScope[]} An array of coordination scope instances.
|
|
233
272
|
*/
|
|
234
273
|
addCoordination(...args: string[]): VitessceConfigCoordinationScope[];
|
|
274
|
+
addMetaCoordination(): VitessceConfigMetaCoordinationScope;
|
|
275
|
+
addComplexCoordination(input: any): {};
|
|
235
276
|
/**
|
|
236
277
|
* A convenience function for setting up new coordination scopes across a set of views.
|
|
237
278
|
* @param {VitessceConfigView[]} views An array of view objects to link together.
|
|
@@ -254,4 +295,9 @@ export class VitessceConfig {
|
|
|
254
295
|
*/
|
|
255
296
|
toJSON(): object;
|
|
256
297
|
}
|
|
298
|
+
declare class CoordinationLevel {
|
|
299
|
+
constructor(value: any);
|
|
300
|
+
value: any;
|
|
301
|
+
}
|
|
302
|
+
export {};
|
|
257
303
|
//# sourceMappingURL=VitessceConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitessceConfig.d.ts","sourceRoot":"","sources":["../src/VitessceConfig.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VitessceConfig.d.ts","sourceRoot":"","sources":["../src/VitessceConfig.js"],"names":[],"mappings":"AAoXA;;;;;GAKG;AACH,kCAJe,CAAC,kBAAkB,GAAC,yBAAyB,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 -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
1
2
|
import { CoordinationType } from '@vitessce/constants-internal';
|
|
2
3
|
import { fromEntries, getNextScope } from '@vitessce/utils';
|
|
3
4
|
/**
|
|
@@ -96,6 +97,131 @@ export class VitessceConfigDataset {
|
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
function useComplexCoordinationHelper(scopes, coordinationScopes, coordinationScopesBy) {
|
|
101
|
+
// Set this.coordinationScopes and this.coordinationScopesBy by recursion on `scopes`.
|
|
102
|
+
/*
|
|
103
|
+
// Destructured, `scopes` might look like:
|
|
104
|
+
const {
|
|
105
|
+
[CoordinationType.SPATIAL_IMAGE_LAYER]: [
|
|
106
|
+
{
|
|
107
|
+
scope: imageLayerScope,
|
|
108
|
+
children: {
|
|
109
|
+
[CoordinationType.IMAGE]: { scope: imageScope },
|
|
110
|
+
[CoordinationType.SPATIAL_LAYER_VISIBLE]: { scope: imageVisibleScope },
|
|
111
|
+
[CoordinationType.SPATIAL_LAYER_OPACITY]: { scope: imageOpacityScope },
|
|
112
|
+
[CoordinationType.SPATIAL_IMAGE_CHANNEL]: [
|
|
113
|
+
{
|
|
114
|
+
scope: imageChannelScopeR,
|
|
115
|
+
children: {
|
|
116
|
+
[CoordinationType.SPATIAL_TARGET_C]: { scope: rTargetScope },
|
|
117
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: { scope: rColorScope },
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
scope: imageChannelScopeG,
|
|
122
|
+
children: {
|
|
123
|
+
[CoordinationType.SPATIAL_TARGET_C]: { scope: gTargetScope },
|
|
124
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: { scope: gColorScope },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
// ...
|
|
132
|
+
} = scopes;
|
|
133
|
+
|
|
134
|
+
// This would set the values to:
|
|
135
|
+
this.coordinationScopes = {
|
|
136
|
+
// Add the top-level coordination types to `coordinationScopes`.
|
|
137
|
+
[CoordinationType.SPATIAL_IMAGE_LAYER]: [imageLayerScope.cScope],
|
|
138
|
+
};
|
|
139
|
+
this.coordinationScopesBy = {
|
|
140
|
+
[CoordinationType.SPATIAL_IMAGE_LAYER]: {
|
|
141
|
+
[CoordinationType.IMAGE]: {
|
|
142
|
+
[imageLayerScope.cScope]: imageScope.cScope,
|
|
143
|
+
},
|
|
144
|
+
[CoordinationType.SPATIAL_LAYER_VISIBLE]: {
|
|
145
|
+
[imageLayerScope.cScope]: imageVisibleScope.cScope,
|
|
146
|
+
},
|
|
147
|
+
[CoordinationType.SPATIAL_LAYER_OPACITY]: {
|
|
148
|
+
[imageLayerScope.cScope]: imageOpacityScope.cScope,
|
|
149
|
+
},
|
|
150
|
+
[CoordinationType.SPATIAL_IMAGE_CHANNEL]: {
|
|
151
|
+
[imageLayerScope.cScope]: [imageChannelScopeR.cScope, imageChannelScopeG.cScope],
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
[CoordinationType.SPATIAL_IMAGE_CHANNEL]: {
|
|
155
|
+
[CoordinationType.SPATIAL_TARGET_C]: {
|
|
156
|
+
[imageChannelScopeR.cScope]: rTargetScope.cScope,
|
|
157
|
+
[imageChannelScopeG.cScope]: gTargetScope.cScope,
|
|
158
|
+
},
|
|
159
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: {
|
|
160
|
+
[imageChannelScopeR.cScope]: rColorScope.cScope,
|
|
161
|
+
[imageChannelScopeG.cScope]: gColorScope.cScope,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
*/
|
|
166
|
+
// Recursive inner function.
|
|
167
|
+
function processLevel(parentType, parentScope, levelType, levelVal) {
|
|
168
|
+
if (Array.isArray(levelVal)) {
|
|
169
|
+
// eslint-disable-next-line no-param-reassign
|
|
170
|
+
coordinationScopesBy[parentType] = {
|
|
171
|
+
...(coordinationScopesBy[parentType] || {}),
|
|
172
|
+
[levelType]: {
|
|
173
|
+
...(coordinationScopesBy[parentType]?.[levelType] || {}),
|
|
174
|
+
[parentScope.cScope]: levelVal.map(childVal => childVal.scope.cScope),
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
levelVal.forEach((childVal) => {
|
|
178
|
+
if (childVal.children) {
|
|
179
|
+
// Continue recursion.
|
|
180
|
+
Object.entries(childVal.children)
|
|
181
|
+
.forEach(([nextLevelType, nextLevelVal]) => processLevel(levelType, childVal.scope, nextLevelType, nextLevelVal));
|
|
182
|
+
} // Else is the base case: no children
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// eslint-disable-next-line no-param-reassign
|
|
187
|
+
coordinationScopesBy[parentType] = {
|
|
188
|
+
...(coordinationScopesBy[parentType] || {}),
|
|
189
|
+
[levelType]: {
|
|
190
|
+
...(coordinationScopesBy[parentType]?.[levelType] || {}),
|
|
191
|
+
[parentScope.cScope]: levelVal.scope.cScope,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
if (levelVal.children) {
|
|
195
|
+
// Continue recursion.
|
|
196
|
+
Object.entries(levelVal.children)
|
|
197
|
+
.forEach(([nextLevelType, nextLevelVal]) => processLevel(levelType, levelVal.scope, nextLevelType, nextLevelVal));
|
|
198
|
+
} // Else is the base case: no children
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
Object.entries(scopes).forEach(([topLevelType, topLevelVal]) => {
|
|
202
|
+
if (Array.isArray(topLevelVal)) {
|
|
203
|
+
// eslint-disable-next-line no-param-reassign
|
|
204
|
+
coordinationScopes[topLevelType] = topLevelVal.map(levelVal => levelVal.scope.cScope);
|
|
205
|
+
topLevelVal.forEach((levelVal) => {
|
|
206
|
+
if (levelVal.children) {
|
|
207
|
+
// Begin recursion.
|
|
208
|
+
Object.entries(levelVal.children)
|
|
209
|
+
.forEach(([nextLevelType, nextLevelVal]) => processLevel(topLevelType, levelVal.scope, nextLevelType, nextLevelVal));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
// eslint-disable-next-line no-param-reassign
|
|
215
|
+
coordinationScopes[topLevelType] = topLevelVal.scope.cScope;
|
|
216
|
+
if (topLevelVal.children) {
|
|
217
|
+
// Begin recursion.
|
|
218
|
+
Object.entries(topLevelVal.children)
|
|
219
|
+
.forEach(([nextLevelType, nextLevelVal]) => processLevel(topLevelType, topLevelVal.scope, nextLevelType, nextLevelVal));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return [coordinationScopes, coordinationScopesBy];
|
|
224
|
+
}
|
|
99
225
|
/**
|
|
100
226
|
* Class representing a view within a Vitessce layout.
|
|
101
227
|
*/
|
|
@@ -114,6 +240,7 @@ export class VitessceConfigView {
|
|
|
114
240
|
this.view = {
|
|
115
241
|
component,
|
|
116
242
|
coordinationScopes,
|
|
243
|
+
coordinationScopesBy: undefined,
|
|
117
244
|
x,
|
|
118
245
|
y,
|
|
119
246
|
w,
|
|
@@ -133,6 +260,37 @@ export class VitessceConfigView {
|
|
|
133
260
|
});
|
|
134
261
|
return this;
|
|
135
262
|
}
|
|
263
|
+
useComplexCoordination(scopes) {
|
|
264
|
+
if (!this.view.coordinationScopes) {
|
|
265
|
+
this.view.coordinationScopes = {};
|
|
266
|
+
}
|
|
267
|
+
if (!this.view.coordinationScopesBy) {
|
|
268
|
+
this.view.coordinationScopesBy = {};
|
|
269
|
+
}
|
|
270
|
+
const [nextCoordinationScopes, nextCoordinationScopesBy] = useComplexCoordinationHelper(scopes, this.view.coordinationScopes, this.view.coordinationScopesBy);
|
|
271
|
+
this.view.coordinationScopes = nextCoordinationScopes;
|
|
272
|
+
this.view.coordinationScopesBy = nextCoordinationScopesBy;
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Attach meta coordination scopes to this view.
|
|
277
|
+
* @param {VitessceConfigMetaCoordinationScope} metaScope A meta coordination scope instance.
|
|
278
|
+
* @returns {VitessceConfigView} This, to allow chaining.
|
|
279
|
+
*/
|
|
280
|
+
useMetaCoordination(metaScope) {
|
|
281
|
+
if (!this.view.coordinationScopes) {
|
|
282
|
+
this.view.coordinationScopes = {};
|
|
283
|
+
}
|
|
284
|
+
this.view.coordinationScopes[CoordinationType.META_COORDINATION_SCOPES] = [
|
|
285
|
+
...(this.view.coordinationScopes[CoordinationType.META_COORDINATION_SCOPES] || []),
|
|
286
|
+
metaScope.metaScope.cScope,
|
|
287
|
+
];
|
|
288
|
+
this.view.coordinationScopes[CoordinationType.META_COORDINATION_SCOPES_BY] = [
|
|
289
|
+
...(this.view.coordinationScopes[CoordinationType.META_COORDINATION_SCOPES_BY] || []),
|
|
290
|
+
metaScope.metaByScope.cScope,
|
|
291
|
+
];
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
136
294
|
/**
|
|
137
295
|
* Set the x, y, w, h values for this view.
|
|
138
296
|
* @param {number} x The x-coordinate of the view in the layout.
|
|
@@ -202,6 +360,15 @@ export function vconcat(...views) {
|
|
|
202
360
|
const vcvvc = new VitessceConfigViewVConcat(views);
|
|
203
361
|
return vcvvc;
|
|
204
362
|
}
|
|
363
|
+
// would import as CL for convenience
|
|
364
|
+
class CoordinationLevel {
|
|
365
|
+
constructor(value) {
|
|
366
|
+
this.value = value;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
export function CL(value) {
|
|
370
|
+
return new CoordinationLevel(value);
|
|
371
|
+
}
|
|
205
372
|
/**
|
|
206
373
|
* Class representing a coordination scope in the coordination space.
|
|
207
374
|
*/
|
|
@@ -226,6 +393,58 @@ export class VitessceConfigCoordinationScope {
|
|
|
226
393
|
return this;
|
|
227
394
|
}
|
|
228
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Class representing a pair of coordination scopes,
|
|
398
|
+
* for metaCoordinationScopes and metaCoordinationScopesBy,
|
|
399
|
+
* respectively, in the coordination space.
|
|
400
|
+
*/
|
|
401
|
+
export class VitessceConfigMetaCoordinationScope {
|
|
402
|
+
/**
|
|
403
|
+
* Construct a new coordination scope instance.
|
|
404
|
+
* @param {string} metaScope The name of the coordination scope for metaCoordinationScopes.
|
|
405
|
+
* @param {string} metaByScope The name of the coordination scope for metaCoordinationScopesBy.
|
|
406
|
+
*/
|
|
407
|
+
constructor(metaScope, metaByScope) {
|
|
408
|
+
this.metaScope = new VitessceConfigCoordinationScope(CoordinationType.META_COORDINATION_SCOPES, metaScope);
|
|
409
|
+
this.metaByScope = new VitessceConfigCoordinationScope(CoordinationType.META_COORDINATION_SCOPES_BY, metaByScope);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Attach coordination scopes to this meta scope.
|
|
413
|
+
* @param {...VitessceConfigCoordinationScope} args A variable number of
|
|
414
|
+
* coordination scope instances.
|
|
415
|
+
* @returns {VitessceConfigMetaCoordinationScope} This, to allow chaining.
|
|
416
|
+
*/
|
|
417
|
+
useCoordination(...args) {
|
|
418
|
+
const cScopes = args;
|
|
419
|
+
const metaScopesVal = this.metaScope.cValue;
|
|
420
|
+
cScopes.forEach((cScope) => {
|
|
421
|
+
metaScopesVal[cScope.cType] = cScope.cScope;
|
|
422
|
+
});
|
|
423
|
+
this.metaScope.setValue(metaScopesVal);
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
useComplexCoordination(scopes) {
|
|
427
|
+
if (!this.metaScope.cValue) {
|
|
428
|
+
this.metaScope.setValue({});
|
|
429
|
+
}
|
|
430
|
+
if (!this.metaByScope.cValue) {
|
|
431
|
+
this.metaByScope.setValue({});
|
|
432
|
+
}
|
|
433
|
+
const [metaScopesVal, metaByScopesVal] = useComplexCoordinationHelper(scopes, this.metaScope.cValue, this.metaByScope.cValue);
|
|
434
|
+
this.metaScope.setValue(metaScopesVal);
|
|
435
|
+
this.metaByScope.setValue(metaByScopesVal);
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Set the coordination value of the coordination scope.
|
|
440
|
+
* @param {any} cValue The value to set.
|
|
441
|
+
* @returns {VitessceConfigCoordinationScope} This, to allow chaining.
|
|
442
|
+
*/
|
|
443
|
+
setValue(cValue) {
|
|
444
|
+
this.cValue = cValue;
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
229
448
|
/**
|
|
230
449
|
* Class representing a Vitessce view config.
|
|
231
450
|
*/
|
|
@@ -356,6 +575,140 @@ export class VitessceConfig {
|
|
|
356
575
|
});
|
|
357
576
|
return result;
|
|
358
577
|
}
|
|
578
|
+
addMetaCoordination() {
|
|
579
|
+
const prevMetaScopes = (this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES]
|
|
580
|
+
? Object.keys(this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES])
|
|
581
|
+
: []);
|
|
582
|
+
const prevMetaByScopes = (this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES_BY]
|
|
583
|
+
? Object.keys(this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES_BY])
|
|
584
|
+
: []);
|
|
585
|
+
const metaContainer = new VitessceConfigMetaCoordinationScope(getNextScope(prevMetaScopes), getNextScope(prevMetaByScopes));
|
|
586
|
+
if (!this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES]) {
|
|
587
|
+
this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES] = {};
|
|
588
|
+
}
|
|
589
|
+
if (!this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES_BY]) {
|
|
590
|
+
this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES_BY] = {};
|
|
591
|
+
}
|
|
592
|
+
// eslint-disable-next-line max-len
|
|
593
|
+
this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES][metaContainer.metaScope.cScope] = metaContainer.metaScope;
|
|
594
|
+
// eslint-disable-next-line max-len
|
|
595
|
+
this.config.coordinationSpace[CoordinationType.META_COORDINATION_SCOPES_BY][metaContainer.metaByScope.cScope] = metaContainer.metaByScope;
|
|
596
|
+
return metaContainer;
|
|
597
|
+
}
|
|
598
|
+
addComplexCoordination(input) {
|
|
599
|
+
/*
|
|
600
|
+
// The value for `input` might look like:
|
|
601
|
+
{
|
|
602
|
+
[CoordinationType.SPATIAL_IMAGE_LAYER]: CL([
|
|
603
|
+
{
|
|
604
|
+
[CoordinationType.IMAGE]: 'S-1905-017737_bf',
|
|
605
|
+
[CoordinationType.SPATIAL_LAYER_VISIBLE]: true,
|
|
606
|
+
[CoordinationType.SPATIAL_LAYER_OPACITY]: 1,
|
|
607
|
+
[CoordinationType.SPATIAL_IMAGE_CHANNEL]: CL([
|
|
608
|
+
{
|
|
609
|
+
[CoordinationType.SPATIAL_TARGET_C]: 0,
|
|
610
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: [255, 0, 0],
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
[CoordinationType.SPATIAL_TARGET_C]: 1,
|
|
614
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: [0, 255, 0],
|
|
615
|
+
},
|
|
616
|
+
]),
|
|
617
|
+
},
|
|
618
|
+
]),
|
|
619
|
+
[CoordinationType.SPATIAL_SEGMENTATION_LAYER]: CL([
|
|
620
|
+
{
|
|
621
|
+
[CoordinationType.IMAGE]: 'S-1905-017737',
|
|
622
|
+
[CoordinationType.SPATIAL_LAYER_VISIBLE]: true,
|
|
623
|
+
[CoordinationType.SPATIAL_LAYER_OPACITY]: 1,
|
|
624
|
+
[CoordinationType.SPATIAL_SEGMENTATION_CHANNEL]: CL([
|
|
625
|
+
{
|
|
626
|
+
[CoordinationType.OBS_TYPE]: 'Cortical Interstitia',
|
|
627
|
+
[CoordinationType.SPATIAL_TARGET_C]: 0,
|
|
628
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: [255, 0, 0],
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
[CoordinationType.OBS_TYPE]: 'Non-Globally Sclerotic Glomeruli',
|
|
632
|
+
[CoordinationType.SPATIAL_TARGET_C]: 1,
|
|
633
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: [255, 0, 0],
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
[CoordinationType.OBS_TYPE]: 'Globally Sclerotic Glomeruli',
|
|
637
|
+
[CoordinationType.SPATIAL_TARGET_C]: 2,
|
|
638
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: [255, 0, 0],
|
|
639
|
+
},
|
|
640
|
+
]),
|
|
641
|
+
},
|
|
642
|
+
]),
|
|
643
|
+
}
|
|
644
|
+
// Which would correspond to this `output`,
|
|
645
|
+
// a valid input for `VitessceConfigMetaCoordinationScope.useComplexCoordination()`:
|
|
646
|
+
{
|
|
647
|
+
[CoordinationType.SPATIAL_IMAGE_LAYER]: [
|
|
648
|
+
{
|
|
649
|
+
scope: imageLayerScope,
|
|
650
|
+
children: {
|
|
651
|
+
[CoordinationType.IMAGE]: { scope: imageScope },
|
|
652
|
+
[CoordinationType.SPATIAL_LAYER_VISIBLE]: { scope: imageVisibleScope },
|
|
653
|
+
[CoordinationType.SPATIAL_LAYER_OPACITY]: { scope: imageOpacityScope },
|
|
654
|
+
[CoordinationType.SPATIAL_IMAGE_CHANNEL]: [
|
|
655
|
+
{
|
|
656
|
+
scope: imageChannelScopeR,
|
|
657
|
+
children: {
|
|
658
|
+
[CoordinationType.SPATIAL_TARGET_C]: { scope: rTargetScope },
|
|
659
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: { scope: rColorScope },
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
scope: imageChannelScopeG,
|
|
664
|
+
children: {
|
|
665
|
+
[CoordinationType.SPATIAL_TARGET_C]: { scope: gTargetScope },
|
|
666
|
+
[CoordinationType.SPATIAL_CHANNEL_COLOR]: { scope: gColorScope },
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
],
|
|
670
|
+
},
|
|
671
|
+
},
|
|
672
|
+
],
|
|
673
|
+
// ...
|
|
674
|
+
}
|
|
675
|
+
*/
|
|
676
|
+
const processLevel = (level) => {
|
|
677
|
+
const result = {};
|
|
678
|
+
Object.entries(level).forEach(([cType, nextLevelOrInitialValue]) => {
|
|
679
|
+
// Check if value of object is instanceof CoordinationLevel
|
|
680
|
+
// (otherwise assume it is the coordination value).
|
|
681
|
+
if (nextLevelOrInitialValue instanceof CoordinationLevel) {
|
|
682
|
+
const nextLevel = nextLevelOrInitialValue.value;
|
|
683
|
+
if (Array.isArray(nextLevel)) {
|
|
684
|
+
result[cType] = nextLevel.map((nextEl) => {
|
|
685
|
+
const [dummyScope] = this.addCoordination(cType);
|
|
686
|
+
// TODO: set a better initial value for dummy cases.
|
|
687
|
+
dummyScope.setValue('__dummy__');
|
|
688
|
+
return {
|
|
689
|
+
scope: dummyScope,
|
|
690
|
+
children: processLevel(nextEl),
|
|
691
|
+
};
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
throw new Error('Expected CoordinationLevel.value to be an array.');
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
// Base case.
|
|
700
|
+
const initialValue = nextLevelOrInitialValue;
|
|
701
|
+
const [scope] = this.addCoordination(cType);
|
|
702
|
+
scope.setValue(initialValue);
|
|
703
|
+
result[cType] = { scope };
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
return result;
|
|
707
|
+
};
|
|
708
|
+
// Begin recursion.
|
|
709
|
+
const output = processLevel(input);
|
|
710
|
+
return output;
|
|
711
|
+
}
|
|
359
712
|
/**
|
|
360
713
|
* A convenience function for setting up new coordination scopes across a set of views.
|
|
361
714
|
* @param {VitessceConfigView[]} views An array of view objects to link together.
|