@vitessce/vit-s 2.0.3-beta.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +41348 -18
- package/dist-tsc/CallbackPublisher.d.ts +18 -0
- package/dist-tsc/CallbackPublisher.d.ts.map +1 -0
- package/{dist → dist-tsc}/CallbackPublisher.js +6 -12
- package/dist-tsc/LoadingIndicator.d.ts +2 -0
- package/dist-tsc/LoadingIndicator.d.ts.map +1 -0
- package/{dist → dist-tsc}/LoadingIndicator.js +1 -2
- package/dist-tsc/TitleInfo.d.ts +2 -0
- package/dist-tsc/TitleInfo.d.ts.map +1 -0
- package/{dist → dist-tsc}/TitleInfo.js +6 -83
- package/dist-tsc/VitS.d.ts +45 -0
- package/dist-tsc/VitS.d.ts.map +1 -0
- package/dist-tsc/VitS.js +119 -0
- package/dist-tsc/VitessceGrid.d.ts +23 -0
- package/dist-tsc/VitessceGrid.d.ts.map +1 -0
- package/{dist → dist-tsc}/VitessceGrid.js +14 -13
- package/dist-tsc/VitessceGrid.test.d.ts +2 -0
- package/dist-tsc/VitessceGrid.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/VitessceGrid.test.js +8 -4
- package/dist-tsc/Warning.d.ts +2 -0
- package/dist-tsc/Warning.d.ts.map +1 -0
- package/{dist → dist-tsc}/Warning.js +2 -2
- package/dist-tsc/classNames.d.ts +8 -0
- package/dist-tsc/classNames.d.ts.map +1 -0
- package/dist-tsc/data/AbstractLoader.d.ts +22 -0
- package/dist-tsc/data/AbstractLoader.d.ts.map +1 -0
- package/dist-tsc/data/AbstractLoader.js +18 -0
- package/dist-tsc/data/AbstractTwoStepLoader.d.ts +6 -0
- package/dist-tsc/data/AbstractTwoStepLoader.d.ts.map +1 -0
- package/{dist → dist-tsc}/data/AbstractTwoStepLoader.js +1 -1
- package/dist-tsc/data/LoaderResult.d.ts +7 -0
- package/dist-tsc/data/LoaderResult.d.ts.map +1 -0
- package/dist-tsc/data/index.d.ts +4 -0
- package/dist-tsc/data/index.d.ts.map +1 -0
- package/dist-tsc/data/index.js +3 -0
- package/dist-tsc/data/loader-registry.d.ts +9 -0
- package/dist-tsc/data/loader-registry.d.ts.map +1 -0
- package/dist-tsc/data/loader-registry.js +27 -0
- package/dist-tsc/data-hook-utils.d.ts +69 -0
- package/dist-tsc/data-hook-utils.d.ts.map +1 -0
- package/{dist → dist-tsc}/data-hook-utils.js +4 -6
- package/dist-tsc/data-hooks.d.ts +77 -0
- package/dist-tsc/data-hooks.d.ts.map +1 -0
- package/{dist → dist-tsc}/data-hooks.js +4 -4
- package/dist-tsc/errors/AbstractLoaderError.d.ts +10 -0
- package/dist-tsc/errors/AbstractLoaderError.d.ts.map +1 -0
- package/dist-tsc/errors/DataSourceFetchError.d.ts +8 -0
- package/dist-tsc/errors/DataSourceFetchError.d.ts.map +1 -0
- package/{dist → dist-tsc}/errors/DataSourceFetchError.js +1 -1
- package/dist-tsc/errors/DatasetNotFoundError.d.ts +6 -0
- package/dist-tsc/errors/DatasetNotFoundError.d.ts.map +1 -0
- package/{dist → dist-tsc}/errors/DatasetNotFoundError.js +1 -1
- package/dist-tsc/errors/LoaderNotFoundError.d.ts +10 -0
- package/dist-tsc/errors/LoaderNotFoundError.d.ts.map +1 -0
- package/{dist → dist-tsc}/errors/LoaderNotFoundError.js +1 -1
- package/dist-tsc/errors/LoaderValidationError.d.ts +10 -0
- package/dist-tsc/errors/LoaderValidationError.d.ts.map +1 -0
- package/{dist → dist-tsc}/errors/LoaderValidationError.js +1 -1
- package/dist-tsc/errors/index.d.ts +6 -0
- package/dist-tsc/errors/index.d.ts.map +1 -0
- package/{dist → dist-tsc}/errors/index.js +5 -6
- package/dist-tsc/hooks.d.ts +80 -0
- package/dist-tsc/hooks.d.ts.map +1 -0
- package/{dist → dist-tsc}/hooks.js +60 -4
- package/dist-tsc/index.d.ts +11 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +11 -0
- package/dist-tsc/plugins.test.fixtures.d.ts +61 -0
- package/dist-tsc/plugins.test.fixtures.d.ts.map +1 -0
- package/{dist → dist-tsc}/schemas/config-1.0.16.schema.json +21 -41
- package/dist-tsc/schemas/obsSets.schema.d.ts +179 -0
- package/dist-tsc/schemas/obsSets.schema.d.ts.map +1 -0
- package/dist-tsc/schemas/obsSetsTabular.schema.d.ts +57 -0
- package/dist-tsc/schemas/obsSetsTabular.schema.d.ts.map +1 -0
- package/dist-tsc/schemas/raster.schema.d.ts +239 -0
- package/dist-tsc/schemas/raster.schema.d.ts.map +1 -0
- package/dist-tsc/shared-mui/components.d.ts +2 -0
- package/dist-tsc/shared-mui/components.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-mui/components.js +2 -8
- package/dist-tsc/shared-mui/container.d.ts +2 -0
- package/dist-tsc/shared-mui/container.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-mui/container.js +1 -1
- package/dist-tsc/shared-mui/styles.d.ts +5 -0
- package/dist-tsc/shared-mui/styles.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-mui/styles.js +4 -2
- package/dist-tsc/shared-plot-options/CellColorEncodingOption.d.ts +2 -0
- package/dist-tsc/shared-plot-options/CellColorEncodingOption.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-plot-options/CellColorEncodingOption.js +3 -4
- package/dist-tsc/shared-plot-options/OptionSelect.d.ts +2 -0
- package/dist-tsc/shared-plot-options/OptionSelect.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-plot-options/OptionSelect.js +2 -2
- package/dist-tsc/shared-plot-options/OptionsContainer.d.ts +2 -0
- package/dist-tsc/shared-plot-options/OptionsContainer.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-plot-options/OptionsContainer.js +2 -5
- package/dist-tsc/shared-plot-options/index.d.ts +5 -0
- package/dist-tsc/shared-plot-options/index.d.ts.map +1 -0
- package/dist-tsc/shared-plot-options/index.js +4 -0
- package/dist-tsc/shared-plot-options/styles.d.ts +2 -0
- package/dist-tsc/shared-plot-options/styles.d.ts.map +1 -0
- package/{dist → dist-tsc}/shared-plot-options/styles.js +1 -1
- package/dist-tsc/state/hooks.d.ts +216 -0
- package/dist-tsc/state/hooks.d.ts.map +1 -0
- package/{dist → dist-tsc}/state/hooks.js +47 -21
- package/dist-tsc/title-styles.d.ts +2 -0
- package/dist-tsc/title-styles.d.ts.map +1 -0
- package/dist-tsc/title-styles.js +72 -0
- package/dist-tsc/view-config-utils.d.ts +30 -0
- package/dist-tsc/view-config-utils.d.ts.map +1 -0
- package/{dist → dist-tsc}/view-config-utils.js +32 -84
- package/dist-tsc/view-config-utils.test.d.ts +2 -0
- package/dist-tsc/view-config-utils.test.d.ts.map +1 -0
- package/dist-tsc/view-config-utils.test.fixtures.d.ts +1049 -0
- package/dist-tsc/view-config-utils.test.fixtures.d.ts.map +1 -0
- package/{dist → dist-tsc}/view-config-utils.test.fixtures.js +118 -0
- package/dist-tsc/view-config-utils.test.js +209 -0
- package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts +8 -0
- package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts.map +1 -0
- package/{dist → dist-tsc}/vitessce-grid-layout/VitessceGridLayout.js +47 -28
- package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.d.ts +2 -0
- package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/vitessce-grid-layout/VitessceGridLayout.test.js +13 -5
- package/dist-tsc/vitessce-grid-layout/index.d.ts +2 -0
- package/dist-tsc/vitessce-grid-layout/index.d.ts.map +1 -0
- package/dist-tsc/vitessce-grid-layout/index.js +1 -0
- package/dist-tsc/vitessce-grid-layout/layout-utils.d.ts +15 -0
- package/dist-tsc/vitessce-grid-layout/layout-utils.d.ts.map +1 -0
- package/{dist → dist-tsc}/vitessce-grid-layout/layout-utils.js +2 -1
- package/dist-tsc/vitessce-grid-layout/layout-utils.test.d.ts +2 -0
- package/dist-tsc/vitessce-grid-layout/layout-utils.test.d.ts.map +1 -0
- package/{dist → dist-tsc}/vitessce-grid-layout/layout-utils.test.js +3 -1
- package/dist-tsc/vitessce-grid-utils.d.ts +13 -0
- package/dist-tsc/vitessce-grid-utils.d.ts.map +1 -0
- package/{dist → dist-tsc}/vitessce-grid-utils.js +15 -14
- package/package.json +24 -11
- package/src/CallbackPublisher.js +77 -0
- package/src/LoadingIndicator.js +33 -0
- package/src/TitleInfo.js +167 -0
- package/src/VitS.js +202 -0
- package/src/VitessceGrid.js +118 -0
- package/src/VitessceGrid.test.jsx +57 -0
- package/src/Warning.js +62 -0
- package/src/classNames.js +8 -0
- package/src/data/AbstractLoader.js +23 -0
- package/src/data/AbstractTwoStepLoader.js +8 -0
- package/src/data/LoaderResult.js +8 -0
- package/src/data/index.js +3 -0
- package/src/data/loader-registry.js +28 -0
- package/src/data-hook-utils.js +195 -0
- package/src/data-hooks.js +354 -0
- package/src/errors/AbstractLoaderError.js +14 -0
- package/src/errors/DataSourceFetchError.js +15 -0
- package/src/errors/DatasetNotFoundError.js +23 -0
- package/src/errors/LoaderNotFoundError.js +24 -0
- package/src/errors/LoaderValidationError.js +23 -0
- package/src/errors/index.js +5 -0
- package/src/hooks.js +317 -0
- package/src/index.js +76 -0
- package/src/plugins.test.fixtures.js +78 -0
- package/src/schemas/config-0.1.0.schema.json +85 -0
- package/src/schemas/config-1.0.0.schema.json +733 -0
- package/src/schemas/config-1.0.1.schema.json +909 -0
- package/src/schemas/config-1.0.10.schema.json +969 -0
- package/src/schemas/config-1.0.11.schema.json +990 -0
- package/src/schemas/config-1.0.12.schema.json +997 -0
- package/src/schemas/config-1.0.13.schema.json +1013 -0
- package/src/schemas/config-1.0.14.schema.json +1048 -0
- package/src/schemas/config-1.0.15.schema.json +1048 -0
- package/src/schemas/config-1.0.16.schema.json +1089 -0
- package/src/schemas/config-1.0.2.schema.json +911 -0
- package/src/schemas/config-1.0.3.schema.json +911 -0
- package/src/schemas/config-1.0.4.schema.json +949 -0
- package/src/schemas/config-1.0.5.schema.json +949 -0
- package/src/schemas/config-1.0.6.schema.json +950 -0
- package/src/schemas/config-1.0.7.schema.json +950 -0
- package/src/schemas/config-1.0.8.schema.json +966 -0
- package/src/schemas/config-1.0.9.schema.json +965 -0
- package/src/schemas/fixtures/cellSets.good.json +16 -0
- package/src/schemas/fixtures/config-1.0.1.bad.json +1 -0
- package/src/schemas/fixtures/config-1.0.1.bad.message.json +11 -0
- package/src/schemas/fixtures/config-1.0.1.good.json +37 -0
- package/src/schemas/fixtures/config-1.0.2.bad.json +1 -0
- package/src/schemas/fixtures/config-1.0.2.bad.message.json +11 -0
- package/src/schemas/fixtures/config-1.0.2.good.json +38 -0
- package/src/schemas/fixtures/config-1.0.3.bad.json +1 -0
- package/src/schemas/fixtures/config-1.0.3.bad.message.json +11 -0
- package/src/schemas/fixtures/config-1.0.3.good.json +38 -0
- package/src/schemas/fixtures/obsSets.bad.json +1 -0
- package/src/schemas/fixtures/obsSets.bad.message.json +11 -0
- package/src/schemas/fixtures/obsSets.good.json +16 -0
- package/src/schemas/fixtures/obsSetsTabular.bad.json +1 -0
- package/src/schemas/fixtures/obsSetsTabular.bad.message.json +11 -0
- package/src/schemas/fixtures/obsSetsTabular.good.json +26 -0
- package/src/schemas/fixtures/raster.bad.json +1 -0
- package/src/schemas/fixtures/raster.bad.message.json +11 -0
- package/src/schemas/fixtures/raster.good.json +39 -0
- package/src/schemas/obsSets.schema.js +195 -0
- package/src/schemas/obsSetsTabular.schema.js +39 -0
- package/src/schemas/raster.schema.js +121 -0
- package/src/schemas/schema-schema.sh +34 -0
- package/src/shared-mui/components.js +81 -0
- package/src/shared-mui/container.js +212 -0
- package/src/shared-mui/styles.js +113 -0
- package/src/shared-plot-options/CellColorEncodingOption.js +42 -0
- package/src/shared-plot-options/OptionSelect.js +19 -0
- package/src/shared-plot-options/OptionsContainer.js +23 -0
- package/src/shared-plot-options/index.js +4 -0
- package/src/shared-plot-options/styles.js +49 -0
- package/src/state/hooks.js +640 -0
- package/src/title-styles.js +73 -0
- package/src/view-config-utils.js +263 -0
- package/src/view-config-utils.test.fixtures.js +893 -0
- package/src/view-config-utils.test.jsx +222 -0
- package/src/vitessce-grid-layout/VitessceGridLayout.js +179 -0
- package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +64 -0
- package/src/vitessce-grid-layout/index.js +1 -0
- package/src/vitessce-grid-layout/layout-utils.js +76 -0
- package/src/vitessce-grid-layout/layout-utils.test.js +167 -0
- package/src/vitessce-grid-utils.js +172 -0
- package/dist/VitS.js +0 -117
- package/dist/Vitessce.integration.test.js +0 -36
- package/dist/Vitessce.js +0 -101
- package/dist/component-registry.js +0 -16
- package/dist/data/AbstractLoader.js +0 -35
- package/dist/data/index.js +0 -3
- package/dist/data/loader-registry.js +0 -15
- package/dist/errors/OptionsValidationError.js +0 -15
- package/dist/export-utils.js +0 -70
- package/dist/export-utils.test.js +0 -66
- package/dist/file-options-schemas-legacy.js +0 -136
- package/dist/file-options-schemas-legacy.test.js +0 -126
- package/dist/file-options-schemas.js +0 -322
- package/dist/file-options-schemas.test.js +0 -23
- package/dist/joint-file-types-legacy.js +0 -278
- package/dist/joint-file-types-legacy.test.js +0 -400
- package/dist/joint-file-types.js +0 -148
- package/dist/joint-file-types.test.js +0 -139
- package/dist/loader-registry.js +0 -98
- package/dist/plugins.js +0 -154
- package/dist/plugins.test.js +0 -30
- package/dist/schemas/PrettyJsonSchema.js +0 -34
- package/dist/schemas/config-1.0.15.schema.test.js +0 -22
- package/dist/schemas/config-1.0.16.schema.test.js +0 -22
- package/dist/schemas/obs-sets-tabular.schema.js +0 -37
- package/dist/schemas/obs-sets.schema.js +0 -194
- package/dist/schemas/schema.test-old.js +0 -50
- package/dist/schemas/schema.test.js +0 -46
- package/dist/schemas-extra.js +0 -3
- package/dist/schemas.js +0 -4
- package/dist/shared-plot-options/index.js +0 -4
- package/dist/view-config-upgraders.js +0 -525
- package/dist/view-config-utils.test.js +0 -66
- package/dist/view-config-versions.js +0 -47
- package/dist/vitessce-grid-layout/index.js +0 -1
- /package/{dist → dist-tsc}/classNames.js +0 -0
- /package/{dist → dist-tsc}/data/LoaderResult.js +0 -0
- /package/{dist → dist-tsc}/errors/AbstractLoaderError.js +0 -0
- /package/{dist → dist-tsc}/plugins.test.fixtures.js +0 -0
- /package/{dist → dist-tsc}/schemas/config-0.1.0.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.0.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.1.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.10.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.11.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.12.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.13.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.14.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.15.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.2.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.3.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.4.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.5.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.6.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.7.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.8.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/config-1.0.9.schema.json +0 -0
- /package/{dist → dist-tsc}/schemas/obsSets.schema.js +0 -0
- /package/{dist → dist-tsc}/schemas/obsSetsTabular.schema.js +0 -0
- /package/{dist → dist-tsc}/schemas/raster.schema.js +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState, useEffect, useRef,
|
|
3
|
+
} from 'react';
|
|
4
|
+
import { InternMap } from 'internmap';
|
|
5
|
+
import { isEqual, pick } from 'lodash-es';
|
|
6
|
+
import { fromEntries } from '@vitessce/utils';
|
|
7
|
+
import { DATA_TYPE_COORDINATION_VALUE_USAGE } from '@vitessce/constants-internal';
|
|
8
|
+
import { getSourceAndLoaderFromFileType, getDataTypeFromFileType } from './data/loader-registry.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Return the bottom coordinate of the layout.
|
|
12
|
+
* https://github.com/STRML/react-grid-layout/blob/20dac73f91274526034c00968b5bedb9c2ed36b9/lib/utils.js#L82
|
|
13
|
+
* @param {array} layout react-grid-layout layout array.
|
|
14
|
+
* @returns {number} Bottom coordinate.
|
|
15
|
+
*/
|
|
16
|
+
function getNumRows(layout) {
|
|
17
|
+
let max = 0;
|
|
18
|
+
let bottomY;
|
|
19
|
+
// eslint-disable-next-line no-plusplus
|
|
20
|
+
for (let i = 0, len = layout.length; i < len; i++) {
|
|
21
|
+
bottomY = layout[i].y + layout[i].h;
|
|
22
|
+
if (bottomY > max) max = bottomY;
|
|
23
|
+
}
|
|
24
|
+
return max;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compute the row height based on the container height, number of rows,
|
|
29
|
+
* and margin/padding. Basically the reverse of the react-grid-layout's
|
|
30
|
+
* `.containerHeight()` function.
|
|
31
|
+
* https://github.com/STRML/react-grid-layout/blob/83251e5e682abfa3252ff89d4bacf47fdc1f4270/lib/ReactGridLayout.jsx#L223
|
|
32
|
+
* @param {number} containerHeight The height of the .vitessce-container element.
|
|
33
|
+
* @param {number} numRows The number of rows in the layout.
|
|
34
|
+
* @param {number} margin The margin value that will be passed to VitessceGrid.
|
|
35
|
+
* @param {number} padding The padding value that will be passed to VitessceGrid.
|
|
36
|
+
* @returns {number} The new row height value.
|
|
37
|
+
*/
|
|
38
|
+
function getRowHeight(containerHeight, numRows, margin, padding) {
|
|
39
|
+
const effectiveContainerHeight = containerHeight - 2 * padding - (numRows - 1) * margin;
|
|
40
|
+
return effectiveContainerHeight / numRows;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useRowHeight(config, initialRowHeight, height, margin, padding) {
|
|
44
|
+
const [containerHeight, setContainerHeight] = useState(height);
|
|
45
|
+
const [rowHeight, setRowHeight] = useState(initialRowHeight);
|
|
46
|
+
const containerRef = useRef();
|
|
47
|
+
|
|
48
|
+
// Detect when the `config` or `containerHeight` variables
|
|
49
|
+
// have changed, and update `rowHeight` in response.
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const numRows = getNumRows(config.layout);
|
|
52
|
+
const newRowHeight = getRowHeight(containerHeight, numRows, margin, padding);
|
|
53
|
+
setRowHeight(newRowHeight);
|
|
54
|
+
}, [containerHeight, config, margin, padding]);
|
|
55
|
+
|
|
56
|
+
// Update the `containerHeight` state when the `height` prop has changed.
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (height !== null && height !== undefined) {
|
|
59
|
+
setContainerHeight(height);
|
|
60
|
+
}
|
|
61
|
+
}, [height]);
|
|
62
|
+
|
|
63
|
+
// If no height prop has been provided, set the `containerHeight`
|
|
64
|
+
// using height of the `.vitessce-container` element.
|
|
65
|
+
// Check the container element height whenever the window has been
|
|
66
|
+
// resized, as it may change if `.vitessce-container` should be
|
|
67
|
+
// sized relative to its parent (and by extension, potentially the window).
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (height !== null && height !== undefined) {
|
|
70
|
+
// eslint will complain if the return value is inconsistent,
|
|
71
|
+
// so return a no-op function.
|
|
72
|
+
return () => {};
|
|
73
|
+
}
|
|
74
|
+
function onWindowResize() {
|
|
75
|
+
if (!containerRef.current) return;
|
|
76
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
77
|
+
setContainerHeight(containerRect.height);
|
|
78
|
+
}
|
|
79
|
+
window.addEventListener('resize', onWindowResize);
|
|
80
|
+
onWindowResize();
|
|
81
|
+
return () => {
|
|
82
|
+
window.removeEventListener('resize', onWindowResize);
|
|
83
|
+
};
|
|
84
|
+
}, [containerRef, height]);
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
return [rowHeight, containerRef];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function withDefaults(
|
|
91
|
+
coordinationValues,
|
|
92
|
+
dataType,
|
|
93
|
+
fileType,
|
|
94
|
+
datasetUid,
|
|
95
|
+
defaultCoordinationValues,
|
|
96
|
+
) {
|
|
97
|
+
const defaultKeys = DATA_TYPE_COORDINATION_VALUE_USAGE[dataType]
|
|
98
|
+
.filter(k => (
|
|
99
|
+
Object.keys(defaultCoordinationValues).includes(k)
|
|
100
|
+
&& defaultCoordinationValues[k]
|
|
101
|
+
&& !Object.keys(coordinationValues).includes(k)
|
|
102
|
+
));
|
|
103
|
+
const defaultValues = pick(defaultCoordinationValues, defaultKeys);
|
|
104
|
+
const coordinationValuesWithDefaults = {
|
|
105
|
+
...defaultValues,
|
|
106
|
+
// The user-provided values should take precedence.
|
|
107
|
+
...coordinationValues,
|
|
108
|
+
};
|
|
109
|
+
if (!isEqual(coordinationValues, coordinationValuesWithDefaults)) {
|
|
110
|
+
// eslint-disable-next-line max-len
|
|
111
|
+
console.warn(`Using coordination value defaults for file type ${fileType} in dataset ${datasetUid}\nBefore: ${JSON.stringify(coordinationValues)}\nAfter: ${JSON.stringify(coordinationValuesWithDefaults)}`);
|
|
112
|
+
}
|
|
113
|
+
return coordinationValuesWithDefaults;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create a mapping from dataset ID to loader objects by data type.
|
|
118
|
+
* @param {object[]} datasets The datasets array from the view config.
|
|
119
|
+
* @param {string} configDescription The top-level description in the
|
|
120
|
+
* @param {PluginFileType[]} fileTypes
|
|
121
|
+
* @param {PluginCoordinationType[]} coordinationTypes
|
|
122
|
+
* view config.
|
|
123
|
+
* @returns {object} Mapping from dataset ID to data type to loader
|
|
124
|
+
* instance.
|
|
125
|
+
*/
|
|
126
|
+
export function createLoaders(datasets, configDescription, fileTypes, coordinationTypes) {
|
|
127
|
+
const result = {};
|
|
128
|
+
const dataSources = {};
|
|
129
|
+
const defaultCoordinationValues = fromEntries(
|
|
130
|
+
coordinationTypes.map(ct => ([ct.name, ct.defaultValue])),
|
|
131
|
+
);
|
|
132
|
+
datasets.forEach((dataset) => {
|
|
133
|
+
const datasetLoaders = {
|
|
134
|
+
name: dataset.name,
|
|
135
|
+
description: dataset.description || configDescription,
|
|
136
|
+
loaders: {},
|
|
137
|
+
};
|
|
138
|
+
dataset.files.forEach((file) => {
|
|
139
|
+
const {
|
|
140
|
+
url,
|
|
141
|
+
options,
|
|
142
|
+
requestInit,
|
|
143
|
+
fileType,
|
|
144
|
+
coordinationValues = {},
|
|
145
|
+
} = file;
|
|
146
|
+
const dataType = getDataTypeFromFileType(fileType, fileTypes);
|
|
147
|
+
const coordinationValuesWithDefaults = withDefaults(
|
|
148
|
+
coordinationValues,
|
|
149
|
+
dataType,
|
|
150
|
+
fileType,
|
|
151
|
+
dataset.uid,
|
|
152
|
+
defaultCoordinationValues,
|
|
153
|
+
);
|
|
154
|
+
const [DataSourceClass, LoaderClass] = getSourceAndLoaderFromFileType(fileType, fileTypes);
|
|
155
|
+
// Create _one_ DataSourceClass instance per URL. Derived loaders share this object.
|
|
156
|
+
const fileId = url || JSON.stringify(options);
|
|
157
|
+
if (!(fileId in dataSources)) {
|
|
158
|
+
dataSources[fileId] = new DataSourceClass({ url, requestInit });
|
|
159
|
+
}
|
|
160
|
+
const loader = new LoaderClass(dataSources[fileId], file);
|
|
161
|
+
if (datasetLoaders.loaders[dataType]) {
|
|
162
|
+
datasetLoaders.loaders[dataType].set(coordinationValuesWithDefaults, loader);
|
|
163
|
+
} else {
|
|
164
|
+
datasetLoaders.loaders[dataType] = new InternMap([
|
|
165
|
+
[coordinationValuesWithDefaults, loader],
|
|
166
|
+
], JSON.stringify);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
result[dataset.uid] = datasetLoaders;
|
|
170
|
+
});
|
|
171
|
+
return result;
|
|
172
|
+
}
|
package/dist/VitS.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
import React, { useEffect, useMemo } from 'react';
|
|
4
|
-
import { ThemeProvider, StylesProvider, createGenerateClassName, } from '@material-ui/core/styles';
|
|
5
|
-
import isEqual from 'lodash/isEqual';
|
|
6
|
-
import { META_VERSION } from '@vitessce/constants-internal';
|
|
7
|
-
import { muiTheme } from './shared-mui/styles';
|
|
8
|
-
import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
|
|
9
|
-
import VitessceGrid from './VitessceGrid';
|
|
10
|
-
import { Warning } from './Warning';
|
|
11
|
-
import CallbackPublisher from './CallbackPublisher';
|
|
12
|
-
import { getComponent } from './component-registry';
|
|
13
|
-
import { checkTypes, initialize, upgradeAndValidate, } from './view-config-utils';
|
|
14
|
-
function logConfig(config, name) {
|
|
15
|
-
console.groupCollapsed(`🚄 Vitessce (${META_VERSION.version}) ${name}`);
|
|
16
|
-
console.info(`data:,${JSON.stringify(config)}`);
|
|
17
|
-
console.info(JSON.stringify(config, null, 2));
|
|
18
|
-
console.groupEnd();
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The Vitessce component.
|
|
22
|
-
* @param {object} props
|
|
23
|
-
* @param {object} props.config A Vitessce view config.
|
|
24
|
-
* If the config is valid, the VitessceGrid will be rendered as a child.
|
|
25
|
-
* If the config is invalid, a Warning will be rendered instead.
|
|
26
|
-
* @param {number} props.rowHeight Row height for grid layout. Optional.
|
|
27
|
-
* @param {number} props.height Total height for grid layout. Optional.
|
|
28
|
-
* @param {string} props.theme The theme, used for styling as
|
|
29
|
-
* light or dark. Optional. By default, "dark"
|
|
30
|
-
* @param {function} props.onWarn A callback for warning messages. Optional.
|
|
31
|
-
* @param {function} props.onConfigChange A callback for view config
|
|
32
|
-
* updates. Optional.
|
|
33
|
-
* @param {function} props.onLoaderChange A callback for loader
|
|
34
|
-
* updates. Optional.
|
|
35
|
-
* @param {boolean} props.validateOnConfigChange Whether to validate
|
|
36
|
-
* against the view config schema when publishing changes. Use for debugging
|
|
37
|
-
* purposes, as this may have a performance impact. By default, false.
|
|
38
|
-
* @param {undefined|string} props.uid A unique identifier for this Vitessce instance,
|
|
39
|
-
* for the purpose of avoiding CSS autogenerated class name conflicts. Must be valid as part
|
|
40
|
-
* of a CSS class name string.
|
|
41
|
-
*/
|
|
42
|
-
export function VitS(props) {
|
|
43
|
-
const { config, rowHeight, height, theme, onWarn, onConfigChange, onLoaderChange, validateOnConfigChange = false, onConfigUpgrade, isBounded = false, uid, } = props;
|
|
44
|
-
const generateClassName = useMemo(() => createGenerateClassName({
|
|
45
|
-
disableGlobal: false,
|
|
46
|
-
// Avoid conflicts with portal-ui MUI class names,
|
|
47
|
-
// and allow setting a UID.
|
|
48
|
-
productionPrefix: (uid ? `vit${uid}` : 'vit'),
|
|
49
|
-
}), [uid]);
|
|
50
|
-
// Process the view config and memoize the result:
|
|
51
|
-
// - Validate.
|
|
52
|
-
// - Upgrade, if legacy schema.
|
|
53
|
-
// - Validate after upgrade, if legacy schema.
|
|
54
|
-
// - Initialize (based on initStrategy).
|
|
55
|
-
const [configOrWarning, success] = useMemo(() => {
|
|
56
|
-
// If the config value is undefined, show a warning message.
|
|
57
|
-
if (!config) {
|
|
58
|
-
return [
|
|
59
|
-
{
|
|
60
|
-
title: 'No such dataset',
|
|
61
|
-
unformatted: 'The dataset configuration could not be found.',
|
|
62
|
-
},
|
|
63
|
-
false,
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
// If the view config is missing a version, show a warning message.
|
|
67
|
-
if (!config.version) {
|
|
68
|
-
return [
|
|
69
|
-
{
|
|
70
|
-
title: 'Missing version',
|
|
71
|
-
unformatted: 'The dataset configuration is missing a version, preventing validation.',
|
|
72
|
-
},
|
|
73
|
-
false,
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
logConfig(config, 'input view config');
|
|
77
|
-
// Check if this is a "legacy" view config.
|
|
78
|
-
const [upgradedConfig, upgradeSuccess] = upgradeAndValidate(config, onConfigUpgrade);
|
|
79
|
-
if (upgradeSuccess) {
|
|
80
|
-
logConfig(upgradedConfig, 'upgraded view config');
|
|
81
|
-
// Initialize the view config according to the initStrategy.
|
|
82
|
-
const [typeCheckSuccess, typeCheckMessage] = checkTypes(upgradedConfig);
|
|
83
|
-
if (typeCheckSuccess) {
|
|
84
|
-
try {
|
|
85
|
-
const initializedConfig = initialize(upgradedConfig);
|
|
86
|
-
logConfig(initializedConfig, 'initialized view config');
|
|
87
|
-
return [initializedConfig, true];
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
return [
|
|
91
|
-
{
|
|
92
|
-
title: 'View config initialization failed.',
|
|
93
|
-
unformatted: e.message,
|
|
94
|
-
},
|
|
95
|
-
false,
|
|
96
|
-
];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return [
|
|
100
|
-
{
|
|
101
|
-
title: 'View config checks failed.',
|
|
102
|
-
unformatted: typeCheckMessage,
|
|
103
|
-
},
|
|
104
|
-
false,
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
return [upgradedConfig, false];
|
|
108
|
-
}, [config, onConfigUpgrade]);
|
|
109
|
-
// Emit the upgraded/initialized view config
|
|
110
|
-
// to onConfigChange if necessary.
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
if (success && !isEqual(configOrWarning, config) && onConfigChange) {
|
|
113
|
-
onConfigChange(configOrWarning);
|
|
114
|
-
}
|
|
115
|
-
}, [success, config, configOrWarning, onConfigChange]);
|
|
116
|
-
return success ? (_jsx(StylesProvider, { generateClassName: generateClassName, children: _jsx(ThemeProvider, { theme: muiTheme[theme], children: _jsx(ViewConfigProvider, { createStore: createViewConfigStore, children: _jsxs(AuxiliaryProvider, { createStore: createAuxiliaryStore, children: [_jsx(VitessceGrid, { config: configOrWarning, getComponent: getComponent, rowHeight: rowHeight, height: height, theme: theme, isBounded: isBounded }), _jsx(CallbackPublisher, { onWarn: onWarn, onConfigChange: onConfigChange, onLoaderChange: onLoaderChange, validateOnConfigChange: validateOnConfigChange })] }) }) }) })) : (_jsx(StylesProvider, { generateClassName: generateClassName, children: _jsx(ThemeProvider, { theme: muiTheme[theme], children: _jsx(Warning, { ...configOrWarning }) }) }));
|
|
117
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable max-len */
|
|
3
|
-
// import React from 'react';
|
|
4
|
-
// import Adapter from 'enzyme-adapter-react-16';
|
|
5
|
-
// import { mount, configure } from 'enzyme';
|
|
6
|
-
// import Ajv from 'ajv';
|
|
7
|
-
// import expect from 'expect';
|
|
8
|
-
// import Vitessce from './Vitessce';
|
|
9
|
-
// import { configs } from './api';
|
|
10
|
-
// import configSchema from '../schemas/config.schema.json';
|
|
11
|
-
// configure({ adapter: new Adapter() });
|
|
12
|
-
// describe('Vitessce.js', () => {
|
|
13
|
-
// describe('<Vitessce />', () => {
|
|
14
|
-
// it('Produces valid view config', (done) => {
|
|
15
|
-
// const config = configs['linnarsson-2018'];
|
|
16
|
-
// let updatedConfig = {};
|
|
17
|
-
// // eslint-disable-next-line no-return-assign
|
|
18
|
-
// const wrapper = mount(<Vitessce config={config} onConfigChange={c => updatedConfig = c} />);
|
|
19
|
-
// setTimeout(() => {
|
|
20
|
-
// // Simulate usage of some of the app
|
|
21
|
-
// wrapper.find('[id^="deckgl-overlay-"]').at(0).simulate('wheel', { deltaY: 1000, deltaX: 1000 });
|
|
22
|
-
// wrapper.find('[id^="deckgl-overlay-"]').at(1).simulate('wheel', { deltaY: 1000, deltaX: 1000 });
|
|
23
|
-
// wrapper.find('[id^="deckgl-overlay-"]').at(2).simulate('wheel', { deltaY: 1000, deltaX: 1000 });
|
|
24
|
-
// const validate = new Ajv().compile(configSchema);
|
|
25
|
-
// const valid = validate(updatedConfig);
|
|
26
|
-
// if (!valid) {
|
|
27
|
-
// const failureReason = JSON.stringify(validate.errors, null, 2);
|
|
28
|
-
// console.error(failureReason);
|
|
29
|
-
// }
|
|
30
|
-
// expect(valid).toEqual(true);
|
|
31
|
-
// wrapper.unmount();
|
|
32
|
-
// done();
|
|
33
|
-
// }, 20000);
|
|
34
|
-
// }).timeout(30000);
|
|
35
|
-
// });
|
|
36
|
-
// });
|
package/dist/Vitessce.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
import React, { useEffect, useMemo } from 'react';
|
|
4
|
-
import { ThemeProvider, StylesProvider, createGenerateClassName, } from '@material-ui/core/styles';
|
|
5
|
-
import isEqual from 'lodash/isEqual';
|
|
6
|
-
import { muiTheme } from './shared-mui/styles';
|
|
7
|
-
import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
|
|
8
|
-
import VitessceGrid from './VitessceGrid';
|
|
9
|
-
import { Warning } from './Warning';
|
|
10
|
-
import CallbackPublisher from './CallbackPublisher';
|
|
11
|
-
import { getComponent } from './component-registry';
|
|
12
|
-
import { checkTypes, initialize, upgradeAndValidate } from './view-config-utils';
|
|
13
|
-
// TODO(monorepo): figure out how to get the current package version from package.json
|
|
14
|
-
// import packageJson from '../package.json';
|
|
15
|
-
const packageJson = { version: 'unk' };
|
|
16
|
-
const generateClassName = createGenerateClassName({
|
|
17
|
-
disableGlobal: true,
|
|
18
|
-
});
|
|
19
|
-
function logConfig(config, name) {
|
|
20
|
-
console.groupCollapsed(`🚄 Vitessce (${packageJson.version}) ${name}`);
|
|
21
|
-
console.info(`data:,${JSON.stringify(config)}`);
|
|
22
|
-
console.info(JSON.stringify(config, null, 2));
|
|
23
|
-
console.groupEnd();
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The Vitessce component.
|
|
27
|
-
* @param {object} props
|
|
28
|
-
* @param {object} props.config A Vitessce view config.
|
|
29
|
-
* If the config is valid, the VitessceGrid will be rendered as a child.
|
|
30
|
-
* If the config is invalid, a Warning will be rendered instead.
|
|
31
|
-
* @param {number} props.rowHeight Row height for grid layout. Optional.
|
|
32
|
-
* @param {number} props.height Total height for grid layout. Optional.
|
|
33
|
-
* @param {string} props.theme The theme, used for styling as
|
|
34
|
-
* light or dark. Optional. By default, "dark"
|
|
35
|
-
* @param {function} props.onWarn A callback for warning messages. Optional.
|
|
36
|
-
* @param {function} props.onConfigChange A callback for view config
|
|
37
|
-
* updates. Optional.
|
|
38
|
-
* @param {function} props.onLoaderChange A callback for loader
|
|
39
|
-
* updates. Optional.
|
|
40
|
-
* @param {boolean} props.validateOnConfigChange Whether to validate
|
|
41
|
-
* against the view config schema when publishing changes. Use for debugging
|
|
42
|
-
* purposes, as this may have a performance impact. By default, false.
|
|
43
|
-
*/
|
|
44
|
-
export function Vitessce(props) {
|
|
45
|
-
const { config, rowHeight, height, theme, onWarn, onConfigChange, onLoaderChange, validateOnConfigChange = false, onConfigUpgrade, isBounded = false, } = props;
|
|
46
|
-
// Process the view config and memoize the result:
|
|
47
|
-
// - Validate.
|
|
48
|
-
// - Upgrade, if legacy schema.
|
|
49
|
-
// - Validate after upgrade, if legacy schema.
|
|
50
|
-
// - Initialize (based on initStrategy).
|
|
51
|
-
const [configOrWarning, success] = useMemo(() => {
|
|
52
|
-
// If the config value is undefined, show a warning message.
|
|
53
|
-
if (!config) {
|
|
54
|
-
return [{
|
|
55
|
-
title: 'No such dataset',
|
|
56
|
-
unformatted: 'The dataset configuration could not be found.',
|
|
57
|
-
}, false];
|
|
58
|
-
}
|
|
59
|
-
// If the view config is missing a version, show a warning message.
|
|
60
|
-
if (!config.version) {
|
|
61
|
-
return [{
|
|
62
|
-
title: 'Missing version',
|
|
63
|
-
unformatted: 'The dataset configuration is missing a version, preventing validation.',
|
|
64
|
-
}, false];
|
|
65
|
-
}
|
|
66
|
-
logConfig(config, 'input view config');
|
|
67
|
-
// Check if this is a "legacy" view config.
|
|
68
|
-
const [upgradedConfig, upgradeSuccess] = upgradeAndValidate(config, onConfigUpgrade);
|
|
69
|
-
if (upgradeSuccess) {
|
|
70
|
-
logConfig(upgradedConfig, 'upgraded view config');
|
|
71
|
-
// Initialize the view config according to the initStrategy.
|
|
72
|
-
const [typeCheckSuccess, typeCheckMessage] = checkTypes(upgradedConfig);
|
|
73
|
-
if (typeCheckSuccess) {
|
|
74
|
-
try {
|
|
75
|
-
const initializedConfig = initialize(upgradedConfig);
|
|
76
|
-
logConfig(initializedConfig, 'initialized view config');
|
|
77
|
-
return [initializedConfig, true];
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
return [{
|
|
81
|
-
title: 'View config initialization failed.',
|
|
82
|
-
unformatted: e.message,
|
|
83
|
-
}, false];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return [{
|
|
87
|
-
title: 'View config checks failed.',
|
|
88
|
-
unformatted: typeCheckMessage,
|
|
89
|
-
}, false];
|
|
90
|
-
}
|
|
91
|
-
return [upgradedConfig, false];
|
|
92
|
-
}, [config, onConfigUpgrade]);
|
|
93
|
-
// Emit the upgraded/initialized view config
|
|
94
|
-
// to onConfigChange if necessary.
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (success && !isEqual(configOrWarning, config) && onConfigChange) {
|
|
97
|
-
onConfigChange(configOrWarning);
|
|
98
|
-
}
|
|
99
|
-
}, [success, config, configOrWarning, onConfigChange]);
|
|
100
|
-
return success ? (_jsx(StylesProvider, { generateClassName: generateClassName, children: _jsx(ThemeProvider, { theme: muiTheme[theme], children: _jsx(ViewConfigProvider, { createStore: createViewConfigStore, children: _jsxs(AuxiliaryProvider, { createStore: createAuxiliaryStore, children: [_jsx(VitessceGrid, { config: configOrWarning, getComponent: getComponent, rowHeight: rowHeight, height: height, theme: theme, isBounded: isBounded }), _jsx(CallbackPublisher, { onWarn: onWarn, onConfigChange: onConfigChange, onLoaderChange: onLoaderChange, validateOnConfigChange: validateOnConfigChange })] }) }) }) })) : (_jsx(StylesProvider, { generateClassName: generateClassName, children: _jsx(ThemeProvider, { theme: muiTheme[theme], children: _jsx(Warning, { ...configOrWarning }) }) }));
|
|
101
|
-
}
|
|
@@ -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
|
-
}
|
package/dist/data/index.js
DELETED
|
@@ -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,15 +0,0 @@
|
|
|
1
|
-
import AbstractLoaderError from './AbstractLoaderError';
|
|
2
|
-
export default class OptionsValidationError extends AbstractLoaderError {
|
|
3
|
-
constructor(fileType, url, options, reason) {
|
|
4
|
-
super(`Error while validating file definition options: ${fileType} from ${url}.`);
|
|
5
|
-
this.name = 'OptionsValidationError';
|
|
6
|
-
this.fileType = fileType;
|
|
7
|
-
this.url = url;
|
|
8
|
-
this.options = options;
|
|
9
|
-
this.reason = reason;
|
|
10
|
-
}
|
|
11
|
-
warnInConsole() {
|
|
12
|
-
const { options, reason, } = this;
|
|
13
|
-
console.warn('Received options\n', JSON.stringify(options, null, 2), 'JSON schema validation failure reason\n', JSON.stringify(reason, null, 2));
|
|
14
|
-
}
|
|
15
|
-
}
|
package/dist/export-utils.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import Bowser from 'bowser';
|
|
2
|
-
import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from 'lz-string';
|
|
3
|
-
const CURRENT_VERSION = '0.0.1';
|
|
4
|
-
const VITESSCE_CONF_QUERY_STRING = 'vitessce_conf';
|
|
5
|
-
const VERSION_QUERY_STRING = 'vitessce_conf_version';
|
|
6
|
-
const LENGTH_QUERY_STRING = 'vitessce_conf_length';
|
|
7
|
-
function sniffBrowser() {
|
|
8
|
-
const { browser } = Bowser.parse(window.navigator.userAgent);
|
|
9
|
-
return browser.name;
|
|
10
|
-
}
|
|
11
|
-
// https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
|
|
12
|
-
const MAX_BROWSER_URL_LENGTHS = {
|
|
13
|
-
Chrome: 32779,
|
|
14
|
-
'Internet Explorer': 2047,
|
|
15
|
-
Edge: 2047,
|
|
16
|
-
Safari: 65000,
|
|
17
|
-
Firefox: 65000,
|
|
18
|
-
};
|
|
19
|
-
export default class CompressedConfLengthError {
|
|
20
|
-
constructor(message) {
|
|
21
|
-
this.message = message;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Encode a configuration as url params with a version and an lz-compressed conf.
|
|
26
|
-
* @param {Object} params
|
|
27
|
-
* @param {Object} params.conf Previous scope names.
|
|
28
|
-
* @param {function} params.onOverMaximumUrlLength Callback for when new url
|
|
29
|
-
* is over max length for your browser - takes two arguments: { message, willWorkOn }
|
|
30
|
-
* for the error message and the browsers for which the url will work (optional).
|
|
31
|
-
* @returns {string} The new params like
|
|
32
|
-
* vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl
|
|
33
|
-
*/
|
|
34
|
-
export function encodeConfInUrl({ conf, onOverMaximumUrlLength = () => { }, }) {
|
|
35
|
-
const compressedConf = compressToEncodedURIComponent(JSON.stringify(conf));
|
|
36
|
-
const newParams = `${LENGTH_QUERY_STRING}=${compressedConf.length}&${VERSION_QUERY_STRING}=${CURRENT_VERSION}&${VITESSCE_CONF_QUERY_STRING}=${compressedConf}`;
|
|
37
|
-
const browser = sniffBrowser();
|
|
38
|
-
const maxLength = MAX_BROWSER_URL_LENGTHS[browser];
|
|
39
|
-
if (newParams.length > maxLength) {
|
|
40
|
-
const willWorkOn = Object.entries(MAX_BROWSER_URL_LENGTHS)
|
|
41
|
-
.filter(entry => entry[1] > newParams.length)
|
|
42
|
-
.map(entry => entry[0]);
|
|
43
|
-
const message = `Configuration is ${compressedConf.length} characters; max URL for ${browser} is ${maxLength}: it will work on ${willWorkOn.join(', ') || 'no browser'}.`;
|
|
44
|
-
console.error(message);
|
|
45
|
-
onOverMaximumUrlLength({ message, willWorkOn });
|
|
46
|
-
}
|
|
47
|
-
return newParams;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Decode URL params to a Vitessce configuration.
|
|
51
|
-
* The URL params must have version and vitessce_conf params,
|
|
52
|
-
* like vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl.
|
|
53
|
-
* @param {Object} queryString The URL params,
|
|
54
|
-
* like vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl.
|
|
55
|
-
* @returns {string} A vitessce configuration.
|
|
56
|
-
*/
|
|
57
|
-
export function decodeURLParamsToConf(queryString) {
|
|
58
|
-
const params = new URLSearchParams(queryString.replace('#', '&'));
|
|
59
|
-
const compressedConfString = params.get(VITESSCE_CONF_QUERY_STRING);
|
|
60
|
-
const expectedConfLength = Number(params.get(LENGTH_QUERY_STRING));
|
|
61
|
-
if (expectedConfLength !== compressedConfString.length) {
|
|
62
|
-
throw new CompressedConfLengthError(`Compressed conf length (${compressedConfString.length}) != expected (${expectedConfLength}). URL truncated?`);
|
|
63
|
-
}
|
|
64
|
-
const version = params.get(VERSION_QUERY_STRING);
|
|
65
|
-
if (version === CURRENT_VERSION) {
|
|
66
|
-
const conf = JSON.parse(decompressFromEncodedURIComponent(compressedConfString));
|
|
67
|
-
return conf;
|
|
68
|
-
}
|
|
69
|
-
throw new Error('Unrecognized URL Param Version');
|
|
70
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import expect from 'expect';
|
|
2
|
-
import { encodeConfInUrl, decodeURLParamsToConf, } from './export-utils';
|
|
3
|
-
const fakeConfig = {
|
|
4
|
-
version: '0.1.0',
|
|
5
|
-
public: false,
|
|
6
|
-
layers: [
|
|
7
|
-
{
|
|
8
|
-
name: 'cells',
|
|
9
|
-
type: 'CELLS',
|
|
10
|
-
fileType: 'cells.json',
|
|
11
|
-
url: 'http://example.com/cells.json',
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
name: 'Just scatterplot',
|
|
15
|
-
staticLayout: [
|
|
16
|
-
{
|
|
17
|
-
component: 'scatterplot',
|
|
18
|
-
props: {
|
|
19
|
-
mapping: 't-SNE',
|
|
20
|
-
view: {
|
|
21
|
-
zoom: 0.75,
|
|
22
|
-
target: [0, 0, 0],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
x: 0,
|
|
26
|
-
y: 0,
|
|
27
|
-
w: 12,
|
|
28
|
-
h: 2,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
};
|
|
32
|
-
function makeLongString(length) {
|
|
33
|
-
let result = '';
|
|
34
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
35
|
-
const charactersLength = characters.length;
|
|
36
|
-
// eslint-disable-next-line no-plusplus
|
|
37
|
-
for (let i = 0; i < length; i++) {
|
|
38
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
describe('src/app/export-utils.js', () => {
|
|
43
|
-
describe('encodeConfInUrl', () => {
|
|
44
|
-
it('encodes a view config for a URL', () => {
|
|
45
|
-
const urlParams1 = encodeConfInUrl({ conf: {} });
|
|
46
|
-
expect(urlParams1).toEqual('vitessce_conf_length=5&vitessce_conf_version=0.0.1&vitessce_conf=N4XyA');
|
|
47
|
-
const urlParams2 = encodeConfInUrl({ conf: fakeConfig });
|
|
48
|
-
expect(urlParams2).toEqual('vitessce_conf_length=327&vitessce_conf_version=0.0.1&vitessce_conf=N4IgbgpgTgzglgewHYgFwgAwDoCMWMgA0IADgK4BGANnAMZoBmAhlTBMVUwJ7QxoDaoJEwC2ENCFoQqrIiAAuXEuPQBhAKIAZTQGU5DOFQgAVJSsnTWWAFYxkcslCoSAFvPklUAei8QAHqIkRli0CCJeUjIwNnYoAL4AusTCYhIAUmQw8gAEMLRM7tBBCPJyWQV0mtwIZKWogpJhJMgQSHUgeQXyRVQlciRQCCR8qKAiTCQkcEgA5hLyALQ6AHLqcmBwEADuaKAAXghhaNgA7ACsxPJMUDMQdfwYhI8YCXFxxH7HxFxfIDuoOAATMQXGhAYk4kA');
|
|
49
|
-
});
|
|
50
|
-
it('Calls onOverMaximumUrlLength for conf too long', () => {
|
|
51
|
-
let browsers;
|
|
52
|
-
// eslint-disable-next-line no-return-assign
|
|
53
|
-
const onOverMaximumUrlLength = ({ willWorkOn }) => browsers = willWorkOn;
|
|
54
|
-
encodeConfInUrl({ conf: { foo: makeLongString(69000) }, onOverMaximumUrlLength });
|
|
55
|
-
expect(browsers).toEqual([]);
|
|
56
|
-
encodeConfInUrl({ conf: { foo: makeLongString(37000) }, onOverMaximumUrlLength });
|
|
57
|
-
expect(browsers).toEqual(['Safari', 'Firefox']);
|
|
58
|
-
});
|
|
59
|
-
it('decodes a view config for a URL', () => {
|
|
60
|
-
const viewConfig1 = decodeURLParamsToConf('vitessce_conf_length=5&vitessce_conf_version=0.0.1&vitessce_conf=N4XyA');
|
|
61
|
-
expect(viewConfig1).toEqual({});
|
|
62
|
-
const viewConfig2 = decodeURLParamsToConf('vitessce_conf_length=327&vitessce_conf_version=0.0.1&vitessce_conf=N4IgbgpgTgzglgewHYgFwgAwDoCMWMgA0IADgK4BGANnAMZoBmAhlTBMVUwJ7QxoDaoJEwC2ENCFoQqrIiAAuXEuPQBhAKIAZTQGU5DOFQgAVJSsnTWWAFYxkcslCoSAFvPklUAei8QAHqIkRli0CCJeUjIwNnYoAL4AusTCYhIAUmQw8gAEMLRM7tBBCPJyWQV0mtwIZKWogpJhJMgQSHUgeQXyRVQlciRQCCR8qKAiTCQkcEgA5hLyALQ6AHLqcmBwEADuaKAAXghhaNgA7ACsxPJMUDMQdfwYhI8YCXFxxH7HxFxfIDuoOAATMQXGhAYk4kA');
|
|
63
|
-
expect(viewConfig2).toEqual(fakeConfig);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|