@vitessce/vit-s 2.0.3-beta.0 → 2.0.3

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 (184) hide show
  1. package/dist/index.mjs +84801 -0
  2. package/{dist → dist-tsc}/index.js +2 -2
  3. package/package.json +7 -7
  4. package/src/CallbackPublisher.js +81 -0
  5. package/src/LoadingIndicator.js +34 -0
  6. package/src/TitleInfo.js +240 -0
  7. package/src/VitS.js +180 -0
  8. package/src/VitessceGrid.js +110 -0
  9. package/src/VitessceGrid.test.jsx +48 -0
  10. package/src/Warning.js +62 -0
  11. package/{dist → src}/classNames.js +0 -0
  12. package/src/component-registry.js +21 -0
  13. package/src/data/AbstractLoader.js +46 -0
  14. package/{dist → src}/data/AbstractTwoStepLoader.js +5 -4
  15. package/src/data/LoaderResult.js +8 -0
  16. package/{dist → src}/data/index.js +0 -0
  17. package/src/data/loader-registry.js +19 -0
  18. package/src/data-hook-utils.js +197 -0
  19. package/src/data-hooks.js +354 -0
  20. package/src/errors/AbstractLoaderError.js +14 -0
  21. package/src/errors/DataSourceFetchError.js +15 -0
  22. package/src/errors/DatasetNotFoundError.js +23 -0
  23. package/src/errors/LoaderNotFoundError.js +24 -0
  24. package/src/errors/LoaderValidationError.js +23 -0
  25. package/src/errors/OptionsValidationError.js +25 -0
  26. package/{dist → src}/errors/index.js +0 -0
  27. package/src/file-options-schemas-legacy.js +139 -0
  28. package/src/file-options-schemas-legacy.test.js +138 -0
  29. package/src/file-options-schemas.js +327 -0
  30. package/src/file-options-schemas.test.js +26 -0
  31. package/src/hooks.js +252 -0
  32. package/src/index.js +101 -0
  33. package/src/joint-file-types-legacy.js +298 -0
  34. package/src/joint-file-types-legacy.test.js +412 -0
  35. package/src/joint-file-types.js +171 -0
  36. package/src/joint-file-types.test.js +144 -0
  37. package/{dist/schemas.js → src/json-schemas.js} +6 -1
  38. package/{dist → src}/plugins.js +102 -70
  39. package/src/plugins.test.fixtures.js +78 -0
  40. package/src/plugins.test.js +42 -0
  41. package/src/schemas/config-0.1.0.schema.json +85 -0
  42. package/src/schemas/config-1.0.0.schema.json +733 -0
  43. package/src/schemas/config-1.0.1.schema.json +909 -0
  44. package/src/schemas/config-1.0.10.schema.json +969 -0
  45. package/src/schemas/config-1.0.11.schema.json +990 -0
  46. package/src/schemas/config-1.0.12.schema.json +997 -0
  47. package/src/schemas/config-1.0.13.schema.json +1013 -0
  48. package/src/schemas/config-1.0.14.schema.json +1048 -0
  49. package/src/schemas/config-1.0.15.schema.json +1048 -0
  50. package/src/schemas/config-1.0.16.schema.json +1069 -0
  51. package/src/schemas/config-1.0.16.schema.test.js +32 -0
  52. package/src/schemas/config-1.0.2.schema.json +911 -0
  53. package/src/schemas/config-1.0.3.schema.json +911 -0
  54. package/src/schemas/config-1.0.4.schema.json +949 -0
  55. package/src/schemas/config-1.0.5.schema.json +949 -0
  56. package/src/schemas/config-1.0.6.schema.json +950 -0
  57. package/src/schemas/config-1.0.7.schema.json +950 -0
  58. package/src/schemas/config-1.0.8.schema.json +966 -0
  59. package/src/schemas/config-1.0.9.schema.json +965 -0
  60. package/src/schemas/fixtures/cellSets.good.json +16 -0
  61. package/src/schemas/fixtures/config-1.0.1.bad.json +1 -0
  62. package/src/schemas/fixtures/config-1.0.1.bad.message.json +11 -0
  63. package/src/schemas/fixtures/config-1.0.1.good.json +37 -0
  64. package/src/schemas/fixtures/config-1.0.2.bad.json +1 -0
  65. package/src/schemas/fixtures/config-1.0.2.bad.message.json +11 -0
  66. package/src/schemas/fixtures/config-1.0.2.good.json +38 -0
  67. package/src/schemas/fixtures/config-1.0.3.bad.json +1 -0
  68. package/src/schemas/fixtures/config-1.0.3.bad.message.json +11 -0
  69. package/src/schemas/fixtures/config-1.0.3.good.json +38 -0
  70. package/src/schemas/fixtures/obsSets.bad.json +1 -0
  71. package/src/schemas/fixtures/obsSets.bad.message.json +11 -0
  72. package/src/schemas/fixtures/obsSets.good.json +16 -0
  73. package/src/schemas/fixtures/obsSetsTabular.bad.json +1 -0
  74. package/src/schemas/fixtures/obsSetsTabular.bad.message.json +11 -0
  75. package/src/schemas/fixtures/obsSetsTabular.good.json +26 -0
  76. package/src/schemas/fixtures/raster.bad.json +1 -0
  77. package/src/schemas/fixtures/raster.bad.message.json +11 -0
  78. package/src/schemas/fixtures/raster.good.json +39 -0
  79. package/src/schemas/obsSets.schema.js +195 -0
  80. package/src/schemas/obsSetsTabular.schema.js +39 -0
  81. package/src/schemas/raster.schema.js +121 -0
  82. package/src/schemas/schema-schema.sh +34 -0
  83. package/{dist → src}/schemas/schema.test-old.js +0 -1
  84. package/src/shared-mui/components.js +79 -0
  85. package/src/shared-mui/container.js +212 -0
  86. package/src/shared-mui/styles.js +110 -0
  87. package/src/shared-plot-options/CellColorEncodingOption.js +43 -0
  88. package/src/shared-plot-options/OptionSelect.js +19 -0
  89. package/src/shared-plot-options/OptionsContainer.js +26 -0
  90. package/{dist → src}/shared-plot-options/index.js +0 -0
  91. package/src/shared-plot-options/styles.js +49 -0
  92. package/src/state/hooks.js +633 -0
  93. package/src/view-config-upgraders.js +628 -0
  94. package/src/view-config-utils.js +315 -0
  95. package/src/view-config-utils.test.fixtures.js +893 -0
  96. package/src/view-config-utils.test.js +95 -0
  97. package/src/view-config-versions.js +68 -0
  98. package/src/vitessce-grid-layout/VitessceGridLayout.js +158 -0
  99. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +56 -0
  100. package/{dist → src}/vitessce-grid-layout/index.js +0 -0
  101. package/src/vitessce-grid-layout/layout-utils.js +76 -0
  102. package/src/vitessce-grid-layout/layout-utils.test.js +167 -0
  103. package/src/vitessce-grid-utils.js +160 -0
  104. package/dist/CallbackPublisher.js +0 -68
  105. package/dist/LoadingIndicator.js +0 -27
  106. package/dist/TitleInfo.js +0 -151
  107. package/dist/VitS.js +0 -117
  108. package/dist/Vitessce.integration.test.js +0 -36
  109. package/dist/Vitessce.js +0 -101
  110. package/dist/VitessceGrid.js +0 -59
  111. package/dist/VitessceGrid.test.js +0 -36
  112. package/dist/Warning.js +0 -45
  113. package/dist/component-registry.js +0 -16
  114. package/dist/data/AbstractLoader.js +0 -35
  115. package/dist/data/LoaderResult.js +0 -7
  116. package/dist/data/loader-registry.js +0 -15
  117. package/dist/data-hook-utils.js +0 -175
  118. package/dist/data-hooks.js +0 -241
  119. package/dist/errors/AbstractLoaderError.js +0 -13
  120. package/dist/errors/DataSourceFetchError.js +0 -13
  121. package/dist/errors/DatasetNotFoundError.js +0 -17
  122. package/dist/errors/LoaderNotFoundError.js +0 -17
  123. package/dist/errors/LoaderValidationError.js +0 -15
  124. package/dist/errors/OptionsValidationError.js +0 -15
  125. package/dist/export-utils.js +0 -70
  126. package/dist/export-utils.test.js +0 -66
  127. package/dist/file-options-schemas-legacy.js +0 -136
  128. package/dist/file-options-schemas-legacy.test.js +0 -126
  129. package/dist/file-options-schemas.js +0 -322
  130. package/dist/file-options-schemas.test.js +0 -23
  131. package/dist/hooks.js +0 -215
  132. package/dist/joint-file-types-legacy.js +0 -278
  133. package/dist/joint-file-types-legacy.test.js +0 -400
  134. package/dist/joint-file-types.js +0 -148
  135. package/dist/joint-file-types.test.js +0 -139
  136. package/dist/loader-registry.js +0 -98
  137. package/dist/plugins.test.fixtures.js +0 -76
  138. package/dist/plugins.test.js +0 -30
  139. package/dist/schemas/PrettyJsonSchema.js +0 -34
  140. package/dist/schemas/config-0.1.0.schema.json +0 -84
  141. package/dist/schemas/config-1.0.0.schema.json +0 -733
  142. package/dist/schemas/config-1.0.1.schema.json +0 -909
  143. package/dist/schemas/config-1.0.10.schema.json +0 -969
  144. package/dist/schemas/config-1.0.11.schema.json +0 -990
  145. package/dist/schemas/config-1.0.12.schema.json +0 -997
  146. package/dist/schemas/config-1.0.13.schema.json +0 -1013
  147. package/dist/schemas/config-1.0.14.schema.json +0 -1048
  148. package/dist/schemas/config-1.0.15.schema.json +0 -1048
  149. package/dist/schemas/config-1.0.15.schema.test.js +0 -22
  150. package/dist/schemas/config-1.0.16.schema.json +0 -1109
  151. package/dist/schemas/config-1.0.16.schema.test.js +0 -22
  152. package/dist/schemas/config-1.0.2.schema.json +0 -910
  153. package/dist/schemas/config-1.0.3.schema.json +0 -910
  154. package/dist/schemas/config-1.0.4.schema.json +0 -949
  155. package/dist/schemas/config-1.0.5.schema.json +0 -949
  156. package/dist/schemas/config-1.0.6.schema.json +0 -949
  157. package/dist/schemas/config-1.0.7.schema.json +0 -949
  158. package/dist/schemas/config-1.0.8.schema.json +0 -965
  159. package/dist/schemas/config-1.0.9.schema.json +0 -965
  160. package/dist/schemas/obs-sets-tabular.schema.js +0 -37
  161. package/dist/schemas/obs-sets.schema.js +0 -194
  162. package/dist/schemas/obsSets.schema.js +0 -195
  163. package/dist/schemas/obsSetsTabular.schema.js +0 -38
  164. package/dist/schemas/raster.schema.js +0 -120
  165. package/dist/schemas/schema.test.js +0 -46
  166. package/dist/schemas-extra.js +0 -3
  167. package/dist/shared-mui/components.js +0 -35
  168. package/dist/shared-mui/container.js +0 -211
  169. package/dist/shared-mui/styles.js +0 -107
  170. package/dist/shared-plot-options/CellColorEncodingOption.js +0 -18
  171. package/dist/shared-plot-options/OptionSelect.js +0 -12
  172. package/dist/shared-plot-options/OptionsContainer.js +0 -12
  173. package/dist/shared-plot-options/styles.js +0 -48
  174. package/dist/state/hooks.js +0 -549
  175. package/dist/view-config-upgraders.js +0 -525
  176. package/dist/view-config-utils.js +0 -286
  177. package/dist/view-config-utils.test.fixtures.js +0 -765
  178. package/dist/view-config-utils.test.js +0 -66
  179. package/dist/view-config-versions.js +0 -47
  180. package/dist/vitessce-grid-layout/VitessceGridLayout.js +0 -95
  181. package/dist/vitessce-grid-layout/VitessceGridLayout.test.js +0 -40
  182. package/dist/vitessce-grid-layout/layout-utils.js +0 -60
  183. package/dist/vitessce-grid-layout/layout-utils.test.js +0 -146
  184. package/dist/vitessce-grid-utils.js +0 -140
