@vitessce/vit-s 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.
Files changed (105) hide show
  1. package/dist/index.js +28430 -25685
  2. package/dist-tsc/VitS.d.ts +7 -2
  3. package/dist-tsc/VitS.d.ts.map +1 -1
  4. package/dist-tsc/VitS.js +43 -23
  5. package/dist-tsc/VitessceGrid.d.ts.map +1 -1
  6. package/dist-tsc/VitessceGrid.js +14 -11
  7. package/dist-tsc/VitessceGrid.test.js +5 -2
  8. package/dist-tsc/Warning.js +2 -2
  9. package/dist-tsc/data/LoaderResult.d.ts +8 -3
  10. package/dist-tsc/data/LoaderResult.d.ts.map +1 -1
  11. package/dist-tsc/data/LoaderResult.js +5 -0
  12. package/dist-tsc/data-hook-utils.d.ts +3 -7
  13. package/dist-tsc/data-hook-utils.d.ts.map +1 -1
  14. package/dist-tsc/data-hook-utils.js +97 -79
  15. package/dist-tsc/data-hooks.d.ts +12 -16
  16. package/dist-tsc/data-hooks.d.ts.map +1 -1
  17. package/dist-tsc/data-hooks.js +140 -127
  18. package/dist-tsc/errors/DataSourceFetchError.js +1 -1
  19. package/dist-tsc/hooks.d.ts +3 -7
  20. package/dist-tsc/hooks.d.ts.map +1 -1
  21. package/dist-tsc/hooks.js +12 -18
  22. package/dist-tsc/index.d.ts +2 -1
  23. package/dist-tsc/index.js +2 -1
  24. package/dist-tsc/mui-utils.d.ts +2 -0
  25. package/dist-tsc/mui-utils.d.ts.map +1 -0
  26. package/dist-tsc/mui-utils.js +44 -0
  27. package/dist-tsc/shared-plot-options/OptionSelect.js +1 -1
  28. package/dist-tsc/shared-plot-options/styles.js +1 -1
  29. package/dist-tsc/state/hooks.d.ts +27 -1
  30. package/dist-tsc/state/hooks.d.ts.map +1 -1
  31. package/dist-tsc/state/hooks.js +61 -21
  32. package/dist-tsc/view-config-utils.d.ts +1 -0
  33. package/dist-tsc/view-config-utils.d.ts.map +1 -1
  34. package/dist-tsc/view-config-utils.js +7 -1
  35. package/dist-tsc/view-config-utils.test.js +1 -0
  36. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.js +1 -1
  37. package/dist-tsc/vitessce-grid-layout/layout-utils.test.js +1 -0
  38. package/package.json +10 -9
  39. package/src/VitS.js +79 -43
  40. package/src/VitessceGrid.js +16 -10
  41. package/src/VitessceGrid.test.jsx +8 -2
  42. package/src/Warning.js +2 -2
  43. package/src/data/LoaderResult.js +5 -0
  44. package/src/data-hook-utils.js +116 -81
  45. package/src/data-hooks.js +148 -129
  46. package/src/errors/DataSourceFetchError.js +1 -1
  47. package/src/hooks.js +14 -21
  48. package/src/index.js +2 -0
  49. package/src/mui-utils.js +52 -0
  50. package/src/shared-plot-options/OptionSelect.js +1 -1
  51. package/src/shared-plot-options/styles.js +1 -1
  52. package/src/state/hooks.js +66 -21
  53. package/src/view-config-utils.js +8 -0
  54. package/src/view-config-utils.test.jsx +1 -0
  55. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +1 -1
  56. package/src/vitessce-grid-layout/layout-utils.test.js +1 -0
  57. package/dist-tsc/schemas/config-0.1.0.schema.json +0 -84
  58. package/dist-tsc/schemas/config-1.0.0.schema.json +0 -733
  59. package/dist-tsc/schemas/config-1.0.1.schema.json +0 -909
  60. package/dist-tsc/schemas/config-1.0.10.schema.json +0 -969
  61. package/dist-tsc/schemas/config-1.0.11.schema.json +0 -990
  62. package/dist-tsc/schemas/config-1.0.12.schema.json +0 -997
  63. package/dist-tsc/schemas/config-1.0.13.schema.json +0 -1013
  64. package/dist-tsc/schemas/config-1.0.14.schema.json +0 -1048
  65. package/dist-tsc/schemas/config-1.0.15.schema.json +0 -1048
  66. package/dist-tsc/schemas/config-1.0.16.schema.json +0 -1089
  67. package/dist-tsc/schemas/config-1.0.2.schema.json +0 -910
  68. package/dist-tsc/schemas/config-1.0.3.schema.json +0 -910
  69. package/dist-tsc/schemas/config-1.0.4.schema.json +0 -949
  70. package/dist-tsc/schemas/config-1.0.5.schema.json +0 -949
  71. package/dist-tsc/schemas/config-1.0.6.schema.json +0 -949
  72. package/dist-tsc/schemas/config-1.0.7.schema.json +0 -949
  73. package/dist-tsc/schemas/config-1.0.8.schema.json +0 -965
  74. package/dist-tsc/schemas/config-1.0.9.schema.json +0 -965
  75. package/dist-tsc/schemas/obsSets.schema.d.ts +0 -179
  76. package/dist-tsc/schemas/obsSets.schema.d.ts.map +0 -1
  77. package/dist-tsc/schemas/obsSets.schema.js +0 -195
  78. package/dist-tsc/schemas/obsSetsTabular.schema.d.ts +0 -57
  79. package/dist-tsc/schemas/obsSetsTabular.schema.d.ts.map +0 -1
  80. package/dist-tsc/schemas/obsSetsTabular.schema.js +0 -38
  81. package/dist-tsc/schemas/raster.schema.d.ts +0 -239
  82. package/dist-tsc/schemas/raster.schema.d.ts.map +0 -1
  83. package/dist-tsc/schemas/raster.schema.js +0 -120
  84. package/src/schemas/config-0.1.0.schema.json +0 -85
  85. package/src/schemas/config-1.0.0.schema.json +0 -733
  86. package/src/schemas/config-1.0.1.schema.json +0 -909
  87. package/src/schemas/config-1.0.10.schema.json +0 -969
  88. package/src/schemas/config-1.0.11.schema.json +0 -990
  89. package/src/schemas/config-1.0.12.schema.json +0 -997
  90. package/src/schemas/config-1.0.13.schema.json +0 -1013
  91. package/src/schemas/config-1.0.14.schema.json +0 -1048
  92. package/src/schemas/config-1.0.15.schema.json +0 -1048
  93. package/src/schemas/config-1.0.16.schema.json +0 -1089
  94. package/src/schemas/config-1.0.2.schema.json +0 -911
  95. package/src/schemas/config-1.0.3.schema.json +0 -911
  96. package/src/schemas/config-1.0.4.schema.json +0 -949
  97. package/src/schemas/config-1.0.5.schema.json +0 -949
  98. package/src/schemas/config-1.0.6.schema.json +0 -950
  99. package/src/schemas/config-1.0.7.schema.json +0 -950
  100. package/src/schemas/config-1.0.8.schema.json +0 -966
  101. package/src/schemas/config-1.0.9.schema.json +0 -965
  102. package/src/schemas/obsSets.schema.js +0 -195
  103. package/src/schemas/obsSetsTabular.schema.js +0 -39
  104. package/src/schemas/raster.schema.js +0 -121
  105. package/src/schemas/schema-schema.sh +0 -34
