@vitessce/vit-s 2.0.2 → 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 (172) 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 -112
  108. package/dist/VitessceGrid.js +0 -59
  109. package/dist/VitessceGrid.test.js +0 -36
  110. package/dist/Warning.js +0 -45
  111. package/dist/component-registry.js +0 -16
  112. package/dist/data/AbstractLoader.js +0 -35
  113. package/dist/data/LoaderResult.js +0 -7
  114. package/dist/data/loader-registry.js +0 -15
  115. package/dist/data-hook-utils.js +0 -175
  116. package/dist/data-hooks.js +0 -241
  117. package/dist/errors/AbstractLoaderError.js +0 -13
  118. package/dist/errors/DataSourceFetchError.js +0 -13
  119. package/dist/errors/DatasetNotFoundError.js +0 -17
  120. package/dist/errors/LoaderNotFoundError.js +0 -17
  121. package/dist/errors/LoaderValidationError.js +0 -15
  122. package/dist/errors/OptionsValidationError.js +0 -15
  123. package/dist/file-options-schemas-legacy.js +0 -136
  124. package/dist/file-options-schemas-legacy.test.js +0 -126
  125. package/dist/file-options-schemas.js +0 -322
  126. package/dist/file-options-schemas.test.js +0 -23
  127. package/dist/hooks.js +0 -215
  128. package/dist/joint-file-types-legacy.js +0 -278
  129. package/dist/joint-file-types-legacy.test.js +0 -400
  130. package/dist/joint-file-types.js +0 -148
  131. package/dist/joint-file-types.test.js +0 -139
  132. package/dist/plugins.test.fixtures.js +0 -76
  133. package/dist/plugins.test.js +0 -30
  134. package/dist/schemas/config-0.1.0.schema.json +0 -84
  135. package/dist/schemas/config-1.0.0.schema.json +0 -733
  136. package/dist/schemas/config-1.0.1.schema.json +0 -909
  137. package/dist/schemas/config-1.0.10.schema.json +0 -969
  138. package/dist/schemas/config-1.0.11.schema.json +0 -990
  139. package/dist/schemas/config-1.0.12.schema.json +0 -997
  140. package/dist/schemas/config-1.0.13.schema.json +0 -1013
  141. package/dist/schemas/config-1.0.14.schema.json +0 -1048
  142. package/dist/schemas/config-1.0.15.schema.json +0 -1048
  143. package/dist/schemas/config-1.0.15.schema.test.js +0 -22
  144. package/dist/schemas/config-1.0.2.schema.json +0 -910
  145. package/dist/schemas/config-1.0.3.schema.json +0 -910
  146. package/dist/schemas/config-1.0.4.schema.json +0 -949
  147. package/dist/schemas/config-1.0.5.schema.json +0 -949
  148. package/dist/schemas/config-1.0.6.schema.json +0 -949
  149. package/dist/schemas/config-1.0.7.schema.json +0 -949
  150. package/dist/schemas/config-1.0.8.schema.json +0 -965
  151. package/dist/schemas/config-1.0.9.schema.json +0 -965
  152. package/dist/schemas/obsSets.schema.js +0 -195
  153. package/dist/schemas/obsSetsTabular.schema.js +0 -38
  154. package/dist/schemas/raster.schema.js +0 -120
  155. package/dist/shared-mui/components.js +0 -35
  156. package/dist/shared-mui/container.js +0 -211
  157. package/dist/shared-mui/styles.js +0 -73
  158. package/dist/shared-plot-options/CellColorEncodingOption.js +0 -18
  159. package/dist/shared-plot-options/OptionSelect.js +0 -12
  160. package/dist/shared-plot-options/OptionsContainer.js +0 -12
  161. package/dist/shared-plot-options/styles.js +0 -48
  162. package/dist/state/hooks.js +0 -549
  163. package/dist/view-config-upgraders.js +0 -525
  164. package/dist/view-config-utils.js +0 -286
  165. package/dist/view-config-utils.test.fixtures.js +0 -765
  166. package/dist/view-config-utils.test.js +0 -66
  167. package/dist/view-config-versions.js +0 -47
  168. package/dist/vitessce-grid-layout/VitessceGridLayout.js +0 -95
  169. package/dist/vitessce-grid-layout/VitessceGridLayout.test.js +0 -40
  170. package/dist/vitessce-grid-layout/layout-utils.js +0 -60
  171. package/dist/vitessce-grid-layout/layout-utils.test.js +0 -146
  172. package/dist/vitessce-grid-utils.js +0 -140
