@vitessce/description 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.
- package/dist/index.mjs +6003 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +7 -7
- package/src/Description.js +69 -0
- package/src/Description.test.jsx +38 -0
- package/src/DescriptionSubscriber.js +91 -0
- package/src/index.js +2 -0
- package/dist/Description.js +0 -45
- package/dist/Description.test.js +0 -35
- package/dist/DescriptionSubscriber.js +0 -48
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/description",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "dist/index.
|
|
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",
|
|
17
|
-
"@vitessce/constants-internal": "2.0.
|
|
18
|
-
"@vitessce/vit-s": "2.0.
|
|
18
|
+
"@vitessce/constants-internal": "2.0.3",
|
|
19
|
+
"@vitessce/vit-s": "2.0.3"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"react": "^18.0.0",
|
|
@@ -26,8 +27,7 @@
|
|
|
26
27
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
|
-
"
|
|
30
|
-
"build": "tsc",
|
|
30
|
+
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
|
31
31
|
"test": "pnpm exec vitest --run -r ../../../ --dir ."
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
3
|
+
|
|
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
|
+
|
|
40
|
+
export default function Description(props) {
|
|
41
|
+
const { description, metadata } = props;
|
|
42
|
+
const classes = useStyles();
|
|
43
|
+
return (
|
|
44
|
+
<div className={classes.description}>
|
|
45
|
+
<p>{description}</p>
|
|
46
|
+
|
|
47
|
+
{metadata && Array.from(metadata.entries())
|
|
48
|
+
.map(([layerIndex, { name: layerName, metadata: metadataRecord }]) => (
|
|
49
|
+
metadataRecord && Object.entries(metadataRecord).length > 0 ? (
|
|
50
|
+
<details key={layerIndex}>
|
|
51
|
+
<summary>{layerName}</summary>
|
|
52
|
+
<div className={classes.metadataContainer}>
|
|
53
|
+
<table>
|
|
54
|
+
<tbody>
|
|
55
|
+
{Object.entries(metadataRecord)
|
|
56
|
+
.map(([key, value]) => (
|
|
57
|
+
<tr key={key}>
|
|
58
|
+
<th title={key}>{key}</th>
|
|
59
|
+
<td title={value}>{value}</td>
|
|
60
|
+
</tr>
|
|
61
|
+
))}
|
|
62
|
+
</tbody>
|
|
63
|
+
</table>
|
|
64
|
+
</div>
|
|
65
|
+
</details>
|
|
66
|
+
) : null))}
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
3
|
+
import { afterEach } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import Description from './Description';
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
cleanup()
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('Description.js', () => {
|
|
12
|
+
describe('<Description />', () => {
|
|
13
|
+
it('shows text', async () => {
|
|
14
|
+
render(<Description description="Some text" />);
|
|
15
|
+
expect(await screen.findByText('Some text'));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('shows metadata', async () => {
|
|
19
|
+
const layerIndex = '0';
|
|
20
|
+
const layerName = 'My layer';
|
|
21
|
+
const metadata = new Map([
|
|
22
|
+
[layerIndex, {
|
|
23
|
+
name: layerName,
|
|
24
|
+
metadata: {
|
|
25
|
+
Channels: 4,
|
|
26
|
+
'Pixels Type': 'uint16',
|
|
27
|
+
},
|
|
28
|
+
}],
|
|
29
|
+
]);
|
|
30
|
+
render(<Description metadata={metadata} />);
|
|
31
|
+
expect(await screen.findByText('My layer'));
|
|
32
|
+
expect(await screen.findByText('Channels'));
|
|
33
|
+
expect(await screen.findByText('4'));
|
|
34
|
+
expect(await screen.findByText('Pixels Type'));
|
|
35
|
+
expect(await screen.findByText('uint16'));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TitleInfo,
|
|
4
|
+
useReady,
|
|
5
|
+
useCoordination, useLoaders,
|
|
6
|
+
useDescription, useImageData,
|
|
7
|
+
registerPluginViewType,
|
|
8
|
+
} from '@vitessce/vit-s';
|
|
9
|
+
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
|
10
|
+
import Description from './Description';
|
|
11
|
+
|
|
12
|
+
const addUrl = () => {}; // noop
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A subscriber component for a text description component.
|
|
16
|
+
* Also renders a table containing image metadata.
|
|
17
|
+
* @param {object} props
|
|
18
|
+
* @param {string} props.theme The current theme name.
|
|
19
|
+
* @param {object} props.coordinationScopes The mapping from coordination types to coordination
|
|
20
|
+
* scopes.
|
|
21
|
+
* @param {function} props.removeGridComponent The callback function to pass to TitleInfo,
|
|
22
|
+
* to call when the component has been removed from the grid.
|
|
23
|
+
* @param {string} props.title The component title.
|
|
24
|
+
*/
|
|
25
|
+
export function DescriptionSubscriber(props) {
|
|
26
|
+
const {
|
|
27
|
+
coordinationScopes,
|
|
28
|
+
description: descriptionOverride,
|
|
29
|
+
removeGridComponent,
|
|
30
|
+
theme,
|
|
31
|
+
title = 'Description',
|
|
32
|
+
} = props;
|
|
33
|
+
|
|
34
|
+
const loaders = useLoaders();
|
|
35
|
+
|
|
36
|
+
// Get "props" from the coordination space.
|
|
37
|
+
const [{
|
|
38
|
+
dataset,
|
|
39
|
+
spatialImageLayer: rasterLayers,
|
|
40
|
+
}] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.DESCRIPTION], coordinationScopes);
|
|
41
|
+
|
|
42
|
+
// Get data from loaders using the data hooks.
|
|
43
|
+
const [description] = useDescription(loaders, dataset);
|
|
44
|
+
const [{ image }, imageStatus] = useImageData(
|
|
45
|
+
loaders, dataset, addUrl, false, {}, {},
|
|
46
|
+
{}, // TODO: which properties to match on. Revisit after #830.
|
|
47
|
+
);
|
|
48
|
+
const { loaders: imageLayerLoaders = [], meta: imageLayerMeta = [] } = image || {};
|
|
49
|
+
|
|
50
|
+
const isReady = useReady([imageStatus]);
|
|
51
|
+
|
|
52
|
+
const metadata = useMemo(() => {
|
|
53
|
+
const result = new Map();
|
|
54
|
+
if (rasterLayers && rasterLayers.length > 0 && imageLayerMeta && imageLayerLoaders) {
|
|
55
|
+
rasterLayers.forEach((layer) => {
|
|
56
|
+
if (imageLayerMeta[layer.index]) {
|
|
57
|
+
// Want to ensure that layer index is a string.
|
|
58
|
+
const { format } = imageLayerLoaders[layer.index].metadata;
|
|
59
|
+
result.set(`${layer.index}`, {
|
|
60
|
+
name: imageLayerMeta[layer.index].name,
|
|
61
|
+
metadata: format && format(),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}, [rasterLayers, imageLayerMeta, imageLayerLoaders]);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<TitleInfo
|
|
71
|
+
title={title}
|
|
72
|
+
removeGridComponent={removeGridComponent}
|
|
73
|
+
isScroll
|
|
74
|
+
theme={theme}
|
|
75
|
+
isReady={isReady}
|
|
76
|
+
>
|
|
77
|
+
<Description
|
|
78
|
+
description={descriptionOverride || description}
|
|
79
|
+
metadata={metadata}
|
|
80
|
+
/>
|
|
81
|
+
</TitleInfo>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function register() {
|
|
86
|
+
registerPluginViewType(
|
|
87
|
+
ViewType.DESCRIPTION,
|
|
88
|
+
DescriptionSubscriber,
|
|
89
|
+
COMPONENT_COORDINATION_TYPES[ViewType.DESCRIPTION],
|
|
90
|
+
);
|
|
91
|
+
}
|
package/src/index.js
ADDED
package/dist/Description.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/Description.test.js
DELETED
|
@@ -1,35 +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 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
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|