@vitessce/description 2.0.0-beta.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/LICENSE +21 -0
- package/dist/Description.js +45 -0
- package/dist/Description.test.js +35 -0
- package/dist/DescriptionSubscriber.js +48 -0
- package/dist/index.js +2 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
4
|
+
const useStyles = makeStyles(theme => ({
|
|
5
|
+
description: {
|
|
6
|
+
'& p, details, table': {
|
|
7
|
+
fontSize: '80%',
|
|
8
|
+
opacity: '0.8',
|
|
9
|
+
},
|
|
10
|
+
'& details': {
|
|
11
|
+
marginBottom: '6px',
|
|
12
|
+
},
|
|
13
|
+
'& summary': {
|
|
14
|
+
// TODO(monorepo): lighten color by 10%
|
|
15
|
+
borderBottom: `1px solid ${theme.palette.primaryBackground}`,
|
|
16
|
+
cursor: 'pointer',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
metadataContainer: {
|
|
20
|
+
paddingLeft: '14px',
|
|
21
|
+
'& table': {
|
|
22
|
+
width: '100%',
|
|
23
|
+
'& td, th': {
|
|
24
|
+
outline: 'none',
|
|
25
|
+
padding: '2px 2px',
|
|
26
|
+
maxWidth: '0',
|
|
27
|
+
overflow: 'hidden',
|
|
28
|
+
textOverflow: 'ellipsis',
|
|
29
|
+
whiteSpace: 'nowrap',
|
|
30
|
+
width: '50%',
|
|
31
|
+
},
|
|
32
|
+
'& tr:nth-child(even)': {
|
|
33
|
+
// TODO(monorepo): lighten color by 5%
|
|
34
|
+
backgroundColor: `1px solid ${theme.palette.primaryBackground}`,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
export default function Description(props) {
|
|
40
|
+
const { description, metadata } = props;
|
|
41
|
+
const classes = useStyles();
|
|
42
|
+
return (_jsxs("div", { className: classes.description, children: [_jsx("p", { children: description }), metadata && Array.from(metadata.entries())
|
|
43
|
+
.map(([layerIndex, { name: layerName, metadata: metadataRecord }]) => (metadataRecord && Object.entries(metadataRecord).length > 0 ? (_jsxs("details", { children: [_jsx("summary", { children: layerName }), _jsx("div", { className: classes.metadataContainer, children: _jsx("table", { children: _jsx("tbody", { children: Object.entries(metadataRecord)
|
|
44
|
+
.map(([key, value]) => (_jsxs("tr", { children: [_jsx("th", { title: key, children: key }), _jsx("td", { title: value, children: value })] }, key))) }) }) })] }, layerIndex)) : null))] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 Description from './Description';
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
cleanup();
|
|
8
|
+
});
|
|
9
|
+
describe('Description.js', () => {
|
|
10
|
+
describe('<Description />', () => {
|
|
11
|
+
it('shows text', async () => {
|
|
12
|
+
render(_jsx(Description, { description: "Some text" }));
|
|
13
|
+
expect(await screen.findByText('Some text'));
|
|
14
|
+
});
|
|
15
|
+
it('shows metadata', async () => {
|
|
16
|
+
const layerIndex = '0';
|
|
17
|
+
const layerName = 'My layer';
|
|
18
|
+
const metadata = new Map([
|
|
19
|
+
[layerIndex, {
|
|
20
|
+
name: layerName,
|
|
21
|
+
metadata: {
|
|
22
|
+
Channels: 4,
|
|
23
|
+
'Pixels Type': 'uint16',
|
|
24
|
+
},
|
|
25
|
+
}],
|
|
26
|
+
]);
|
|
27
|
+
render(_jsx(Description, { metadata: metadata }));
|
|
28
|
+
expect(await screen.findByText('My layer'));
|
|
29
|
+
expect(await screen.findByText('Channels'));
|
|
30
|
+
expect(await screen.findByText('4'));
|
|
31
|
+
expect(await screen.findByText('Pixels Type'));
|
|
32
|
+
expect(await screen.findByText('uint16'));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo } from 'react';
|
|
3
|
+
import { TitleInfo, useReady, useCoordination, useLoaders, useDescription, useImageData, registerPluginViewType, } from '@vitessce/vit-s';
|
|
4
|
+
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
|
5
|
+
import Description from './Description';
|
|
6
|
+
const addUrl = () => { }; // noop
|
|
7
|
+
/**
|
|
8
|
+
* A subscriber component for a text description component.
|
|
9
|
+
* Also renders a table containing image metadata.
|
|
10
|
+
* @param {object} props
|
|
11
|
+
* @param {string} props.theme The current theme name.
|
|
12
|
+
* @param {object} props.coordinationScopes The mapping from coordination types to coordination
|
|
13
|
+
* scopes.
|
|
14
|
+
* @param {function} props.removeGridComponent The callback function to pass to TitleInfo,
|
|
15
|
+
* to call when the component has been removed from the grid.
|
|
16
|
+
* @param {string} props.title The component title.
|
|
17
|
+
*/
|
|
18
|
+
export function DescriptionSubscriber(props) {
|
|
19
|
+
const { coordinationScopes, description: descriptionOverride, removeGridComponent, theme, title = 'Description', } = props;
|
|
20
|
+
const loaders = useLoaders();
|
|
21
|
+
// Get "props" from the coordination space.
|
|
22
|
+
const [{ dataset, spatialImageLayer: rasterLayers, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.DESCRIPTION], coordinationScopes);
|
|
23
|
+
// Get data from loaders using the data hooks.
|
|
24
|
+
const [description] = useDescription(loaders, dataset);
|
|
25
|
+
const [{ image }, imageStatus] = useImageData(loaders, dataset, addUrl, false, {}, {}, {});
|
|
26
|
+
const { loaders: imageLayerLoaders = [], meta: imageLayerMeta = [] } = image || {};
|
|
27
|
+
const isReady = useReady([imageStatus]);
|
|
28
|
+
const metadata = useMemo(() => {
|
|
29
|
+
const result = new Map();
|
|
30
|
+
if (rasterLayers && rasterLayers.length > 0 && imageLayerMeta && imageLayerLoaders) {
|
|
31
|
+
rasterLayers.forEach((layer) => {
|
|
32
|
+
if (imageLayerMeta[layer.index]) {
|
|
33
|
+
// Want to ensure that layer index is a string.
|
|
34
|
+
const { format } = imageLayerLoaders[layer.index].metadata;
|
|
35
|
+
result.set(`${layer.index}`, {
|
|
36
|
+
name: imageLayerMeta[layer.index].name,
|
|
37
|
+
metadata: format && format(),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}, [rasterLayers, imageLayerMeta, imageLayerLoaders]);
|
|
44
|
+
return (_jsx(TitleInfo, { title: title, removeGridComponent: removeGridComponent, isScroll: true, theme: theme, isReady: isReady, children: _jsx(Description, { description: descriptionOverride || description, metadata: metadata }) }));
|
|
45
|
+
}
|
|
46
|
+
export function register() {
|
|
47
|
+
registerPluginViewType(ViewType.DESCRIPTION, DescriptionSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.DESCRIPTION]);
|
|
48
|
+
}
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitessce/description",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"author": "Gehlenborg Lab",
|
|
5
|
+
"homepage": "http://vitessce.io",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@material-ui/core": "~4.12.3",
|
|
17
|
+
"@vitessce/constants-internal": "2.0.0-beta.0",
|
|
18
|
+
"@vitessce/vit-s": "2.0.0-beta.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"react": "^18.0.0",
|
|
22
|
+
"vite": "^3.0.0",
|
|
23
|
+
"vitest": "^0.23.4"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"start": "tsc --watch",
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"test": "pnpm exec vitest --run -r ../../../ --dir ."
|
|
32
|
+
}
|
|
33
|
+
}
|