@@ -4,7 +4,7 @@ export { PopperMenu } from './shared-mui/components';
4
4
  export { registerPluginViewType, registerPluginCoordinationType, registerPluginFileType, registerPluginJointFileType, } from './plugins';
5
5
  // For plugin view types:
6
6
  export { useReady, useUrls, useVitessceContainer, useDeckCanvasSize, useExpressionValueGetter, useGetObsInfo, useClosestVitessceContainerSize, useWindowDimensions, useGridItemSize, } from './hooks';
7
- export { useCoordination, useMultiDatasetCoordination, useDatasetUids, useLoaders, useMatchingLoader, useViewConfigStore, useViewConfigStoreApi, useComponentHover, useSetComponentHover, useComponentViewInfo, useSetComponentViewInfo, useWarning, useSetWarning, useAuxiliaryCoordination, useComponentLayout, } from './state/hooks';
7
+ export { useCoordination, useComplexCoordination, useMultiCoordinationValues, useMultiDatasetCoordination, useDatasetUids, useLoaders, useMatchingLoader, useViewConfigStore, useViewConfigStoreApi, useComponentHover, useSetComponentHover, useComponentViewInfo, useSetComponentViewInfo, useWarning, useSetWarning, useAuxiliaryCoordination, useComponentLayout, } from './state/hooks';
8
8
  export { useDescription, useImageData, useObsSetsData, useObsEmbeddingData, useFeatureSelection, useObsFeatureMatrixIndices, useMultiObsLabels, useObsLocationsData, useObsSegmentationsData, useNeighborhoodsData, useObsLabelsData, useObsFeatureMatrixData, useFeatureLabelsData, useGenomicProfilesData, } from './data-hooks';
9
9
  export { useHasLoader, } from './data-hook-utils';
10
10
  export { AbstractLoader, AbstractTwoStepLoader, LoaderResult, } from './data/index';
@@ -15,4 +15,4 @@ obsEmbeddingAnndataSchema, obsLocationsAnndataSchema, obsSegmentationsAnndataSch
15
15
  export { SCHEMA_HANDLERS, LATEST_VERSION, } from './view-config-versions';
16
16
  export { upgradeAndValidate, } from './view-config-utils';
17
17
  export { CellColorEncodingOption, OptionsContainer, OptionSelect, usePlotOptionsStyles, } from './shared-plot-options';
18
- export * from './schemas';
18
+ export * from './json-schemas';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/vit-s",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -8,9 +8,10 @@
8
8
  "url": "git+https://github.com/vitessce/vitessce.git"
9
9
  },
10
10
  "license": "MIT",
11
- "main": "dist/index.js",
11
+ "main": "dist/index.mjs",
12
12
  "files": [
13
- "dist"
13
+ "dist",
14
+ "src"
14
15
  ],
15
16
  "dependencies": {
16
17
  "@material-ui/core": "~4.12.3",
@@ -24,8 +25,8 @@
24
25
  "react-grid-layout-with-lodash": "^1.3.5",
25
26
  "uuid": "^3.3.2",
26
27
  "zustand": "^3.5.10",
27
- "@vitessce/constants-internal": "2.0.2",
28
- "@vitessce/utils": "2.0.2"
28
+ "@vitessce/constants-internal": "2.0.3",
29
+ "@vitessce/utils": "2.0.3"
29
30
  },
30
31
  "devDependencies": {
31
32
  "react": "^18.0.0",
@@ -36,8 +37,7 @@
36
37
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
37
38
  },
