@vitessce/schemas 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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/index.js +16360 -0
  4. package/dist-tsc/file-def-options-legacy.d.ts +72 -0
  5. package/dist-tsc/file-def-options-legacy.d.ts.map +1 -0
  6. package/dist-tsc/file-def-options-legacy.js +28 -0
  7. package/dist-tsc/file-def-options.d.ts +417 -0
  8. package/dist-tsc/file-def-options.d.ts.map +1 -0
  9. package/dist-tsc/file-def-options.js +139 -0
  10. package/dist-tsc/index.d.ts +11 -0
  11. package/dist-tsc/index.d.ts.map +1 -0
  12. package/dist-tsc/index.js +10 -0
  13. package/dist-tsc/previous-config-meta.d.ts +251 -0
  14. package/dist-tsc/previous-config-meta.d.ts.map +1 -0
  15. package/dist-tsc/previous-config-meta.js +22 -0
  16. package/dist-tsc/previous-config-schemas.d.ts +4053 -0
  17. package/dist-tsc/previous-config-schemas.d.ts.map +1 -0
  18. package/dist-tsc/previous-config-schemas.js +204 -0
  19. package/dist-tsc/previous-config-upgraders.d.ts +25 -0
  20. package/dist-tsc/previous-config-upgraders.d.ts.map +1 -0
  21. package/dist-tsc/previous-config-upgraders.js +589 -0
  22. package/dist-tsc/raster-json.d.ts +274 -0
  23. package/dist-tsc/raster-json.d.ts.map +1 -0
  24. package/dist-tsc/raster-json.js +36 -0
  25. package/dist-tsc/schema-builders.d.ts +465 -0
  26. package/dist-tsc/schema-builders.d.ts.map +1 -0
  27. package/dist-tsc/schema-builders.js +127 -0
  28. package/dist-tsc/shared.d.ts +145 -0
  29. package/dist-tsc/shared.d.ts.map +1 -0
  30. package/dist-tsc/shared.js +100 -0
  31. package/dist-tsc/spatial-layers.d.ts +112 -0
  32. package/dist-tsc/spatial-layers.d.ts.map +1 -0
  33. package/dist-tsc/spatial-layers.js +81 -0
  34. package/dist-tsc/view-config-utils.test.d.ts +2 -0
  35. package/dist-tsc/view-config-utils.test.d.ts.map +1 -0
  36. package/dist-tsc/view-config-utils.test.fixtures.d.ts +495 -0
  37. package/dist-tsc/view-config-utils.test.fixtures.d.ts.map +1 -0
  38. package/dist-tsc/view-config-utils.test.fixtures.js +881 -0
  39. package/dist-tsc/view-config-utils.test.js +23 -0
  40. package/dist-tsc/view-config-versions.d.ts +6 -0
  41. package/dist-tsc/view-config-versions.d.ts.map +1 -0
  42. package/dist-tsc/view-config-versions.js +78 -0
  43. package/package.json +49 -0
  44. package/src/file-def-options-legacy.js +34 -0
  45. package/src/file-def-options.ts +158 -0
  46. package/src/index.ts +41 -0
  47. package/src/missing-types.d.ts +1 -0
  48. package/src/previous-config-meta.ts +85 -0
  49. package/src/previous-config-schemas.ts +259 -0
  50. package/src/previous-config-upgraders.ts +739 -0
  51. package/src/raster-json.ts +38 -0
  52. package/src/schema-builders.ts +179 -0
  53. package/src/shared.ts +158 -0
  54. package/src/spatial-layers.ts +103 -0
  55. package/src/view-config-utils.test.fixtures.ts +901 -0
  56. package/src/view-config-utils.test.ts +39 -0
  57. package/src/view-config-versions.ts +87 -0