@@ -3,7 +3,7 @@ import { useRef, useCallback, useMemo } from 'react';
3
3
  import create from 'zustand';
4
4
  import createContext from 'zustand/context';
5
5
  import shallow from 'zustand/shallow';
6
- import { isMatch } from 'lodash-es';
6
+ import { isMatch, cloneDeep } from 'lodash-es';
7
7
  import { CoordinationType } from '@vitessce/constants-internal';
8
8
  import { fromEntries, capitalize } from '@vitessce/utils';
9
9
 
@@ -38,17 +38,19 @@ export const useAuxiliaryStore = useAuxiliaryStoreLocal;
38
38
  * - https://github.com/pmndrs/zustand#using-subscribe-with-selector
39
39
  * @returns {function} The useStore hook.
40
40
  */
41
- export const createViewConfigStore = () => create(set => ({
41
+ export const createViewConfigStore = (initialLoaders, initialConfig) => create(set => ({
42
42
  // State:
43
43
  // The viewConfig is an object which must conform to the schema
44
44
  // found in src/schemas/config.schema.json.
45
- viewConfig: null,
45
+ viewConfig: initialConfig,
46
+ // Store the initial config so that its values can be used for resetting.
47
+ initialViewConfig: cloneDeep(initialConfig),
46
48
  // The loaders object is a mapping from dataset ID to
47
49
  // data type to loader object instance.
48
- loaders: null,
50
+ loaders: initialLoaders,
49
51
  // Reducer functions which update the state
50
52
  // (although technically also part of state):
51
- setViewConfig: viewConfig => set({ viewConfig }),
53
+ setViewConfig: viewConfig => set({ viewConfig, initialViewConfig: viewConfig }),
52
54
  setLoaders: loaders => set({ loaders }),
53
55
  setCoordinationValue: ({ parameter, scope, value }) => set(state => ({
54
56
  viewConfig: {
@@ -181,6 +183,30 @@ const useGridSizeStore = create(set => ({
181
183
  })),
182
184
  }));
183
185
 
186
+ /**
187
+ * This hook uses the same logic as for the `values` part of
188
+ * the useCoordination hook, with the difference that it
189
+ * gets its values from the _initial_ view config rather
190
+ * than the current view config.
191
+ * @param {string[]} parameters Array of coordination types.
192
+ * @param {object} coordinationScopes Mapping of coordination types
193
+ * to scope names.
194
+ * @returns {object} Object containing all coordination values.
195
+ */
196
+ export function useInitialCoordination(parameters, coordinationScopes) {
197
+ const values = useViewConfigStore((state) => {
198
+ const { coordinationSpace } = state.initialViewConfig;
199
+ return fromEntries(parameters.map((parameter) => {
200
+ if (coordinationSpace && coordinationSpace[parameter]) {
201
+ const value = coordinationSpace[parameter][coordinationScopes[parameter]];
202
+ return [parameter, value];
203
+ }
204
+ return [parameter, undefined];
205
+ }));
206
+ }, shallow);
207
+ return values;
208
+ }
209
+
184
210
  /**
185
211
  * The useCoordination hook returns both the
186
212
  * values and setter functions for the coordination objects
@@ -434,6 +460,37 @@ export function useLoaders() {
434
460
  return useViewConfigStore(state => state.loaders);
435
461
  }
436
462
 
463
+
464
+ /**
465
+ * Find a specific loader instance for a particular dataset, data type, and view
466
+ * coordination values (mapping from coordination types to coordination values).
467
+ * Uses lodash/isMatch to perform matching against the file definition's
468
+ * coordination value mapping.
469
+ * @param {object} loaders The value returned by useLoaders.
470
+ * @param {string} dataset The dataset UID.
471
+ * @param {string} dataType The data type for the matching file.
472
+ * @param {object} viewCoordinationValues Current coordination values
473
+ * from the view. Match these against a subset of file definition coordination
474
+ * values.
475
+ * @returns The matching loader instance or `null`.
476
+ */
477
+ export function getMatchingLoader(loaders, dataset, dataType, viewCoordinationValues) {
478
+ if (!loaders[dataset]) {
479
+ return null;
480
+ }
481
+ const loaderInternMap = loaders[dataset].loaders[dataType];
482
+ if (!loaderInternMap) {
483
+ return null;
484
+ }
485
+ const loaderKeys = Array.from(loaderInternMap.keys());
486
+ const matchingKey = loaderKeys
487
+ .find(fileCoordinationValues => isMatch(fileCoordinationValues, viewCoordinationValues));
488
+ if (!matchingKey) {
489
+ return null;
490
+ }
491
+ return loaderInternMap.get(matchingKey);
492
+ }
493
+
437
494
  /**
438
495
  * Find a specific loader instance for a particular dataset, data type, and view
439
496
  * coordination values (mapping from coordination types to coordination values).
@@ -448,22 +505,9 @@ export function useLoaders() {
448
505
  * @returns The matching loader instance or `null`.
449
506
  */
450
507
  export function useMatchingLoader(loaders, dataset, dataType, viewCoordinationValues) {
451
- return useMemo(() => {
452
- if (!loaders[dataset]) {
453
- return null;
454
- }
455
- const loaderInternMap = loaders[dataset].loaders[dataType];
456
- if (!loaderInternMap) {
457
- return null;
458
- }
459
- const loaderKeys = Array.from(loaderInternMap.keys());
460
- const matchingKey = loaderKeys
461
- .find(fileCoordinationValues => isMatch(fileCoordinationValues, viewCoordinationValues));
462
- if (!matchingKey) {
463
- return null;
464
- }
465
- return loaderInternMap.get(matchingKey);
466
- }, [loaders, dataset, dataType, viewCoordinationValues]);
508
+ return useMemo(() => getMatchingLoader(
509
+ loaders, dataset, dataType, viewCoordinationValues,
510
+ ), [loaders, dataset, dataType, viewCoordinationValues]);
467
511
  }
468
512
 
469
513
  /**
@@ -471,6 +515,7 @@ export function useMatchingLoader(loaders, dataset, dataType, viewCoordinationVa
471
515
  * coordination values (mapping from coordination types to coordination values).
472
516
  * Uses lodash/isMatch to perform matching against the file definition's
473
517
  * coordination value mapping.
518
+ * TODO: can this function be removed?
474
519
  * @param {object} loaders The value returned by useLoaders.
475
520
  * @param {string} dataset The dataset UID.
476
521
  * @param {string} dataType The data type for the matching file.
@@ -4,8 +4,16 @@ import { cloneDeep } from 'lodash-es';
4
4
  import { fromEntries, getNextScope } from '@vitessce/utils';
5
5
  import {
6
6
  AUTO_INDEPENDENT_COORDINATION_TYPES,
7
+ META_VERSION,
7
8
  } from '@vitessce/constants-internal';
8
9
 
10
+ export function logConfig(config, name) {
11
+ console.groupCollapsed(`🚄 VitS (${META_VERSION.version}) ${name}`);
12
+ console.info(`data:,${JSON.stringify(config)}`);
13
+ console.info(JSON.stringify(config, null, 2));
14
+ console.groupEnd();
15
+ }
16
+
9
17
  /**
10
18
  * Get a list of all unique scope names for a
11
19
  * particular coordination type, which exist in
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ import { describe, it, expect } from 'vitest';
2
3
  import React from 'react';
3
4
  import { z } from '@vitessce/schemas';
4
5
  import { PluginViewType, PluginCoordinationType } from '@vitessce/plugins';
@@ -1,6 +1,6 @@
1
+ import { describe, it, expect, afterEach } from 'vitest';
1
2
  import '@testing-library/jest-dom';
2
3
  import { cleanup, render, screen } from '@testing-library/react';
3
- import { afterEach } from 'vitest';
4
4
 
5
5
  import React from 'react';
6
6
  import { PluginViewType } from '@vitessce/plugins';
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import {
2
3
  makeGridLayout, getMaxRows, resolveLayout,
3
4
  } from './layout-utils.js';
@@ -1,84 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://github.com/vitessce/vitessce/#dataset",
4
- "title": "Vitessce data set",
5
- "type": "object",
6
- "definitions": {
7
- "components": {
8
- "type": "array",
9
- "items": {
10
- "type": "object",
11
- "additionalProperties": false,
12
- "required": ["component", "x", "y"],
13
- "properties": {
14
- "component": { "type": "string" },
15
- "props": { "type": "object" },
16
- "x": { "type": "integer" },
17
- "y": { "type": "integer" },
18
- "w": { "type": "integer" },
19
- "h": { "type": "integer" }
20
- }
21
- }
22
- },
23
- "requestInit": {
24
- "type": "object",
25
- "additionalProperties": false,
26
- "required": [],
27
- "properties": {
28
- "method": {
29
- "type": "string"
30
- },
31
- "headers": {
32
- "type": "object"
33
- },
34
- "body": {
35
- "type": "string"
36
- },
37
- "mode": {
38
- "type": "string"
39
- },
40
- "credentials": {
41
- "type": "string"
42
- },
43
- "cache": {
44
- "type": "string"
45
- },
46
- "redirect": {
47
- "type": "string"
48
- },
49
- "referrer": {
50
- "type": "string"
51
- },
52
- "integrity": {
53
- "type": "string"
54
- }
55
- }
56
- }
57
- },
58
- "additionalProperties": false,
59
- "required": ["version", "name", "layers"],
60
- "properties": {
61
- "name": { "type": "string" },
62
- "public": { "type": "boolean" },
63
- "description": { "type": "string" },
64
- "layers": {
65
- "type": "array",
66
- "items": {
67
- "type": "object",
68
- "additionalProperties": false,
69
- "required": ["name", "type", "fileType", "url"],
70
- "properties": {
71
- "name": { "type": "string" },
72
- "type": { "type": "string" },
73
- "fileType": { "type": "string" },
74
- "url": { "type": "string" },
75
- "requestInit": { "$ref": "#/definitions/requestInit" }
76
- }
77
- }
78
- },
79
- "staticLayout": { "$ref": "#/definitions/components" },
80
- "version": {
81
- "type": "string", "enum": ["0.1.0"]
82
- }
83
- }
84
- }