38
39
  "scripts": {
39
- "start": "tsc --watch",
40
- "build": "tsc",
40
+ "bundle": "pnpm exec vite build -c ../../scripts/vite.config.js",
41
41
  "test": "pnpm exec vitest --run -r ../../ --dir ."
42
42
  }
43
43
  }
@@ -0,0 +1,81 @@
1
+ import { useEffect } from 'react';
2
+ import { SCHEMA_HANDLERS, LATEST_VERSION } from './view-config-versions';
3
+ import { useViewConfigStoreApi, useLoaders, useWarning } from './state/hooks';
4
+
5
+ function validateViewConfig(viewConfig) {
6
+ // Need the try-catch here since Zustand will actually
7
+ // just catch and ignore errors in its subscription callbacks.
8
+ try {
9
+ const validate = SCHEMA_HANDLERS[LATEST_VERSION][0];
10
+ const valid = validate(viewConfig);
11
+ if (!valid) {
12
+ const failureReason = JSON.stringify(validate.errors, null, 2);
13
+ throw new Error(`Config validation failed: ${failureReason}`);
14
+ }
15
+ } catch (e) {
16
+ console.error(e);
17
+ }
18
+ // Do nothing if successful.
19
+ }
20
+
21
+ /**
22
+ * This is a dummy component which handles
23
+ * publishing new view configs and loaders to
24
+ * the provided callbacks on changes.
25
+ * @param {object} props
26
+ * @param {function} props.onConfigChange A callback function
27
+ * to execute on each change of the Vitessce view config.
28
+ * @param {function} props.onLoaderChange A callback function
29
+ * to execute on each change of the loaders object.
30
+ * @param {boolean} props.validateOnConfigChange Whether to validate
31
+ * against the view config schema when publishing changes.
32
+ */
33
+ export default function CallbackPublisher(props) {
34
+ const {
35
+ onWarn,
36
+ onConfigChange,
37
+ onLoaderChange,
38
+ validateOnConfigChange,
39
+ } = props;
40
+
41
+ const warning = useWarning();
42
+ const loaders = useLoaders();
43
+
44
+ const viewConfigStoreApi = useViewConfigStoreApi();
45
+
46
+ // View config updates are often-occurring, so
47
+ // we want to use the "transient update" approach
48
+ // to subscribe to view config changes.
49
+ // Reference: https://github.com/react-spring/zustand#transient-updates-for-often-occuring-state-changes
50
+ useEffect(() => viewConfigStoreApi.subscribe(
51
+ // The function to run on each publish.
52
+ (viewConfig) => {
53
+ if (validateOnConfigChange && viewConfig) {
54
+ validateViewConfig(viewConfig);
55
+ }
56
+ if (onConfigChange && viewConfig) {
57
+ onConfigChange(viewConfig);
58
+ }
59
+ },
60
+ // The function to specify which part of the store
61
+ // we want to subscribe to.
62
+ state => state.viewConfig,
63
+ ), [onConfigChange, validateOnConfigChange, viewConfigStoreApi]);
64
+
65
+ // Emit updates to the warning message.
66
+ useEffect(() => {
67
+ if (onWarn && warning) {
68
+ onWarn(warning);
69
+ }
70
+ }, [warning, onWarn]);
71
+
72
+ // Emit updates to the loaders.
73
+ useEffect(() => {
74
+ if (onLoaderChange && loaders) {
75
+ onLoaderChange(loaders);
76
+ }
77
+ }, [loaders, onLoaderChange]);
78
+
79
+ // Render nothing.
80
+ return null;
81
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { makeStyles } from '@material-ui/core/styles';
3
+ import CircularProgress from '@material-ui/core/CircularProgress';
4
+
5
+ const useStyles = makeStyles(() => ({
6
+ loadingIndicatorBackdrop: {
7
+ position: 'absolute',
8
+ top: '0',
9
+ left: '0',
10
+ zIndex: '1040',
11
+ width: '100%',
12
+ height: '100%',
13
+ borderRadius: '4px',
14
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
15
+ },
16
+ loadingIndicatorContainer: {
17
+ display: 'grid',
18
+ placeItems: 'center',
19
+ position: 'absolute',
20
+ width: '100%',
21
+ height: '100%',
22
+ },
23
+ }));
24
+
25
+ export default function LoadingIndicator() {
26
+ const classes = useStyles();
27
+ return (
28
+ <div className={classes.loadingIndicatorBackdrop}>
29
+ <div className={classes.loadingIndicatorContainer}>
30
+ <CircularProgress />
31
+ </div>
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,240 @@
1
+ import React, { useState } from 'react';
2
+ import clsx from 'clsx';
3
+ import { makeStyles } from '@material-ui/core/styles';
4
+ import CloudDownloadIcon from '@material-ui/icons/CloudDownload';
5
+ import MenuItem from '@material-ui/core/MenuItem';
6
+ import IconButton from '@material-ui/core/IconButton';
7
+ import Link from '@material-ui/core/Link';
8
+ import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
9
+ import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
10
+ import SettingsIcon from '@material-ui/icons/Settings';
11
+ import CloseIcon from '@material-ui/icons/Close';
12
+
13
+ import { TOOLTIP_ANCESTOR } from './classNames';
14
+ import LoadingIndicator from './LoadingIndicator';
15
+ import { PopperMenu } from './shared-mui/components';
16
+
17
+ const useStyles = makeStyles(theme => ({
18
+ iconButton: {
19
+ border: 'none',
20
+ marginLeft: 0,
21
+ background: 'none',
22
+ color: theme.palette.primaryForeground,
23
+ paddingLeft: '0.25em',
24
+ paddingRight: '0.25em',
25
+ borderRadius: '2px',
26
+ '&:hover': {
27
+ backgroundColor: theme.palette.primaryBackgroundLight,
28
+ },
29
+ '&:first-child': {
30
+ marginLeft: '0.25em',
31
+ },
32
+ '&:last-child': {
33
+ marginRight: '0.25em',
34
+ },
35
+ '& svg': {
36
+ width: '0.7em',
37
+ height: '0.7em',
38
+ verticalAlign: 'middle',
39
+ overflow: 'visible',
40
+ },
41
+ },
42
+ downloadLink: {
43
+ color: theme.palette.primaryForeground,
44
+ },
45
+ }));
46
+
47
+ function SettingsIconWithArrow({ open }) {
48
+ return (
49
+ <>
50
+ <SettingsIcon />
51
+ {open ? <ArrowDropUpIcon /> : <ArrowDropDownIcon />}
52
+ </>
53
+ );
54
+ }
55
+
56
+ function PlotOptions(props) {
57
+ const { options } = props;
58
+ const [open, setOpen] = useState(false);
59
+ const classes = useStyles();
60
+ return (options ? (
61
+ <PopperMenu
62
+ open={open}
63
+ setOpen={setOpen}
64
+ buttonIcon={<SettingsIconWithArrow open={open} />}
65
+ buttonClassName={classes.iconButton}
66
+ placement="bottom-end"
67
+ >
68
+ {options}
69
+ </PopperMenu>
70
+ ) : null);
71
+ }
72
+
73
+ function CloudDownloadIconWithArrow({ open }) {
74
+ return (
75
+ <>
76
+ <CloudDownloadIcon />
77
+ {open ? <ArrowDropUpIcon /> : <ArrowDropDownIcon />}
78
+ </>
79
+ );
80
+ }
81
+
82
+ function DownloadOptions(props) {
83
+ const { urls } = props;
84
+ const [open, setOpen] = useState(false);
85
+ const classes = useStyles();
86
+ return (urls && urls.length ? (
87
+ <PopperMenu
88
+ open={open}
89
+ setOpen={setOpen}
90
+ buttonIcon={<CloudDownloadIconWithArrow open={open} />}
91
+ buttonClassName={classes.iconButton}
92
+ placement="bottom-end"
93
+ >
94
+ {urls.map(({ url, name }) => (
95
+ <MenuItem dense key={`${url}_${name}`}>
96
+ <Link underline="none" href={url} target="_blank" rel="noopener" className={classes.downloadLink}>
97
+ Download {name}
98
+ </Link>
99
+ </MenuItem>
100
+ ))}
101
+ </PopperMenu>
102
+ ) : null);
103
+ }
104
+
105
+ function ClosePaneButton(props) {
106
+ const { removeGridComponent } = props;
107
+ const classes = useStyles();
108
+ return (
109
+ <IconButton
110
+ onClick={removeGridComponent}
111
+ size="small"
112
+ className={classes.iconButton}
113
+ title="close"
114
+ >
115
+ <CloseIcon />
116
+ </IconButton>
117
+ );
118
+ }
119
+
120
+ export const useTitleStyles = makeStyles(theme => ({
121
+ title: {
122
+ color: theme.palette.primaryForeground,
123
+ overflowX: 'hidden',
124
+ display: 'flex',
125
+ flexDirection: 'row',
126
+ flexShrink: '0',
127
+ },
128
+ titleLeft: {
129
+ flexShrink: '1',
130
+ textOverflow: 'ellipsis',
131
+ whiteSpace: 'nowrap',
132
+ },
133
+ titleInfo: {
134
+ width: '100%',
135
+ textOverflow: 'ellipsis',
136
+ whiteSpace: 'nowrap',
137
+ overflow: 'hidden',
138
+ fontSize: '80% !important',
139
+ opacity: '.8',
140
+ padding: '0 4px',
141
+ justifyContent: 'center',
142
+ lineHeight: '25px !important',
143
+ flexShrink: '1',
144
+ textAlign: 'right !important',
145
+ },
146
+ titleButtons: {
147
+ display: 'flex',
148
+ flexDirection: 'row',
149
+ flexGrow: '1',
150
+ flexShrink: '0',
151
+ justifyContent: 'right',
152
+ '& div': {
153
+ display: 'inline-block',
154
+ },
155
+ },
156
+ card: {
157
+ border: `1px solid ${theme.palette.cardBorder}`,
158
+ flex: '1 1 auto',
159
+ minHeight: '1px',
160
+ padding: '12px',
161
+ marginTop: '8px',
162
+ marginBottom: '8px',
163
+ position: 'relative',
164
+ display: 'flex',
165
+ flexDirection: 'column',
166
+ minWidth: '0',
167
+ wordWrap: 'break-word',
168
+ backgroundClip: 'border-box',
169
+ borderRadius: '4px',
170
+ },
171
+ noScrollCard: {
172
+ backgroundColor: theme.palette.secondaryBackground,
173
+ color: theme.palette.secondaryForeground,
174
+ },
175
+ scrollCard: {
176
+ backgroundColor: theme.palette.primaryBackground,
177
+ color: theme.palette.primaryForeground,
178
+ '& a': {
179
+ color: theme.palette.primaryForegroundActive,
180
+ },
181
+ overflowY: 'auto',
182
+ },
183
+ spatialCard: {
184
+ backgroundColor: theme.palette.black,
185
+ color: theme.palette.white,
186
+ '& a': {
187
+ color: theme.palette.white,
188
+ },
189
+ },
190
+ }));
191
+
192
+
193
+ export function TitleInfo(props) {
194
+ const {
195
+ title, info, children, isScroll, isSpatial, removeGridComponent, urls,
196
+ isReady, options,
197
+ } = props;
198
+
199
+ const classes = useTitleStyles();
200
+
201
+ return (
202
+ // d-flex without wrapping div is not always full height; I don't understand the root cause.
203
+ <>
204
+ <div className={classes.title}>
205
+ <div className={classes.titleLeft}>
206
+ {title}
207
+ </div>
208
+ <div className={classes.titleInfo} title={info}>
209
+ {info}
210
+ </div>
211
+ <div className={classes.titleButtons}>
212
+ <PlotOptions
213
+ options={options}
214
+ />
215
+ <DownloadOptions
216
+ urls={urls}
217
+ />
218
+ <ClosePaneButton
219
+ removeGridComponent={removeGridComponent}
220
+ />
221
+ </div>
222
+ </div>
223
+ <div
224
+ className={clsx(
225
+ TOOLTIP_ANCESTOR,
226
+ classes.card,
227
+ {
228
+ [classes.scrollCard]: isScroll,
229
+ [classes.spatialCard]: isSpatial,
230
+ [classes.noScrollCard]: !isScroll && !isSpatial,
231
+ },
232
+ )}
233
+ >
234
+ { !isReady && <LoadingIndicator /> }
235
+ {children}
236
+ </div>
237
+ </>
238
+ // "pl-2" only matters when the window is very narrow.
239
+ );
240
+ }
package/src/VitS.js ADDED
@@ -0,0 +1,180 @@
1
+ /* eslint-disable camelcase */
2
+ import React, { useEffect, useMemo } from 'react';
3
+ import {
4
+ ThemeProvider,
5
+ StylesProvider,
6
+ createGenerateClassName,
7
+ } from '@material-ui/core/styles';
8
+ import isEqual from 'lodash/isEqual';
9
+ import { META_VERSION } from '@vitessce/constants-internal';
10
+ import { muiTheme } from './shared-mui/styles';
11
+ import {
12
+ ViewConfigProvider,
13
+ createViewConfigStore,
14
+ AuxiliaryProvider,
15
+ createAuxiliaryStore,
16
+ } from './state/hooks';
17
+
18
+ import VitessceGrid from './VitessceGrid';
19
+ import { Warning } from './Warning';
20
+ import CallbackPublisher from './CallbackPublisher';
21
+ import { getComponent } from './component-registry';
22
+ import {
23
+ checkTypes,
24
+ initialize,
25
+ upgradeAndValidate,
26
+ } from './view-config-utils';
27
+
28
+ function logConfig(config, name) {
29
+ console.groupCollapsed(`🚄 Vitessce (${META_VERSION.version}) ${name}`);
30
+ console.info(`data:,${JSON.stringify(config)}`);
31
+ console.info(JSON.stringify(config, null, 2));
32
+ console.groupEnd();
33
+ }
34
+
35
+ /**
36
+ * The Vitessce component.
37
+ * @param {object} props
38
+ * @param {object} props.config A Vitessce view config.
39
+ * If the config is valid, the VitessceGrid will be rendered as a child.
40
+ * If the config is invalid, a Warning will be rendered instead.
41
+ * @param {number} props.rowHeight Row height for grid layout. Optional.
42
+ * @param {number} props.height Total height for grid layout. Optional.
43
+ * @param {string} props.theme The theme, used for styling as
44
+ * light or dark. Optional. By default, "dark"
45
+ * @param {function} props.onWarn A callback for warning messages. Optional.
46
+ * @param {function} props.onConfigChange A callback for view config
47
+ * updates. Optional.
48
+ * @param {function} props.onLoaderChange A callback for loader
49
+ * updates. Optional.
50
+ * @param {boolean} props.validateOnConfigChange Whether to validate
51
+ * against the view config schema when publishing changes. Use for debugging
52
+ * purposes, as this may have a performance impact. By default, false.
53
+ * @param {undefined|string} props.uid A unique identifier for this Vitessce instance,
54
+ * for the purpose of avoiding CSS autogenerated class name conflicts. Must be valid as part
55
+ * of a CSS class name string.
56
+ */
57
+ export function VitS(props) {
58
+ const {
59
+ config,
60
+ rowHeight,
61
+ height,
62
+ theme,
63
+ onWarn,
64
+ onConfigChange,
65
+ onLoaderChange,
66
+ validateOnConfigChange = false,
67
+ onConfigUpgrade,
68
+ isBounded = false,
69
+ uid,
70
+ } = props;
71
+
72
+ const generateClassName = useMemo(() => createGenerateClassName({
73
+ disableGlobal: false, // Class names need to be deterministic
74
+ // Avoid conflicts with portal-ui MUI class names,
75
+ // and allow setting a UID.
76
+ productionPrefix: (uid ? `vit${uid}` : 'vit'),
77
+ }), [uid]);
78
+
79
+ // Process the view config and memoize the result:
80
+ // - Validate.
81
+ // - Upgrade, if legacy schema.
82
+ // - Validate after upgrade, if legacy schema.
83
+ // - Initialize (based on initStrategy).
84
+ const [configOrWarning, success] = useMemo(() => {
85
+ // If the config value is undefined, show a warning message.
86
+ if (!config) {
87
+ return [
88
+ {
89
+ title: 'No such dataset',
90
+ unformatted: 'The dataset configuration could not be found.',
91
+ },
92
+ false,
93
+ ];
94
+ }
95
+ // If the view config is missing a version, show a warning message.
96
+ if (!config.version) {
97
+ return [
98
+ {
99
+ title: 'Missing version',
100
+ unformatted:
101
+ 'The dataset configuration is missing a version, preventing validation.',
102
+ },
103
+ false,
104
+ ];
105
+ }
106
+ logConfig(config, 'input view config');
107
+ // Check if this is a "legacy" view config.
108
+ const [upgradedConfig, upgradeSuccess] = upgradeAndValidate(
109
+ config,
110
+ onConfigUpgrade,
111
+ );
112
+ if (upgradeSuccess) {
113
+ logConfig(upgradedConfig, 'upgraded view config');
114
+ // Initialize the view config according to the initStrategy.
115
+ const [typeCheckSuccess, typeCheckMessage] = checkTypes(upgradedConfig);
116
+ if (typeCheckSuccess) {
117
+ try {
118
+ const initializedConfig = initialize(upgradedConfig);
119
+ logConfig(initializedConfig, 'initialized view config');
120
+ return [initializedConfig, true];
121
+ } catch (e) {
122
+ return [
123
+ {
124
+ title: 'View config initialization failed.',
125
+ unformatted: e.message,
126
+ },
127
+ false,
128
+ ];
129
+ }
130
+ }
131
+ return [
132
+ {
133
+ title: 'View config checks failed.',
134
+ unformatted: typeCheckMessage,
135
+ },
136
+ false,
137
+ ];
138
+ }
139
+ return [upgradedConfig, false];
140
+ }, [config, onConfigUpgrade]);
141
+
142
+ // Emit the upgraded/initialized view config
143
+ // to onConfigChange if necessary.
144
+ useEffect(() => {
145
+ if (success && !isEqual(configOrWarning, config) && onConfigChange) {
146
+ onConfigChange(configOrWarning);
147
+ }
148
+ }, [success, config, configOrWarning, onConfigChange]);
149
+
150
+ return success ? (
151
+ <StylesProvider generateClassName={generateClassName}>
152
+ <ThemeProvider theme={muiTheme[theme]}>
153
+ <ViewConfigProvider createStore={createViewConfigStore}>
154
+ <AuxiliaryProvider createStore={createAuxiliaryStore}>
155
+ <VitessceGrid
156
+ config={configOrWarning}
157
+ getComponent={getComponent}
158
+ rowHeight={rowHeight}
159
+ height={height}
160
+ theme={theme}
161
+ isBounded={isBounded}
162
+ />
163
+ <CallbackPublisher
164
+ onWarn={onWarn}
165
+ onConfigChange={onConfigChange}
166
+ onLoaderChange={onLoaderChange}
167
+ validateOnConfigChange={validateOnConfigChange}
168
+ />
169
+ </AuxiliaryProvider>
170
+ </ViewConfigProvider>
171
+ </ThemeProvider>
172
+ </StylesProvider>
173
+ ) : (
174
+ <StylesProvider generateClassName={generateClassName}>
175
+ <ThemeProvider theme={muiTheme[theme]}>
176
+ <Warning {...configOrWarning} />
177
+ </ThemeProvider>
178
+ </StylesProvider>
179
+ );
180
+ }
@@ -0,0 +1,110 @@
1
+ import React, {
2
+ useEffect,
3
+ useCallback,
4
+ } from 'react';
5
+ import clsx from 'clsx';
6
+ import { VITESSCE_CONTAINER } from './classNames';
7
+ import { VitessceGridLayout } from './vitessce-grid-layout';
8
+ import { useRowHeight, createLoaders } from './vitessce-grid-utils';
9
+ import {
10
+ useViewConfigStoreApi,
11
+ useSetViewConfig,
12
+ useSetLoaders,
13
+ useEmitGridResize,
14
+ useRemoveComponent,
15
+ useChangeLayout,
16
+ useLayout,
17
+ } from './state/hooks';
18
+ import {
19
+ useClosestVitessceContainerSize,
20
+ } from './hooks';
21
+ import { useVitessceContainerStyles } from './shared-mui/container';
22
+ import { useTitleStyles } from './TitleInfo';
23
+
24
+ const padding = 10;
25
+ const margin = 5;
26
+
27
+ /**
28
+ * The wrapper for the VitessceGrid and LoadingIndicator components.
29
+ * @param {object} props
30
+ * @param {number} props.rowHeight The height of each grid row. Optional.
31
+ * @param {object} props.config The view config.
32
+ * @param {function} props.getComponent A function that maps component names to their
33
+ * React counterparts.
34
+ * @param {string} props.theme The theme name.
35
+ * @param {number} props.height Total height for grid. Optional.
36
+ * @param {function} props.onWarn A callback for warning messages. Optional.
37
+ */
38
+ export default function VitessceGrid(props) {
39
+ const {
40
+ rowHeight: initialRowHeight,
41
+ config,
42
+ getComponent,
43
+ theme,
44
+ height,
45
+ isBounded,
46
+ } = props;
47
+
48
+ const [rowHeight, containerRef] = useRowHeight(config, initialRowHeight, height, margin, padding);
49
+ const onResize = useEmitGridResize();
50
+
51
+ const [componentWidth] = useClosestVitessceContainerSize(containerRef);
52
+
53
+ const classes = useVitessceContainerStyles();
54
+ const titleClasses = useTitleStyles();
55
+
56
+ // When the row height has changed, publish a GRID_RESIZE event.
57
+ useEffect(() => {
58
+ onResize();
59
+ }, [rowHeight, onResize]);
60
+
61
+ const viewConfigStoreApi = useViewConfigStoreApi();
62
+ const setViewConfig = useSetViewConfig(viewConfigStoreApi);
63
+ const setLoaders = useSetLoaders();
64
+ const removeComponent = useRemoveComponent();
65
+ const changeLayout = useChangeLayout();
66
+ const layout = useLayout();
67
+
68
+ const changeLayoutPostMount = useCallback((newComponentProps) => {
69
+ if (componentWidth > 0) {
70
+ changeLayout(newComponentProps);
71
+ }
72
+ }, [changeLayout, componentWidth]);
73
+
74
+ // Update the view config and loaders in the global state.
75
+ useEffect(() => {
76
+ if (config) {
77
+ setViewConfig(config);
78
+ const loaders = createLoaders(config.datasets, config.description);
79
+ setLoaders(loaders);
80
+ } else {
81
+ // No config found, so clear the loaders.
82
+ setLoaders({});
83
+ }
84
+ }, [config, setViewConfig, setLoaders]);
85
+
86
+ return (
87
+ <div
88
+ ref={containerRef}
89
+ className={clsx(VITESSCE_CONTAINER, classes.vitessceContainer)}
90
+ >
91
+ {layout && (
92
+ <VitessceGridLayout
93
+ layout={layout}
94
+ height={height}
95
+ rowHeight={rowHeight}
96
+ theme={theme}
97
+ getComponent={getComponent}
98
+ draggableHandle={titleClasses.title}
99
+ margin={margin}
100
+ padding={padding}
101
+ onRemoveComponent={removeComponent}
102
+ onLayoutChange={changeLayoutPostMount}
103
+ isBounded={isBounded}
104
+ onResize={onResize}
105
+ onResizeStop={onResize}
106
+ />
107
+ )}
108
+ </div>
109
+ );
110
+ }