@@ -0,0 +1,589 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { cloneDeep } from 'lodash-es';
3
+ import { getNextScope, capitalize } from '@vitessce/utils';
4
+ import { configSchema1_0_0, } from './previous-config-schemas.js';
5
+ const coordinationSpaceSchema1_0_0 = configSchema1_0_0
6
+ .shape.coordinationSpace.unwrap();
7
+ const viewCoordinationScopes1_0_0 = configSchema1_0_0
8
+ .shape.layout.element.shape.coordinationScopes.unwrap();
9
+ /**
10
+ * A helper function for the `upgrade()` function,
11
+ * which helps convert `props.view` (for scatterplot and spatial),
12
+ * into new coordination scopes, setting their values
13
+ * in the coordination space and returning the new scope mappings.
14
+ * This function does mutate the `coordinationSpace` parameter.
15
+ * @param {string} prefix The coordination type prefix,
16
+ * either 'embedding' or 'spatial'.
17
+ * @param {object} view The view prop object containing
18
+ * the properties `.target` and `.zoom`.
19
+ * @param {object} coordinationSpace The coordination space.
20
+ * @returns {object} The new coordination scope names.
21
+ */
22
+ function upgradeReplaceViewProp(prefix, view, coordinationSpace) {
23
+ const prevZScopes = Object.keys(coordinationSpace[`${prefix}Zoom`]);
24
+ const prevTXScopes = Object.keys(coordinationSpace[`${prefix}TargetX`]);
25
+ const prevTYScopes = Object.keys(coordinationSpace[`${prefix}TargetY`]);
26
+ const nextZScope = getNextScope(prevZScopes);
27
+ const nextTXScope = getNextScope(prevTXScopes);
28
+ const nextTYScope = getNextScope(prevTYScopes);
29
+ const { zoom, target: [targetX, targetY] } = view;
30
+ // eslint-disable-next-line no-param-reassign
31
+ coordinationSpace[`${prefix}Zoom`][nextZScope] = zoom;
32
+ // eslint-disable-next-line no-param-reassign
33
+ coordinationSpace[`${prefix}TargetX`][nextTXScope] = targetX;
34
+ // eslint-disable-next-line no-param-reassign
35
+ coordinationSpace[`${prefix}TargetY`][nextTYScope] = targetY;
36
+ return {
37
+ [`${prefix}Zoom`]: nextZScope,
38
+ [`${prefix}TargetX`]: nextTXScope,
39
+ [`${prefix}TargetY`]: nextTYScope,
40
+ };
41
+ }
42
+ /**
43
+ * Convert an older view config to a newer view config.
44
+ * @param {object} config A v0.1.0 "legacy" view config.
45
+ * @returns {object} A v1.0.0 "upgraded" view config.
46
+ */
47
+ export function upgradeFrom0_1_0(config, datasetUid = null) {
48
+ const coordinationSpace = {
49
+ embeddingType: {},
50
+ embeddingZoom: {},
51
+ embeddingTargetX: {},
52
+ embeddingTargetY: {},
53
+ spatialZoom: {},
54
+ spatialTargetX: {},
55
+ spatialTargetY: {},
56
+ };
57
+ const layout = [];
58
+ config.staticLayout.forEach((componentDef) => {
59
+ let newComponentDef = {
60
+ ...componentDef,
61
+ coordinationScopes: {},
62
+ };
63
+ if (componentDef.component === 'scatterplot') {
64
+ // Need to set up the coordinationSpace
65
+ // with embeddingType to replace scatterplot
66
+ // component prop "mapping".
67
+ if (componentDef.props?.mapping && typeof componentDef.props.mapping === 'string') {
68
+ coordinationSpace.embeddingType[componentDef.props.mapping] = componentDef.props.mapping;
69
+ newComponentDef = {
70
+ ...newComponentDef,
71
+ coordinationScopes: {
72
+ ...newComponentDef.coordinationScopes,
73
+ embeddingType: componentDef.props.mapping,
74
+ },
75
+ };
76
+ }
77
+ // Need to set up the coordinationSpace
78
+ // with embeddingZoom / embeddingTargetX/Y to replace scatterplot
79
+ // component prop "view" ({ zoom, target }).
80
+ if (componentDef.props?.view) {
81
+ // Note that the below function does mutate the coordinationSpace param.
82
+ const newScopeValues = upgradeReplaceViewProp('embedding', componentDef.props.view, coordinationSpace);
83
+ newComponentDef = {
84
+ ...newComponentDef,
85
+ coordinationScopes: {
86
+ ...newComponentDef.coordinationScopes,
87
+ ...newScopeValues,
88
+ },
89
+ };
90
+ }
91
+ }
92
+ if (componentDef.component === 'spatial') {
93
+ // Need to set up the coordinationSpace
94
+ // with spatialZoom / spatialTargetX/Y to replace spatial
95
+ // component prop "view" ({ zoom, target }).
96
+ if (componentDef?.props?.view) {
97
+ // Note that the below function does mutate the coordinationSpace param.
98
+ const newScopeValues = upgradeReplaceViewProp('spatial', componentDef.props.view, coordinationSpace);
99
+ newComponentDef = {
100
+ ...newComponentDef,
101
+ coordinationScopes: {
102
+ ...newComponentDef.coordinationScopes,
103
+ ...newScopeValues,
104
+ },
105
+ };
106
+ }
107
+ }
108
+ layout.push(newComponentDef);
109
+ });
110
+ const lcDef = layout.find(c => c.component === 'layerController');
111
+ const spatialDef = layout.find(c => c.component === 'spatial');
112
+ if (lcDef && spatialDef && 'coordinationScopes' in spatialDef) {
113
+ lcDef.coordinationScopes = spatialDef.coordinationScopes;
114
+ }
115
+ // Use a random dataset ID when initializing automatically,
116
+ // so that it changes with each new v0.1.0 view config.
117
+ // However, check if the `datasetUid` parameter was passed,
118
+ // which allows for unit testing.
119
+ const newDatasetUid = datasetUid || uuidv4();
120
+ return {
121
+ version: '1.0.0',
122
+ name: config.name,
123
+ description: config.description,
124
+ public: config.public,
125
+ datasets: [
126
+ {
127
+ uid: newDatasetUid,
128
+ name: newDatasetUid,
129
+ files: config.layers.map(layer => ({
130
+ fileType: layer.fileType,
131
+ url: layer.url,
132
+ })),
133
+ },
134
+ ],
135
+ initStrategy: 'auto',
136
+ coordinationSpace,
137
+ layout,
138
+ };
139
+ }
140
+ export function upgradeFrom1_0_0(config) {
141
+ const newConfig = cloneDeep(config);
142
+ const { coordinationSpace } = newConfig;
143
+ function replaceLayerType(layerType, cSpace) {
144
+ // Layer type could be one of a few things, bitmask or raster at the moment.
145
+ const isRaster = layerType === 'raster';
146
+ // eslint-disable-next-line no-param-reassign
147
+ cSpace[`spatial${capitalize(layerType)}Layer${isRaster ? 's' : ''}`] = {};
148
+ Object.entries(cSpace.spatialLayers).forEach(([scope, layers]) => {
149
+ if (Array.isArray(layers) && layers.find(layer => layer.type === layerType)) {
150
+ const typedLayers = layers
151
+ .filter(layer => layer.type === layerType)
152
+ .map((layer) => {
153
+ const newLayer = { ...layer };
154
+ delete newLayer.type;
155
+ return newLayer;
156
+ });
157
+ // eslint-disable-next-line no-param-reassign
158
+ cSpace[`spatial${capitalize(layerType)}Layer${isRaster ? 's' : ''}`][scope] = isRaster
159
+ ? typedLayers
160
+ : typedLayers[0];
161
+ }
162
+ else {
163
+ // eslint-disable-next-line no-param-reassign
164
+ cSpace[`spatial${capitalize(layerType)}Layer${isRaster ? 's' : ''}`][scope] = null;
165
+ }
166
+ });
167
+ }
168
+ if (coordinationSpace && 'spatialLayers' in coordinationSpace) {
169
+ replaceLayerType('raster', coordinationSpace);
170
+ replaceLayerType('cells', coordinationSpace);
171
+ replaceLayerType('molecules', coordinationSpace);
172
+ replaceLayerType('neighborhoods', coordinationSpace);
173
+ delete coordinationSpace.spatialLayers;
174
+ }
175
+ const layout = newConfig.layout.map((component) => {
176
+ const newComponent = { ...component };
177
+ function replaceCoordinationScope(layerType, cScopes) {
178
+ const isRaster = layerType === 'raster';
179
+ if (['spatial', 'layerController'].includes(newComponent.component)
180
+ || (newComponent.component === 'description' && isRaster)) {
181
+ // eslint-disable-next-line no-param-reassign
182
+ cScopes[`spatial${capitalize(layerType)}Layer${isRaster ? 's' : ''}`] = cScopes.spatialLayers;
183
+ }
184
+ }
185
+ if (newComponent.coordinationScopes && newComponent.coordinationScopes.spatialLayers) {
186
+ replaceCoordinationScope('raster', newComponent.coordinationScopes);
187
+ replaceCoordinationScope('cells', newComponent.coordinationScopes);
188
+ replaceCoordinationScope('molecules', newComponent.coordinationScopes);
189
+ replaceCoordinationScope('neighborhoods', newComponent.coordinationScopes);
190
+ delete newComponent.coordinationScopes.spatialLayers;
191
+ }
192
+ return newComponent;
193
+ });
194
+ return {
195
+ ...newConfig,
196
+ coordinationSpace,
197
+ layout,
198
+ version: '1.0.1',
199
+ };
200
+ }
201
+ export function upgradeFrom1_0_1(config) {
202
+ // Need to add the globalDisable3d prop to any layer controller views,
203
+ // to match the previous lack of 3D auto-detection behavior.
204
+ const layout = config.layout.map((component) => {
205
+ const newComponent = { ...component };
206
+ if (newComponent.component === 'layerController') {
207
+ newComponent.props = {
208
+ ...newComponent.props,
209
+ globalDisable3d: true,
210
+ };
211
+ }
212
+ return newComponent;
213
+ });
214
+ // Enforce bitmask or raster as spatial raster layer type, defaulting
215
+ // to raster layer if it is not one of bitmask or raster from the old config.
216
+ const newConfig = cloneDeep(config);
217
+ Object.keys((newConfig?.coordinationSpace?.spatialRasterLayers || {})).forEach((key) => {
218
+ if (newConfig.coordinationSpace?.spatialRasterLayers?.[key]) {
219
+ newConfig.coordinationSpace.spatialRasterLayers[key]
220
+ .forEach((layer, index) => {
221
+ if (newConfig.coordinationSpace) {
222
+ newConfig.coordinationSpace.spatialRasterLayers[key][index].type = ['bitmask', 'raster'].includes(layer.type) ? layer.type : 'raster';
223
+ }
224
+ });
225
+ }
226
+ });
227
+ return {
228
+ ...newConfig,
229
+ layout,
230
+ version: '1.0.2',
231
+ };
232
+ }
233
+ export function upgradeFrom1_0_2(config) {
234
+ // Need to add the globalDisable3d prop to any layer controller views,
235
+ // to match the previous lack of 3D auto-detection behavior.
236
+ const layout = config.layout.map((component) => {
237
+ const newComponent = { ...component };
238
+ if (newComponent.component === 'layerController') {
239
+ newComponent.props = {
240
+ ...newComponent.props,
241
+ disableChannelsIfRgbDetected: true,
242
+ };
243
+ }
244
+ return newComponent;
245
+ });
246
+ // Enforce bitmask or raster as spatial raster layer type, defaulting
247
+ // to raster layer if it is not one of bitmask or raster from the old config.
248
+ const newConfig = cloneDeep(config);
249
+ return {
250
+ ...newConfig,
251
+ layout,
252
+ version: '1.0.3',
253
+ };
254
+ }
255
+ export function upgradeFrom1_0_3(config) {
256
+ const newConfig = cloneDeep(config);
257
+ return {
258
+ ...newConfig,
259
+ version: '1.0.4',
260
+ };
261
+ }
262
+ // Added in version 1.0.5:
263
+ // - Support for an array of strings in the setName property within options array items
264
+ // for the anndata-cell-sets.zarr file type.
265
+ export function upgradeFrom1_0_4(config) {
266
+ const newConfig = cloneDeep(config);
267
+ return {
268
+ ...newConfig,
269
+ version: '1.0.5',
270
+ };
271
+ }
272
+ // Added in version 1.0.6:
273
+ // - Support for the scoreName property within options array items
274
+ // for the anndata-cell-sets.zarr file type.
275
+ export function upgradeFrom1_0_5(config) {
276
+ const newConfig = cloneDeep(config);
277
+ return {
278
+ ...newConfig,
279
+ version: '1.0.6',
280
+ };
281
+ }
282
+ // Added in version 1.0.7:
283
+ // - Support for aliasing the gene identifiers using a different var dataframe column
284
+ // via a new `geneAlias` option for the `anndata-expression-matrix.zarr` fileType.
285
+ export function upgradeFrom1_0_6(config) {
286
+ const newConfig = cloneDeep(config);
287
+ return {
288
+ ...newConfig,
289
+ version: '1.0.7',
290
+ };
291
+ }
292
+ // Added in version 1.0.8:
293
+ // - Support for multiple `dataset` coordination scopes and
294
+ // dataset-specific coordination scope mappings for all
295
+ // other coordination types.
296
+ export function upgradeFrom1_0_7(config) {
297
+ const newConfig = cloneDeep(config);
298
+ return {
299
+ ...newConfig,
300
+ version: '1.0.8',
301
+ };
302
+ }
303
+ // Added in version 1.0.9:
304
+ // - Support for plugin coordination types.
305
+ export function upgradeFrom1_0_8(config) {
306
+ const newConfig = cloneDeep(config);
307
+ return {
308
+ ...newConfig,
309
+ version: '1.0.9',
310
+ };
311
+ }
312
+ // Added in version 1.0.10:
313
+ // - Support for the optional 'uid' property for views.
314
+ export function upgradeFrom1_0_9(config) {
315
+ const newConfig = cloneDeep(config);
316
+ return {
317
+ ...newConfig,
318
+ version: '1.0.10',
319
+ };
320
+ }
321
+ // Added in version 1.0.11:
322
+ // - Changes to spatial layer coordination type names.
323
+ // - Cell -> Obs, Gene -> Feature in coordination type names.
324
+ export function upgradeFrom1_0_10(config) {
325
+ const coordinationSpace = { ...config.coordinationSpace };
326
+ const scopeAnalogies = {
327
+ // Spatial layer types
328
+ spatialRasterLayers: 'spatialImageLayer',
329
+ spatialCellsLayer: 'spatialSegmentationLayer',
330
+ spatialMoleculesLayer: 'spatialPointLayer',
331
+ spatialNeighborhoodsLayer: 'spatialNeighborhoodLayer',
332
+ // Other types
333
+ cellFilter: 'obsFilter',
334
+ cellHighlight: 'obsHighlight',
335
+ cellSelection: 'obsSelection',
336
+ cellSetSelection: 'obsSetSelection',
337
+ cellSetHighlight: 'obsSetHighlight',
338
+ cellSetColor: 'obsSetColor',
339
+ geneFilter: 'featureFilter',
340
+ geneHighlight: 'featureHighlight',
341
+ geneSelection: 'featureSelection',
342
+ geneExpressionColormap: 'featureValueColormap',
343
+ geneExpressionColormapRange: 'featureValueColormapRange',
344
+ cellColorEncoding: 'obsColorEncoding',
345
+ additionalCellSets: 'additionalObsSets',
346
+ embeddingCellSetPolygonsVisible: 'embeddingObsSetPolygonsVisible',
347
+ embeddingCellSetLabelsVisible: 'embeddingObsSetLabelsVisible',
348
+ embeddingCellSetLabelSize: 'embeddingObsSetLabelSize',
349
+ embeddingCellRadius: 'embeddingObsRadius',
350
+ embeddingCellRadiusMode: 'embeddingObsRadiusMode',
351
+ embeddingCellOpacity: 'embeddingObsOpacity',
352
+ embeddingCellOpacityMode: 'embeddingObsOpacityMode',
353
+ };
354
+ Object.entries(scopeAnalogies).forEach(([oldKey, newKey]) => {
355
+ if (coordinationSpace[oldKey]) {
356
+ coordinationSpace[newKey] = coordinationSpace[oldKey];
357
+ delete coordinationSpace[oldKey];
358
+ }
359
+ });
360
+ const layout = config.layout.map((component) => {
361
+ const newComponent = { ...component };
362
+ const { coordinationScopes = {} } = newComponent;
363
+ Object.entries(scopeAnalogies).forEach(([oldKey, newKey]) => {
364
+ if (coordinationScopes[oldKey]) {
365
+ coordinationScopes[newKey] = coordinationScopes[oldKey];
366
+ delete coordinationScopes[oldKey];
367
+ }
368
+ });
369
+ return {
370
+ ...newComponent,
371
+ coordinationScopes,
372
+ };
373
+ });
374
+ return {
375
+ ...config,
376
+ coordinationSpace,
377
+ layout,
378
+ version: '1.0.11',
379
+ };
380
+ }
381
+ // Added in version 1.0.12:
382
+ // - Added a fileType-to-dataType mapping
383
+ // so that datasets[].files[].type is no longer required.
384
+ export function upgradeFrom1_0_11(config) {
385
+ const newConfig = cloneDeep(config);
386
+ const { datasets, coordinationSpace, } = newConfig;
387
+ if (coordinationSpace?.embeddingType) {
388
+ // This array may contain more embedding types than
389
+ // the cells.json file actually contains, but the tradeoff is that
390
+ // we do not have to load the cells.json file to double check what
391
+ // embedding types are actually present. CellsJsonAsObsEmbedding
392
+ // will just load the embedding as null if it is not present.
393
+ const embeddingTypes = Object.values(coordinationSpace.embeddingType);
394
+ datasets.forEach((dataset, i) => {
395
+ const { files } = dataset;
396
+ files.forEach((fileDef, j) => {
397
+ const { fileType } = fileDef;
398
+ if (fileType === 'cells.json') {
399
+ datasets[i].files[j].options = {
400
+ embeddingTypes,
401
+ };
402
+ }
403
+ });
404
+ });
405
+ }
406
+ return {
407
+ ...newConfig,
408
+ datasets,
409
+ version: '1.0.12',
410
+ };
411
+ }
412
+ // Added in version 1.0.13:
413
+ // - Adds the property `coordinationValues` for
414
+ // view config file definitions but is not yet
415
+ // used to do file matching/lookups.
416
+ export function upgradeFrom1_0_12(config) {
417
+ const newConfig = cloneDeep(config);
418
+ // Set up coordination scopes for anndata-cells.zarr's options.factors
419
+ // in the coordination space, and create a new coordinationScopes.obsLabelsType array
420
+ // for each component in the layout.
421
+ const { datasets, coordinationSpace, layout } = newConfig;
422
+ const newCoordinationSpace = (coordinationSpace || {});
423
+ const datasetUidToObsLabelsTypeScopes = {};
424
+ datasets.forEach((dataset) => {
425
+ const { files, uid } = dataset;
426
+ files.forEach((fileDef) => {
427
+ const { fileType, options } = fileDef;
428
+ if (fileType === 'anndata-cells.zarr') {
429
+ if (options && 'factors' in options && Array.isArray(options.factors)) {
430
+ const obsLabelsTypeScopes = [];
431
+ options.factors.forEach((olt) => {
432
+ const nextScope = getNextScope(Object.keys(coordinationSpace?.obsLabelsType || {}));
433
+ newCoordinationSpace.obsLabelsType = {
434
+ ...newCoordinationSpace.obsLabelsType,
435
+ // Need to remove the obs/ prefix.
436
+ [nextScope]: olt.split('/').at(-1),
437
+ };
438
+ obsLabelsTypeScopes.push(nextScope);
439
+ });
440
+ datasetUidToObsLabelsTypeScopes[uid] = obsLabelsTypeScopes;
441
+ }
442
+ }
443
+ });
444
+ });
445
+ function getDatasetUidForView(viewDef) {
446
+ if (viewDef.coordinationScopes?.dataset && typeof viewDef.coordinationScopes?.dataset === 'string') {
447
+ return newCoordinationSpace.dataset[viewDef.coordinationScopes.dataset];
448
+ }
449
+ if (datasets.length > 0) {
450
+ return datasets[0].uid;
451
+ }
452
+ return null;
453
+ }
454
+ const newLayout = layout.map((viewDef) => {
455
+ const viewDatasetUid = getDatasetUidForView(viewDef);
456
+ if (typeof viewDatasetUid === 'string') {
457
+ const datasetObsLabelsTypeScopes = datasetUidToObsLabelsTypeScopes[viewDatasetUid];
458
+ if (datasetObsLabelsTypeScopes) {
459
+ return {
460
+ ...viewDef,
461
+ coordinationScopes: {
462
+ ...viewDef.coordinationScopes,
463
+ obsLabelsType: datasetObsLabelsTypeScopes,
464
+ },
465
+ };
466
+ }
467
+ }
468
+ return viewDef;
469
+ });
470
+ return {
471
+ ...newConfig,
472
+ coordinationSpace: newCoordinationSpace,
473
+ layout: newLayout,
474
+ version: '1.0.13',
475
+ };
476
+ }
477
+ // Added in version 1.0.14:
478
+ // - Adds the coordination types
479
+ // gatingFeatureSelectionX,
480
+ // gatingFeatureSelectionY,
481
+ // featureValueTransformCoefficient.
482
+ export function upgradeFrom1_0_13(config) {
483
+ const newConfig = cloneDeep(config);
484
+ return {
485
+ ...newConfig,
486
+ version: '1.0.14',
487
+ };
488
+ }
489
+ // Added in version 1.0.15:
490
+ // - Changes the following view names:
491
+ // - genes -> featureList
492
+ // - cellSets -> obsSets
493
+ // - cellSetSizes -> obsSetSizes
494
+ // - cellSetExpression -> obsSetFeatureValueDistribution
495
+ // - expressionHistogram -> featureValueHistogram
496
+ // - Deprecates the props:
497
+ // - variablesLabelOverride
498
+ // - observationsLabelOverride
499
+ export function upgradeFrom1_0_14(config) {
500
+ const newConfig = cloneDeep(config);
501
+ const { layout } = newConfig;
502
+ const viewTypeAnalogies = {
503
+ genes: 'featureList',
504
+ cellSets: 'obsSets',
505
+ cellSetSizes: 'obsSetSizes',
506
+ cellSetExpression: 'obsSetFeatureValueDistribution',
507
+ expressionHistogram: 'featureValueHistogram',
508
+ };
509
+ // Handle the view type renaming.
510
+ const newLayout = layout.map((viewDef) => {
511
+ // Replace the old component name with the new one.
512
+ if (viewTypeAnalogies[viewDef.component]) {
513
+ return {
514
+ ...viewDef,
515
+ component: viewTypeAnalogies[viewDef.component],
516
+ };
517
+ }
518
+ return viewDef;
519
+ });
520
+ const propAnalogies = {
521
+ variablesLabelOverride: 'featureType',
522
+ observationsLabelOverride: 'obsType',
523
+ };
524
+ // Warn about the prop usage.
525
+ newLayout.forEach((viewDef) => {
526
+ // Iterate over each old prop key.
527
+ Object.entries(propAnalogies).forEach(([oldProp, newType]) => {
528
+ if (viewDef.props?.[oldProp]) {
529
+ console.warn(`Warning: the '${oldProp}' prop on the ${viewDef.component} view is deprecated. Please use the '${newType}' coordination type instead.`);
530
+ }
531
+ });
532
+ });
533
+ return {
534
+ ...newConfig,
535
+ version: '1.0.15',
536
+ layout: newLayout,
537
+ };
538
+ }
539
+ // Added in version 1.0.16:
540
+ // - Explict coordinationScopesBy property for view definitions,
541
+ // to replace the previous implicit mapping of per-dataset coordination
542
+ // scopes.
543
+ export function upgradeFrom1_0_15(config) {
544
+ const newConfig = cloneDeep(config);
545
+ const { layout } = newConfig;
546
+ const newLayout = layout.map((view) => {
547
+ const { coordinationScopes } = view;
548
+ // Create a new coordinationScopes property that conforms to v1.0.16.
549
+ const newCoordinationScopes = {};
550
+ // Update coordinationScopes and coordinationScopesBy when required.
551
+ if (coordinationScopes?.dataset && Array.isArray(coordinationScopes.dataset)) {
552
+ const coordinationScopesBy = {
553
+ dataset: {},
554
+ };
555
+ Object.entries(coordinationScopes).forEach(([coordinationType, coordinationScope]) => {
556
+ if (!Array.isArray(coordinationScope) && typeof coordinationScope === 'object') {
557
+ if (coordinationType === 'dataset') {
558
+ console.error('Expected coordinationScopes.dataset value to be either string or string[], but got object.');
559
+ }
560
+ coordinationScopesBy.dataset[coordinationType] = coordinationScope;
561
+ }
562
+ else if (Array.isArray(coordinationScope) || typeof coordinationScope === 'string') {
563
+ newCoordinationScopes[coordinationType] = coordinationScope;
564
+ }
565
+ });
566
+ return {
567
+ ...view,
568
+ coordinationScopes: newCoordinationScopes,
569
+ coordinationScopesBy,
570
+ };
571
+ }
572
+ if (coordinationScopes) {
573
+ Object.entries(coordinationScopes).forEach(([coordinationType, coordinationScope]) => {
574
+ if (Array.isArray(coordinationScope) || typeof coordinationScope === 'string') {
575
+ newCoordinationScopes[coordinationType] = coordinationScope;
576
+ }
577
+ });
578
+ }
579
+ return {
580
+ ...view,
581
+ coordinationScopes: newCoordinationScopes,
582
+ };
583
+ });
584
+ return {
585
+ ...newConfig,
586
+ layout: newLayout,
587
+ version: '1.0.16',
588
+ };
589
+ }