@vitessce/config 2.0.3-beta.0 → 3.0.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 +15914 -1
- package/dist-tsc/VitessceAutoConfig.d.ts +2 -0
- package/dist-tsc/VitessceAutoConfig.d.ts.map +1 -0
- package/dist-tsc/VitessceAutoConfig.js +323 -0
- package/dist-tsc/VitessceAutoConfig.test.d.ts +2 -0
- package/dist-tsc/VitessceAutoConfig.test.d.ts.map +1 -0
- package/dist-tsc/VitessceAutoConfig.test.js +442 -0
- package/dist-tsc/VitessceConfig.d.ts +257 -0
- package/dist-tsc/VitessceConfig.d.ts.map +1 -0
- package/dist-tsc/VitessceConfig.test.d.ts +2 -0
- package/dist-tsc/VitessceConfig.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/VitessceConfig.test.js +1 -1
- package/dist-tsc/index.d.ts +3 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +2 -0
- package/dist-tsc/utils.d.ts +12 -0
- package/dist-tsc/utils.d.ts.map +1 -0
- package/package.json +15 -6
- package/src/VitessceAutoConfig.js +382 -0
- package/src/VitessceAutoConfig.test.js +465 -0
- package/src/VitessceConfig.js +502 -0
- package/src/VitessceConfig.test.js +490 -0
- package/src/index.js +2 -0
- package/src/utils.js +48 -0
- /package/{dist → dist-tsc}/VitessceConfig.js +0 -0
- /package/{dist → dist-tsc}/utils.js +0 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { CoordinationType } from '@vitessce/constants-internal';
|
|
2
|
+
import { fromEntries, getNextScope } from '@vitessce/utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Class representing a file within a Vitessce config dataset.
|
|
6
|
+
*/
|
|
7
|
+
export class VitessceConfigDatasetFile {
|
|
8
|
+
/**
|
|
9
|
+
* Construct a new file definition instance.
|
|
10
|
+
* @param {string} url The URL to the file.
|
|
11
|
+
* @param {string} dataType The type of data contained in the file.
|
|
12
|
+
* @param {string} fileType The file type.
|
|
13
|
+
* @param {object|array|null} options An optional object or array
|
|
14
|
+
* which may provide additional parameters to the loader class
|
|
15
|
+
* corresponding to the specified fileType.
|
|
16
|
+
*/
|
|
17
|
+
constructor(url, fileType, coordinationValues, options) {
|
|
18
|
+
this.file = {
|
|
19
|
+
url,
|
|
20
|
+
fileType,
|
|
21
|
+
...(coordinationValues ? { coordinationValues } : {}),
|
|
22
|
+
...(options ? { options } : {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns {object} This dataset file as a JSON object.
|
|
28
|
+
*/
|
|
29
|
+
toJSON() {
|
|
30
|
+
return this.file;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Class representing a dataset within a Vitessce config.
|
|
36
|
+
*/
|
|
37
|
+
export class VitessceConfigDataset {
|
|
38
|
+
/**
|
|
39
|
+
* Construct a new dataset definition instance.
|
|
40
|
+
* @param {string} uid The unique ID for the dataset.
|
|
41
|
+
* @param {string} name The name of the dataset.
|
|
42
|
+
* @param {string} description A description for the dataset.
|
|
43
|
+
*/
|
|
44
|
+
constructor(uid, name, description) {
|
|
45
|
+
this.dataset = {
|
|
46
|
+
uid,
|
|
47
|
+
name,
|
|
48
|
+
description,
|
|
49
|
+
files: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Add a file definition to the dataset.
|
|
55
|
+
* @param {object} params An object with named arguments.
|
|
56
|
+
* @param {string|undefined} params.url The URL to the file.
|
|
57
|
+
* @param {string} params.fileType The file type.
|
|
58
|
+
* @param {object|undefined} params.coordinationValues The coordination values.
|
|
59
|
+
* @param {object|array|undefined} params.options An optional object or array
|
|
60
|
+
* which may provide additional parameters to the loader class
|
|
61
|
+
* corresponding to the specified fileType.
|
|
62
|
+
* @returns {VitessceConfigDataset} This, to allow chaining.
|
|
63
|
+
*/
|
|
64
|
+
addFile(params, ...args) {
|
|
65
|
+
let url;
|
|
66
|
+
let fileType;
|
|
67
|
+
let coordinationValues;
|
|
68
|
+
let options;
|
|
69
|
+
if (args.length > 0) {
|
|
70
|
+
// Old behavior.
|
|
71
|
+
url = params;
|
|
72
|
+
// eslint-disable-next-line no-unused-vars
|
|
73
|
+
let dataType;
|
|
74
|
+
if (args.length === 2) {
|
|
75
|
+
[dataType, fileType] = args;
|
|
76
|
+
} else if (args.length === 3) {
|
|
77
|
+
// eslint-disable-next-line no-unused-vars
|
|
78
|
+
[dataType, fileType, options] = args;
|
|
79
|
+
}
|
|
80
|
+
} else if (typeof params === 'object') {
|
|
81
|
+
({
|
|
82
|
+
url, fileType, options, coordinationValues,
|
|
83
|
+
} = params);
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error('Expected addFile argument to be an object.');
|
|
86
|
+
}
|
|
87
|
+
this.dataset.files.push(
|
|
88
|
+
new VitessceConfigDatasetFile(url, fileType, coordinationValues, options),
|
|
89
|
+
);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @returns {object} This dataset as a JSON object.
|
|
95
|
+
*/
|
|
96
|
+
toJSON() {
|
|
97
|
+
return {
|
|
98
|
+
...this.dataset,
|
|
99
|
+
files: this.dataset.files.map(f => f.toJSON()),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Class representing a view within a Vitessce layout.
|
|
106
|
+
*/
|
|
107
|
+
export class VitessceConfigView {
|
|
108
|
+
/**
|
|
109
|
+
* Construct a new view instance.
|
|
110
|
+
* @param {string} component The name of the Vitessce component type.
|
|
111
|
+
* @param {object} coordinationScopes A mapping from coordination type
|
|
112
|
+
* names to coordination scope names.
|
|
113
|
+
* @param {number} x The x-coordinate of the view in the layout.
|
|
114
|
+
* @param {number} y The y-coordinate of the view in the layout.
|
|
115
|
+
* @param {number} w The width of the view in the layout.
|
|
116
|
+
* @param {number} h The height of the view in the layout.
|
|
117
|
+
*/
|
|
118
|
+
constructor(component, coordinationScopes, x, y, w, h) {
|
|
119
|
+
this.view = {
|
|
120
|
+
component,
|
|
121
|
+
coordinationScopes,
|
|
122
|
+
x,
|
|
123
|
+
y,
|
|
124
|
+
w,
|
|
125
|
+
h,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Attach coordination scopes to this view.
|
|
131
|
+
* @param {...VitessceConfigCoordinationScope} args A variable number of
|
|
132
|
+
* coordination scope instances.
|
|
133
|
+
* @returns {VitessceConfigView} This, to allow chaining.
|
|
134
|
+
*/
|
|
135
|
+
useCoordination(...args) {
|
|
136
|
+
const cScopes = args;
|
|
137
|
+
cScopes.forEach((cScope) => {
|
|
138
|
+
this.view.coordinationScopes[cScope.cType] = cScope.cScope;
|
|
139
|
+
});
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Set the x, y, w, h values for this view.
|
|
145
|
+
* @param {number} x The x-coordinate of the view in the layout.
|
|
146
|
+
* @param {number} y The y-coordinate of the view in the layout.
|
|
147
|
+
* @param {number} w The width of the view in the layout.
|
|
148
|
+
* @param {number} h The height of the view in the layout.
|
|
149
|
+
* @returns {VitessceConfigView} This, to allow chaining.
|
|
150
|
+
*/
|
|
151
|
+
setXYWH(x, y, w, h) {
|
|
152
|
+
this.view.x = x;
|
|
153
|
+
this.view.y = y;
|
|
154
|
+
this.view.w = w;
|
|
155
|
+
this.view.h = h;
|
|
156
|
+
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Set props for this view.
|
|
162
|
+
* @returns {VitessceConfigView} This, to allow chaining.
|
|
163
|
+
*/
|
|
164
|
+
setProps(props) {
|
|
165
|
+
this.view.props = {
|
|
166
|
+
...(this.view.props || {}),
|
|
167
|
+
...props,
|
|
168
|
+
};
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @returns {object} This view as a JSON object.
|
|
174
|
+
*/
|
|
175
|
+
toJSON() {
|
|
176
|
+
return this.view;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Class representing a horizontal concatenation of views.
|
|
182
|
+
*/
|
|
183
|
+
export class VitessceConfigViewHConcat {
|
|
184
|
+
constructor(views) {
|
|
185
|
+
this.views = views;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Class representing a vertical concatenation of views.
|
|
191
|
+
*/
|
|
192
|
+
export class VitessceConfigViewVConcat {
|
|
193
|
+
constructor(views) {
|
|
194
|
+
this.views = views;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A helper function to create a horizontal concatenation of views.
|
|
200
|
+
* @param {...(VitessceConfigView|VitessceConfigViewHConcat|VitessceConfigViewVConcat)} views A
|
|
201
|
+
* variable number of views or view concatenations.
|
|
202
|
+
* @returns {VitessceConfigViewHConcat} A new horizontal view concatenation instance.
|
|
203
|
+
*/
|
|
204
|
+
export function hconcat(...views) {
|
|
205
|
+
const vcvhc = new VitessceConfigViewHConcat(views);
|
|
206
|
+
return vcvhc;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A helper function to create a vertical concatenation of views.
|
|
211
|
+
* @param {...(VitessceConfigView|VitessceConfigViewHConcat|VitessceConfigViewVConcat)} views A
|
|
212
|
+
* variable number of views or view concatenations.
|
|
213
|
+
* @returns {VitessceConfigViewVConcat} A new vertical view concatenation instance.
|
|
214
|
+
*/
|
|
215
|
+
export function vconcat(...views) {
|
|
216
|
+
const vcvvc = new VitessceConfigViewVConcat(views);
|
|
217
|
+
return vcvvc;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Class representing a coordination scope in the coordination space.
|
|
222
|
+
*/
|
|
223
|
+
export class VitessceConfigCoordinationScope {
|
|
224
|
+
/**
|
|
225
|
+
* Construct a new coordination scope instance.
|
|
226
|
+
* @param {string} cType The coordination type for this coordination scope.
|
|
227
|
+
* @param {string} cScope The name of the coordination scope.
|
|
228
|
+
*/
|
|
229
|
+
constructor(cType, cScope) {
|
|
230
|
+
this.cType = cType;
|
|
231
|
+
this.cScope = cScope;
|
|
232
|
+
this.cValue = null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Set the coordination value of the coordination scope.
|
|
237
|
+
* @param {any} cValue The value to set.
|
|
238
|
+
* @returns {VitessceConfigCoordinationScope} This, to allow chaining.
|
|
239
|
+
*/
|
|
240
|
+
setValue(cValue) {
|
|
241
|
+
this.cValue = cValue;
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Class representing a Vitessce view config.
|
|
248
|
+
*/
|
|
249
|
+
export class VitessceConfig {
|
|
250
|
+
/**
|
|
251
|
+
* Construct a new view config instance.
|
|
252
|
+
* @param {object} params An object with named arguments.
|
|
253
|
+
* @param {string} params.schemaVersion The view config schema version. Required.
|
|
254
|
+
* @param {string} params.name A name for the config. Optional.
|
|
255
|
+
* @param {string|undefined} params.description A description for the config. Optional.
|
|
256
|
+
*/
|
|
257
|
+
constructor(params, ...args) {
|
|
258
|
+
let name;
|
|
259
|
+
let description;
|
|
260
|
+
let schemaVersion;
|
|
261
|
+
if (typeof params === 'string') {
|
|
262
|
+
// Old behavior for backwards compatibility.
|
|
263
|
+
schemaVersion = '1.0.7';
|
|
264
|
+
name = params || '';
|
|
265
|
+
if (args.length === 1) {
|
|
266
|
+
[description] = args;
|
|
267
|
+
} else if (args.length > 1) {
|
|
268
|
+
throw new Error('Expected only one VitessceConfig constructor argument.');
|
|
269
|
+
}
|
|
270
|
+
} else if (typeof params === 'object') {
|
|
271
|
+
({ schemaVersion, name, description } = params);
|
|
272
|
+
if (!name) {
|
|
273
|
+
throw new Error('Expected params.name argument in VitessceConfig constructor');
|
|
274
|
+
}
|
|
275
|
+
if (!schemaVersion) {
|
|
276
|
+
throw new Error('Expected params.schemaVersion argument in VitessceConfig constructor');
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
throw new Error('Expected VitessceConfig constructor argument to be an object.');
|
|
280
|
+
}
|
|
281
|
+
this.config = {
|
|
282
|
+
version: schemaVersion,
|
|
283
|
+
name,
|
|
284
|
+
description,
|
|
285
|
+
datasets: [],
|
|
286
|
+
coordinationSpace: {},
|
|
287
|
+
layout: [],
|
|
288
|
+
initStrategy: 'auto',
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Add a new dataset to the config.
|
|
294
|
+
* @param {string} name A name for the dataset. Optional.
|
|
295
|
+
* @param {string} description A description for the dataset. Optional.
|
|
296
|
+
* @param {object} options Extra parameters to be used internally. Optional.
|
|
297
|
+
* @param {string} options.uid Override the automatically-generated dataset ID.
|
|
298
|
+
* Intended for internal usage by the VitessceConfig.fromJSON code.
|
|
299
|
+
* @returns {VitessceConfigDataset} A new dataset instance.
|
|
300
|
+
*/
|
|
301
|
+
addDataset(name = undefined, description = undefined, options = undefined) {
|
|
302
|
+
const { uid } = options || {};
|
|
303
|
+
const prevDatasetUids = this.config.datasets.map(d => d.dataset.uid);
|
|
304
|
+
const nextUid = (uid || getNextScope(prevDatasetUids));
|
|
305
|
+
const newDataset = new VitessceConfigDataset(nextUid, name, description);
|
|
306
|
+
this.config.datasets.push(newDataset);
|
|
307
|
+
const [newScope] = this.addCoordination(CoordinationType.DATASET);
|
|
308
|
+
newScope.setValue(nextUid);
|
|
309
|
+
return newDataset;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Add a new view to the config.
|
|
314
|
+
* @param {VitessceConfigDataset} dataset The dataset instance which defines the data
|
|
315
|
+
* that will be displayed in the view.
|
|
316
|
+
* @param {string} component A component name, such as "scatterplot" or "spatial".
|
|
317
|
+
* @param {object} options Extra options for the component.
|
|
318
|
+
* @param {number} options.x The x-coordinate for the view in the grid layout.
|
|
319
|
+
* @param {number} options.y The y-coordinate for the view in the grid layout.
|
|
320
|
+
* @param {number} options.w The width for the view in the grid layout.
|
|
321
|
+
* @param {number} options.h The height for the view in the grid layout.
|
|
322
|
+
* @param {number} options.mapping A convenience parameter for setting the EMBEDDING_TYPE
|
|
323
|
+
* coordination value. Only applicable if the component is "scatterplot".
|
|
324
|
+
* @returns {VitessceConfigView} A new view instance.
|
|
325
|
+
*/
|
|
326
|
+
addView(dataset, component, options) {
|
|
327
|
+
const {
|
|
328
|
+
x = 0,
|
|
329
|
+
y = 0,
|
|
330
|
+
w = 1,
|
|
331
|
+
h = 1,
|
|
332
|
+
mapping = null,
|
|
333
|
+
} = options || {};
|
|
334
|
+
const datasetMatches = (
|
|
335
|
+
this.config.coordinationSpace[CoordinationType.DATASET]
|
|
336
|
+
? Object.entries(this.config.coordinationSpace[CoordinationType.DATASET])
|
|
337
|
+
// eslint-disable-next-line no-unused-vars
|
|
338
|
+
.filter(([scopeName, datasetScope]) => datasetScope.cValue === dataset.dataset.uid)
|
|
339
|
+
.map(([scopeName]) => scopeName)
|
|
340
|
+
: []
|
|
341
|
+
);
|
|
342
|
+
let datasetScope;
|
|
343
|
+
if (datasetMatches.length === 1) {
|
|
344
|
+
[datasetScope] = datasetMatches;
|
|
345
|
+
} else {
|
|
346
|
+
throw new Error('No coordination scope matching the dataset parameter could be found in the coordination space.');
|
|
347
|
+
}
|
|
348
|
+
const coordinationScopes = {
|
|
349
|
+
[CoordinationType.DATASET]: datasetScope,
|
|
350
|
+
};
|
|
351
|
+
const newView = new VitessceConfigView(component, coordinationScopes, x, y, w, h);
|
|
352
|
+
if (mapping) {
|
|
353
|
+
const [etScope] = this.addCoordination(CoordinationType.EMBEDDING_TYPE);
|
|
354
|
+
etScope.setValue(mapping);
|
|
355
|
+
newView.useCoordination(etScope);
|
|
356
|
+
}
|
|
357
|
+
this.config.layout.push(newView);
|
|
358
|
+
return newView;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Get an array of new coordination scope instances corresponding to coordination types
|
|
363
|
+
* of interest.
|
|
364
|
+
* @param {...string} args A variable number of coordination type names.
|
|
365
|
+
* @returns {VitessceConfigCoordinationScope[]} An array of coordination scope instances.
|
|
366
|
+
*/
|
|
367
|
+
addCoordination(...args) {
|
|
368
|
+
const cTypes = args;
|
|
369
|
+
const result = [];
|
|
370
|
+
cTypes.forEach((cType) => {
|
|
371
|
+
const prevScopes = (
|
|
372
|
+
this.config.coordinationSpace[cType]
|
|
373
|
+
? Object.keys(this.config.coordinationSpace[cType])
|
|
374
|
+
: []
|
|
375
|
+
);
|
|
376
|
+
const scope = new VitessceConfigCoordinationScope(cType, getNextScope(prevScopes));
|
|
377
|
+
if (!this.config.coordinationSpace[scope.cType]) {
|
|
378
|
+
this.config.coordinationSpace[scope.cType] = {};
|
|
379
|
+
}
|
|
380
|
+
this.config.coordinationSpace[scope.cType][scope.cScope] = scope;
|
|
381
|
+
result.push(scope);
|
|
382
|
+
});
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* A convenience function for setting up new coordination scopes across a set of views.
|
|
388
|
+
* @param {VitessceConfigView[]} views An array of view objects to link together.
|
|
389
|
+
* @param {string[]} cTypes The coordination types on which to coordinate the views.
|
|
390
|
+
* @param {any[]} cValues Initial values corresponding to each coordination type.
|
|
391
|
+
* Should have the same length as the cTypes array. Optional.
|
|
392
|
+
* @returns {VitessceConfig} This, to allow chaining.
|
|
393
|
+
*/
|
|
394
|
+
linkViews(views, cTypes, cValues = null) {
|
|
395
|
+
const cScopes = this.addCoordination(...cTypes);
|
|
396
|
+
views.forEach((view) => {
|
|
397
|
+
cScopes.forEach((cScope) => {
|
|
398
|
+
view.useCoordination(cScope);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
if (Array.isArray(cValues) && cValues.length === cTypes.length) {
|
|
402
|
+
cScopes.forEach((cScope, i) => {
|
|
403
|
+
cScope.setValue(cValues[i]);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Set the layout of views.
|
|
411
|
+
* @param {VitessceConfigView|VitessceConfigViewHConcat|VitessceConfigViewVConcat} viewConcat A
|
|
412
|
+
* view or a concatenation of views.
|
|
413
|
+
* @returns {VitessceConfig} This, to allow chaining.
|
|
414
|
+
*/
|
|
415
|
+
layout(viewConcat) {
|
|
416
|
+
function layoutAux(obj, xMin, xMax, yMin, yMax) {
|
|
417
|
+
const w = xMax - xMin;
|
|
418
|
+
const h = yMax - yMin;
|
|
419
|
+
if (obj instanceof VitessceConfigView) {
|
|
420
|
+
obj.setXYWH(xMin, yMin, w, h);
|
|
421
|
+
} else if (obj instanceof VitessceConfigViewHConcat) {
|
|
422
|
+
const { views } = obj;
|
|
423
|
+
const numViews = views.length;
|
|
424
|
+
views.forEach((view, i) => {
|
|
425
|
+
layoutAux(view, xMin + (w / numViews) * i, xMin + (w / numViews) * (i + 1), yMin, yMax);
|
|
426
|
+
});
|
|
427
|
+
} else if (obj instanceof VitessceConfigViewVConcat) {
|
|
428
|
+
const { views } = obj;
|
|
429
|
+
const numViews = views.length;
|
|
430
|
+
views.forEach((view, i) => {
|
|
431
|
+
layoutAux(view, xMin, xMax, yMin + (h / numViews) * i, yMin + (h / numViews) * (i + 1));
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
layoutAux(viewConcat, 0, 12, 0, 12);
|
|
437
|
+
|
|
438
|
+
return this;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Convert this instance to a JSON object that can be passed to the Vitessce component.
|
|
443
|
+
* @returns {object} The view config as a JSON object.
|
|
444
|
+
*/
|
|
445
|
+
toJSON() {
|
|
446
|
+
return {
|
|
447
|
+
...this.config,
|
|
448
|
+
datasets: this.config.datasets.map(d => d.toJSON()),
|
|
449
|
+
coordinationSpace: fromEntries(
|
|
450
|
+
Object.entries(this.config.coordinationSpace).map(([cType, cScopes]) => ([
|
|
451
|
+
cType,
|
|
452
|
+
fromEntries(
|
|
453
|
+
Object.entries(cScopes).map(([cScopeName, cScope]) => ([
|
|
454
|
+
cScopeName,
|
|
455
|
+
cScope.cValue,
|
|
456
|
+
])),
|
|
457
|
+
),
|
|
458
|
+
])),
|
|
459
|
+
),
|
|
460
|
+
layout: this.config.layout.map(c => c.toJSON()),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Create a VitessceConfig instance from an existing view config, to enable
|
|
466
|
+
* manipulation with the JavaScript API.
|
|
467
|
+
* @param {object} config An existing Vitessce view config as a JSON object.
|
|
468
|
+
* @returns {VitessceConfig} A new config instance, with values set to match
|
|
469
|
+
* the config parameter.
|
|
470
|
+
*/
|
|
471
|
+
static fromJSON(config) {
|
|
472
|
+
const { name, description, version: schemaVersion } = config;
|
|
473
|
+
const vc = new VitessceConfig({ schemaVersion, name, description });
|
|
474
|
+
config.datasets.forEach((d) => {
|
|
475
|
+
const newDataset = vc.addDataset(d.name, d.description, { uid: d.uid });
|
|
476
|
+
d.files.forEach((f) => {
|
|
477
|
+
newDataset.addFile({
|
|
478
|
+
url: f.url,
|
|
479
|
+
fileType: f.fileType,
|
|
480
|
+
coordinationValues: f.coordinationValues,
|
|
481
|
+
options: f.options,
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
Object.keys(config.coordinationSpace).forEach((cType) => {
|
|
486
|
+
if (cType !== CoordinationType.DATASET) {
|
|
487
|
+
const cObj = config.coordinationSpace[cType];
|
|
488
|
+
vc.config.coordinationSpace[cType] = {};
|
|
489
|
+
Object.entries(cObj).forEach(([cScopeName, cScopeValue]) => {
|
|
490
|
+
const scope = new VitessceConfigCoordinationScope(cType, cScopeName);
|
|
491
|
+
scope.setValue(cScopeValue);
|
|
492
|
+
vc.config.coordinationSpace[cType][cScopeName] = scope;
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
config.layout.forEach((c) => {
|
|
497
|
+
const newView = new VitessceConfigView(c.component, c.coordinationScopes, c.x, c.y, c.w, c.h);
|
|
498
|
+
vc.config.layout.push(newView);
|
|
499
|
+
});
|
|
500
|
+
return vc;
|
|
501
|
+
}
|
|
502
|
+
}
|