@@ -1,59 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useEffect, useCallback, } from 'react';
3
- import clsx from 'clsx';
4
- import { VITESSCE_CONTAINER } from './classNames';
5
- import { VitessceGridLayout } from './vitessce-grid-layout';
6
- import { useRowHeight, createLoaders } from './vitessce-grid-utils';
7
- import { useViewConfigStoreApi, useSetViewConfig, useSetLoaders, useEmitGridResize, useRemoveComponent, useChangeLayout, useLayout, } from './state/hooks';
8
- import { useClosestVitessceContainerSize, } from './hooks';
9
- import { useVitessceContainerStyles } from './shared-mui/container';
10
- import { useTitleStyles } from './TitleInfo';
11
- const padding = 10;
12
- const margin = 5;
13
- /**
14
- * The wrapper for the VitessceGrid and LoadingIndicator components.
15
- * @param {object} props
16
- * @param {number} props.rowHeight The height of each grid row. Optional.
17
- * @param {object} props.config The view config.
18
- * @param {function} props.getComponent A function that maps component names to their
19
- * React counterparts.
20
- * @param {string} props.theme The theme name.
21
- * @param {number} props.height Total height for grid. Optional.
22
- * @param {function} props.onWarn A callback for warning messages. Optional.
23
- */
24
- export default function VitessceGrid(props) {
25
- const { rowHeight: initialRowHeight, config, getComponent, theme, height, isBounded, } = props;
26
- const [rowHeight, containerRef] = useRowHeight(config, initialRowHeight, height, margin, padding);
27
- const onResize = useEmitGridResize();
28
- const [componentWidth] = useClosestVitessceContainerSize(containerRef);
29
- const classes = useVitessceContainerStyles();
30
- const titleClasses = useTitleStyles();
31
- // When the row height has changed, publish a GRID_RESIZE event.
32
- useEffect(() => {
33
- onResize();
34
- }, [rowHeight, onResize]);
35
- const viewConfigStoreApi = useViewConfigStoreApi();
36
- const setViewConfig = useSetViewConfig(viewConfigStoreApi);
37
- const setLoaders = useSetLoaders();
38
- const removeComponent = useRemoveComponent();
39
- const changeLayout = useChangeLayout();
40
- const layout = useLayout();
41
- const changeLayoutPostMount = useCallback((newComponentProps) => {
42
- if (componentWidth > 0) {
43
- changeLayout(newComponentProps);
44
- }
45
- }, [changeLayout, componentWidth]);
46
- // Update the view config and loaders in the global state.
47
- useEffect(() => {
48
- if (config) {
49
- setViewConfig(config);
50
- const loaders = createLoaders(config.datasets, config.description);
51
- setLoaders(loaders);
52
- }
53
- else {
54
- // No config found, so clear the loaders.
55
- setLoaders({});
56
- }
57
- }, [config, setViewConfig, setLoaders]);
58
- return (_jsx("div", { ref: containerRef, className: clsx(VITESSCE_CONTAINER, classes.vitessceContainer), children: layout && (_jsx(VitessceGridLayout, { layout: layout, height: height, rowHeight: rowHeight, theme: theme, getComponent: getComponent, draggableHandle: titleClasses.title, margin: margin, padding: padding, onRemoveComponent: removeComponent, onLayoutChange: changeLayoutPostMount, isBounded: isBounded, onResize: onResize, onResizeStop: onResize })) }));
59
- }
@@ -1,36 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import '@testing-library/jest-dom';
3
- import { cleanup, render, screen } from '@testing-library/react';
4
- import { afterEach } from 'vitest';
5
- import VitessceGrid from './VitessceGrid';
6
- import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
7
- afterEach(() => {
8
- cleanup();
9
- });
10
- describe('VitessceGrid.js', () => {
11
- describe('<VitessceGrid />', () => {
12
- it('renders', async () => {
13
- const config = {
14
- version: '1.0.0',
15
- description: 'fake description',
16
- datasets: [],
17
- name: 'fake name',
18
- layout: [
19
- {
20
- component: 'FakeComponent',
21
- props: { description: 'fake prop description' },
22
- uid: 'A',
23
- x: 0,
24
- y: 0,
25
- },
26
- ],
27
- };
28
- function FakeComponent() {
29
- return _jsx("p", { children: "FakeComponent!" });
30
- }
31
- const getComponent = () => FakeComponent;
32
- render(_jsx(ViewConfigProvider, { createStore: createViewConfigStore, children: _jsx(AuxiliaryProvider, { createStore: createAuxiliaryStore, children: _jsx(VitessceGrid, { config: config, getComponent: getComponent }) }) }));
33
- expect(await screen.findByText('FakeComponent!'));
34
- });
35
- });
36
- });
package/dist/Warning.js DELETED
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import clsx from 'clsx';
3
- import { makeStyles } from '@material-ui/core/styles';
4
- import { VITESSCE_CONTAINER } from './classNames';
5
- const useStyles = makeStyles(theme => ({
6
- warningLayout: {
7
- backgroundColor: theme.palette.gridLayoutBackground,
8
- position: 'absolute',
9
- width: '100%',
10
- height: '100vh',
11
- },
12
- containerFluid: {
13
- width: '100%',
14
- padding: '15px',
15
- marginRight: 'auto',
16
- marginLeft: 'auto',
17
- boxSizing: 'border-box',
18
- display: 'flex',
19
- },
20
- row: {
21
- flexGrow: '1',
22
- },
23
- card: {
24
- border: `1px solid ${theme.palette.cardBorder}`,
25
- flex: '1 1 auto',
26
- minHeight: '1px',
27
- padding: '12px',
28
- marginTop: '8px',
29
- marginBottom: '8px',
30
- position: 'relative',
31
- display: 'flex',
32
- flexDirection: 'column',
33
- minWidth: '0',
34
- wordWrap: 'break-word',
35
- backgroundClip: 'border-box',
36
- borderRadius: '4px',
37
- backgroundColor: theme.palette.primaryBackground,
38
- color: theme.palette.primaryForeground,
39
- },
40
- }));
41
- export function Warning(props) {
42
- const { title, preformatted, unformatted, } = props;
43
- const classes = useStyles();
44
- return (_jsx("div", { className: VITESSCE_CONTAINER, children: _jsx("div", { className: clsx(classes.warningLayout, classes.containerFluid), children: _jsx("div", { className: classes.row, children: _jsxs("div", { className: classes.card, children: [_jsx("h1", { children: title }), preformatted ? (_jsx("pre", { children: preformatted })) : null, _jsx("p", { children: unformatted })] }) }) }) }));
45
- }
@@ -1,16 +0,0 @@
1
- import { getPluginViewType, getPluginViewTypes } from './plugins';
2
- // TODO(monorepo): this code can be simplified
3
- const registry = {};
4
- export function getComponent(name) {
5
- let component = registry[name];
6
- if (component === undefined) {
7
- component = getPluginViewType(name);
8
- if (component === undefined) {
9
- throw new Error(`Could not find definition for "${name}" in the core registry nor the plugin registry.`);
10
- }
11
- }
12
- return component;
13
- }
14
- export function getViewTypes() {
15
- return [...Object.keys(registry), ...getPluginViewTypes()];
16
- }
@@ -1,35 +0,0 @@
1
- import Ajv from 'ajv';
2
- import { OptionsValidationError } from '../errors/index';
3
- import { emptySchema } from '../file-options-schemas';
4
- /**
5
- * A loader ancestor class containing a default constructor
6
- * and a stub for the required load() method.
7
- */
8
- export default class AbstractLoader {
9
- constructor({ type, fileType, url, requestInit, options, coordinationValues, }) {
10
- this.fileType = fileType;
11
- this.type = type;
12
- this.url = url;
13
- this.requestInit = requestInit;
14
- this.options = options;
15
- this.coordinationValues = coordinationValues;
16
- this.optionsSchema = emptySchema;
17
- }
18
- validateOptions() {
19
- const { optionsSchema, options } = this;
20
- const validate = new Ajv().compile(optionsSchema);
21
- const valid = validate(options || null);
22
- if (!valid) {
23
- return [false, validate.errors];
24
- }
25
- return [true, null];
26
- }
27
- load() {
28
- const { fileType, url, options, } = this;
29
- const [optionsAreValid, optionsFailureReason] = this.validateOptions();
30
- if (!optionsAreValid) {
31
- return Promise.reject(new OptionsValidationError(fileType, url, options, optionsFailureReason));
32
- }
33
- return Promise.resolve(optionsAreValid);
34
- }
35
- }
@@ -1,7 +0,0 @@
1
- export default class LoaderResult {
2
- constructor(data, url, coordinationValues = null) {
3
- this.data = data;
4
- this.url = url;
5
- this.coordinationValues = coordinationValues;
6
- }
7
- }
@@ -1,15 +0,0 @@
1
- import { getLoaderClassesForPluginFileType, } from '../plugins';
2
- export const fileTypeToLoaderAndSource = {};
3
- export function getSourceAndLoaderFromFileType(type) {
4
- if (fileTypeToLoaderAndSource[type]) {
5
- return fileTypeToLoaderAndSource[type];
6
- }
7
- const pluginFileType = getLoaderClassesForPluginFileType(type);
8
- if (pluginFileType) {
9
- return pluginFileType;
10
- }
11
- // Fallback to JSON.
12
- // TODO(monorepo)
13
- // return [JsonSource, JsonLoader];
14
- return [null, null];
15
- }
@@ -1,175 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import equal from 'fast-deep-equal';
3
- import { capitalize } from '@vitessce/utils';
4
- import { STATUS } from '@vitessce/constants-internal';
5
- import { useMatchingLoader, useMatchingLoaders, useSetWarning } from './state/hooks';
6
- import { AbstractLoaderError, LoaderNotFoundError, } from './errors/index';
7
- import { getDefaultCoordinationValues } from './plugins';
8
- /**
9
- * Warn via publishing to the console
10
- * and to the global warning store.
11
- * @param {AbstractLoaderError} error An error instance.
12
- */
13
- export function warn(error, setWarning) {
14
- setWarning(error.message);
15
- console.warn(error.message);
16
- console.error(error.stack);
17
- if (error instanceof AbstractLoaderError) {
18
- error.warnInConsole();
19
- }
20
- }
21
- /**
22
- * Initialize values in the coordination space.
23
- * @param {object} values Object where
24
- * keys are coordination type names,
25
- * values are initial coordination values.
26
- * @param {object} setters Object where
27
- * keys are coordination type names with the prefix 'set',
28
- * values are coordination setter functions.
29
- * @param {object} initialValues Object where
30
- * keys are coordination type names and keys are values.
31
- */
32
- export function initCoordinationSpace(values, setters, initialValues) {
33
- if (!values || !setters) {
34
- return;
35
- }
36
- const defaultCoordinationValues = getDefaultCoordinationValues();
37
- Object.entries(values).forEach(([coordinationType, value]) => {
38
- const setterName = `set${capitalize(coordinationType)}`;
39
- const setterFunc = setters[setterName];
40
- const initialValue = initialValues && initialValues[coordinationType];
41
- const shouldInit = equal(initialValue, defaultCoordinationValues[coordinationType]);
42
- if (shouldInit && setterFunc) {
43
- setterFunc(value);
44
- }
45
- });
46
- }
47
- /**
48
- * Get data from a cells data type loader,
49
- * updating "ready" and URL state appropriately.
50
- * Throw warnings if the data is marked as required.
51
- * Subscribe to loader updates.
52
- * @param {object} loaders The object mapping
53
- * datasets and data types to loader instances.
54
- * @param {string} dataset The key for a dataset,
55
- * used to identify which loader to use.
56
- * @param {function} addUrl A function to call to update
57
- * the URL list.
58
- * @param {boolean} isRequired Should a warning be thrown if
59
- * loading is unsuccessful?
60
- * @param {object} coordinationSetters Object where
61
- * keys are coordination type names with the prefix 'set',
62
- * values are coordination setter functions.
63
- * @param {object} initialCoordinationValues Object where
64
- * keys are coordination type names with the prefix 'initialize',
65
- * values are initialization preferences as boolean values.
66
- * @returns {array} [cells, cellsCount] where
67
- * cells is an object and cellsCount is the
68
- * number of items in the cells object.
69
- */
70
- export function useDataType(dataType, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
71
- const [data, setData] = useState({});
72
- const [status, setStatus] = useState(STATUS.LOADING);
73
- const setWarning = useSetWarning();
74
- const loader = useMatchingLoader(loaders, dataset, dataType, matchOn);
75
- useEffect(() => {
76
- if (loader) {
77
- setStatus(STATUS.LOADING);
78
- loader.load().catch(e => warn(e, setWarning)).then((payload) => {
79
- if (!payload)
80
- return;
81
- const { data: payloadData, url, coordinationValues } = payload;
82
- setData(payloadData);
83
- if (Array.isArray(url)) {
84
- url.forEach(([val, name]) => {
85
- addUrl(val, name);
86
- });
87
- }
88
- else if (url) {
89
- addUrl(url, dataType);
90
- }
91
- initCoordinationSpace(coordinationValues, coordinationSetters, initialCoordinationValues);
92
- setStatus(STATUS.SUCCESS);
93
- });
94
- }
95
- else {
96
- setData({});
97
- if (isRequired) {
98
- warn(new LoaderNotFoundError(loaders, dataset, dataType, matchOn), setWarning);
99
- setStatus(STATUS.ERROR);
100
- }
101
- else {
102
- setStatus(STATUS.SUCCESS);
103
- }
104
- }
105
- // eslint-disable-next-line react-hooks/exhaustive-deps
106
- }, [loader]);
107
- return [data, status];
108
- }
109
- /**
110
- * Get data from a cells data type loader,
111
- * updating "ready" and URL state appropriately.
112
- * Throw warnings if the data is marked as required.
113
- * Subscribe to loader updates.
114
- * @param {object} loaders The object mapping
115
- * datasets and data types to loader instances.
116
- * @param {string} dataset The key for a dataset,
117
- * used to identify which loader to use.
118
- * @param {function} addUrl A function to call to update
119
- * the URL list.
120
- * @param {boolean} isRequired Should a warning be thrown if
121
- * loading is unsuccessful?
122
- * @param {object} coordinationSetters Object where
123
- * keys are coordination type names with the prefix 'set',
124
- * values are coordination setter functions.
125
- * @param {object} initialCoordinationValues Object where
126
- * keys are coordination type names with the prefix 'initialize',
127
- * values are initialization preferences as boolean values.
128
- * @returns {array} [cells, cellsCount] where
129
- * cells is an object and cellsCount is the
130
- * number of items in the cells object.
131
- */
132
- export function useDataTypeMulti(dataType, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOnObj) {
133
- const [data, setData] = useState({});
134
- const [status, setStatus] = useState(STATUS.LOADING);
135
- const setWarning = useSetWarning();
136
- const matchingLoaders = useMatchingLoaders(loaders, dataset, dataType, matchOnObj);
137
- useEffect(() => {
138
- if (matchingLoaders) {
139
- setStatus(STATUS.LOADING);
140
- Object.entries(matchingLoaders).forEach(([scopeKey, loader]) => {
141
- if (loader) {
142
- loader.load().catch(e => warn(e, setWarning)).then((payload) => {
143
- if (!payload)
144
- return;
145
- const { data: payloadData, url, coordinationValues } = payload;
146
- setData((prev) => {
147
- // eslint-disable-next-line no-param-reassign
148
- prev[scopeKey] = payloadData;
149
- return prev;
150
- });
151
- addUrl(url, dataType);
152
- initCoordinationSpace(coordinationValues, coordinationSetters, initialCoordinationValues);
153
- setStatus(STATUS.SUCCESS);
154
- });
155
- }
156
- });
157
- }
158
- else {
159
- setData({});
160
- if (isRequired) {
161
- warn(new LoaderNotFoundError(loaders, dataset, dataType, matchOnObj), setWarning);
162
- setStatus(STATUS.ERROR);
163
- }
164
- else {
165
- setStatus(STATUS.SUCCESS);
166
- }
167
- }
168
- // eslint-disable-next-line react-hooks/exhaustive-deps
169
- }, [matchingLoaders]);
170
- return [data, status];
171
- }
172
- export function useHasLoader(loaders, dataset, dataType, matchOn) {
173
- const loader = useMatchingLoader(loaders, dataset, dataType, matchOn);
174
- return loader !== null;
175
- }
@@ -1,241 +0,0 @@
1
- import { useState, useEffect, useMemo } from 'react';
2
- import { CoordinationType, DataType, STATUS } from '@vitessce/constants-internal';
3
- import { fromEntries } from '@vitessce/utils';
4
- import { useMatchingLoader, useMultiCoordinationValues, useSetWarning } from './state/hooks';
5
- import { LoaderNotFoundError, } from './errors/index';
6
- import { warn, useDataType, useDataTypeMulti, } from './data-hook-utils';
7
- /**
8
- * Get the dataset description string.
9
- * @param {object} loaders The object mapping
10
- * datasets and data types to loader instances.
11
- * @param {string} dataset The key for a dataset,
12
- * used to identify which loader to use.
13
- * @returns {array} [description] where
14
- * description is a string.
15
- */
16
- export function useDescription(loaders, dataset) {
17
- const [description, setDescription] = useState();
18
- useEffect(() => {
19
- if (!loaders[dataset]) {
20
- return;
21
- }
22
- if (loaders[dataset].description) {
23
- setDescription(loaders[dataset].description);
24
- }
25
- else {
26
- setDescription(null);
27
- }
28
- // eslint-disable-next-line react-hooks/exhaustive-deps
29
- }, [loaders, dataset]);
30
- return [description];
31
- }
32
- /**
33
- * Get data from a cells data type loader,
34
- * updating "ready" and URL state appropriately.
35
- * Throw warnings if the data is marked as required.
36
- * Subscribe to loader updates.
37
- * @param {object} loaders The object mapping
38
- * datasets and data types to loader instances.
39
- * @param {string} dataset The key for a dataset,
40
- * used to identify which loader to use.
41
- * @param {function} addUrl A function to call to update
42
- * the URL list.
43
- * @param {boolean} isRequired Should a warning be thrown if
44
- * loading is unsuccessful?
45
- * @param {object} coordinationSetters Object where
46
- * keys are coordination type names with the prefix 'set',
47
- * values are coordination setter functions.
48
- * @param {object} initialCoordinationValues Object where
49
- * keys are coordination type names with the prefix 'initialize',
50
- * values are initialization preferences as boolean values.
51
- * @returns {array} [cells, cellsCount] where
52
- * cells is an object and cellsCount is the
53
- * number of items in the cells object.
54
- */
55
- export function useObsEmbeddingData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
56
- return useDataType(DataType.OBS_EMBEDDING, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
57
- }
58
- export function useObsLocationsData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
59
- return useDataType(DataType.OBS_LOCATIONS, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
60
- }
61
- export function useObsLabelsData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
62
- return useDataType(DataType.OBS_LABELS, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
63
- }
64
- export function useObsSegmentationsData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
65
- return useDataType(DataType.OBS_SEGMENTATIONS, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
66
- }
67
- export function useObsSetsData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
68
- return useDataType(DataType.OBS_SETS, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
69
- }
70
- export function useObsFeatureMatrixData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
71
- return useDataType(DataType.OBS_FEATURE_MATRIX, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
72
- }
73
- export function useFeatureLabelsData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
74
- return useDataType(DataType.FEATURE_LABELS, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
75
- }
76
- export function useImageData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
77
- return useDataType(DataType.IMAGE, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
78
- }
79
- export function useGenomicProfilesData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
80
- return useDataType(DataType.GENOMIC_PROFILES, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
81
- }
82
- export function useNeighborhoodsData(loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn) {
83
- return useDataType(DataType.NEIGHBORHOODS, loaders, dataset, addUrl, isRequired, coordinationSetters, initialCoordinationValues, matchOn);
84
- }
85
- /**
86
- * Get data from the expression matrix data type loader for a given gene selection.
87
- * Throw warnings if the data is marked as required.
88
- * Subscribe to loader updates.
89
- * @param {object} loaders The object mapping
90
- * datasets and data types to loader instances.
91
- * @param {string} dataset The key for a dataset,
92
- * used to identify which loader to use.
93
- * @param {boolean} isRequired Should a warning be thrown if
94
- * loading is unsuccessful?
95
- * @param {boolean} selection A list of gene names to get expression data for.
96
- * @returns {array} [geneData] where geneData is an array [Uint8Array, ..., Uint8Array]
97
- * for however many genes are in the selection.
98
- */
99
- export function useFeatureSelection(loaders, dataset, isRequired, selection, matchOn) {
100
- const [geneData, setGeneData] = useState();
101
- const [status, setStatus] = useState(STATUS.LOADING);
102
- const [loadedGeneName, setLoadedGeneName] = useState(null);
103
- const setWarning = useSetWarning();
104
- const loader = useMatchingLoader(loaders, dataset, DataType.OBS_FEATURE_MATRIX, matchOn);
105
- useEffect(() => {
106
- if (!selection) {
107
- setGeneData(null);
108
- setLoadedGeneName(null);
109
- setStatus(STATUS.SUCCESS);
110
- return;
111
- }
112
- if (loader) {
113
- setGeneData(null);
114
- setLoadedGeneName(null);
115
- setStatus(STATUS.LOADING);
116
- const implementsGeneSelection = typeof loader.loadGeneSelection === 'function';
117
- if (implementsGeneSelection) {
118
- loader
119
- .loadGeneSelection({ selection })
120
- .catch(e => warn(e, setWarning))
121
- .then((payload) => {
122
- if (!payload)
123
- return;
124
- const { data } = payload;
125
- setGeneData(data);
126
- setStatus(STATUS.SUCCESS);
127
- setLoadedGeneName(selection);
128
- });
129
- }
130
- else {
131
- loader.load().catch(e => warn(e, setWarning)).then((payload) => {
132
- if (!payload)
133
- return;
134
- const { data } = payload;
135
- const { obsIndex, featureIndex, obsFeatureMatrix } = data;
136
- const expressionDataForSelection = selection.map((sel) => {
137
- const geneIndex = featureIndex.indexOf(sel);
138
- const numGenes = featureIndex.length;
139
- const numCells = obsIndex.length;
140
- const expressionData = new Uint8Array(numCells);
141
- for (let cellIndex = 0; cellIndex < numCells; cellIndex += 1) {
142
- expressionData[cellIndex] = obsFeatureMatrix.data[cellIndex * numGenes + geneIndex];
143
- }
144
- return expressionData;
145
- });
146
- setGeneData(expressionDataForSelection);
147
- setStatus(STATUS.SUCCESS);
148
- setLoadedGeneName(selection);
149
- });
150
- }
151
- }
152
- else {
153
- setGeneData(null);
154
- setLoadedGeneName(null);
155
- if (isRequired) {
156
- warn(new LoaderNotFoundError(loaders, dataset, DataType.OBS_FEATURE_MATRIX, matchOn), setWarning);
157
- setStatus(STATUS.ERROR);
158
- }
159
- else {
160
- setStatus(STATUS.SUCCESS);
161
- }
162
- }
163
- // eslint-disable-next-line react-hooks/exhaustive-deps
164
- }, [loader, selection]);
165
- return [geneData, loadedGeneName, status];
166
- }
167
- /**
168
- * Get the attributes for the expression matrix data type loader,
169
- * i.e names of cells and genes.
170
- * Throw warnings if the data is marked as required.
171
- * Subscribe to loader updates. Should not be used in conjunction (called in the same component)
172
- * with useExpressionMatrixData.
173
- * @param {object} loaders The object mapping
174
- * datasets and data types to loader instances.
175
- * @param {string} dataset The key for a dataset,
176
- * used to identify which loader to use.
177
- * @param {function} addUrl A function to call to update
178
- * the URL list.
179
- * @param {boolean} isRequired Should a warning be thrown if
180
- * loading is unsuccessful?
181
- * @returns {object} [attrs] { rows, cols } object containing cell and gene names.
182
- */
183
- export function useObsFeatureMatrixIndices(loaders, dataset, addUrl, isRequired, matchOn) {
184
- const [data, setData] = useState({});
185
- const [status, setStatus] = useState(STATUS.LOADING);
186
- const setWarning = useSetWarning();
187
- const loader = useMatchingLoader(loaders, dataset, DataType.OBS_FEATURE_MATRIX, matchOn);
188
- useEffect(() => {
189
- if (loader) {
190
- setStatus(STATUS.LOADING);
191
- const implementsLoadAttrs = typeof loader.loadAttrs === 'function';
192
- if (implementsLoadAttrs) {
193
- loader.loadAttrs().catch(e => warn(e, setWarning)).then((payload) => {
194
- if (!payload)
195
- return;
196
- const { data: payloadData, url } = payload;
197
- setData({
198
- obsIndex: payloadData.rows,
199
- featureIndex: payloadData.cols,
200
- });
201
- addUrl(url, DataType.OBS_FEATURE_MATRIX);
202
- setStatus(STATUS.SUCCESS);
203
- });
204
- }
205
- else {
206
- loader.load().catch(e => warn(e, setWarning)).then((payload) => {
207
- if (!payload)
208
- return;
209
- const { data: payloadData, url } = payload;
210
- setData({
211
- obsIndex: payloadData.obsIndex,
212
- featureIndex: payloadData.featureIndex,
213
- });
214
- addUrl(url, DataType.OBS_FEATURE_MATRIX);
215
- setStatus(STATUS.SUCCESS);
216
- });
217
- }
218
- }
219
- else {
220
- setData({});
221
- if (isRequired) {
222
- warn(new LoaderNotFoundError(loaders, dataset, DataType.OBS_FEATURE_MATRIX, matchOn), setWarning);
223
- setStatus(STATUS.ERROR);
224
- }
225
- else {
226
- setStatus(STATUS.SUCCESS);
227
- }
228
- }
229
- // eslint-disable-next-line react-hooks/exhaustive-deps
230
- }, [loader]);
231
- return [data, status];
232
- }
233
- export function useMultiObsLabels(coordinationScopes, obsType, loaders, dataset, addUrl) {
234
- const obsLabelsTypes = useMultiCoordinationValues(CoordinationType.OBS_LABELS_TYPE, coordinationScopes);
235
- const obsLabelsMatchOnObj = useMemo(() => fromEntries(Object.entries(obsLabelsTypes).map(([scope, obsLabelsType]) => ([
236
- scope,
237
- { obsLabelsType, obsType },
238
- ]))), [obsLabelsTypes, obsType]);
239
- const [obsLabelsData, obsLabelsDataStatus] = useDataTypeMulti(DataType.OBS_LABELS, loaders, dataset, addUrl, false, {}, {}, obsLabelsMatchOnObj);
240
- return [obsLabelsTypes, obsLabelsData, obsLabelsDataStatus];
241
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * A loader error ancestor class containing a default constructor
3
- * and a stub for the required warnInConsole() method.
4
- */
5
- export default class AbstractLoaderError {
6
- constructor(message) {
7
- this.message = message;
8
- }
9
- // eslint-disable-next-line class-methods-use-this
10
- warnInConsole() {
11
- throw new Error('The warnInConsole() method has not been implemented.');
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- import AbstractLoaderError from './AbstractLoaderError';
2
- export default class DataSourceFetchError extends AbstractLoaderError {
3
- constructor(source, url, headers) {
4
- super(`${source} Error HTTP Status fetching from ${url}`);
5
- this.source = source;
6
- this.url = url;
7
- this.headers = headers;
8
- }
9
- warnInConsole() {
10
- const { source, url, headers } = this;
11
- console.warn(`${source} failed to fetch from ${url} with headers ${headers}`);
12
- }
13
- }