@vitessce/tooltip 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 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,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import Paper from '@material-ui/core/Paper';
4
+ import Popper from '@material-ui/core/Popper';
5
+ import { useVitessceContainer } from '@vitessce/vit-s';
6
+ import { styles } from './styles';
7
+ export default function Tooltip(props) {
8
+ const { x, y, parentWidth, parentHeight, children, } = props;
9
+ const ref = useRef();
10
+ const classes = styles();
11
+ const [placementX, setPlacementX] = useState('start');
12
+ const [placementY, setPlacementY] = useState('bottom');
13
+ const getTooltipContainer = useVitessceContainer(ref);
14
+ // Do collision detection based on the bounds of the tooltip ancestor element.
15
+ useEffect(() => {
16
+ if (ref && ref.current) {
17
+ const flipX = (x > parentWidth / 2);
18
+ const flipY = (y > parentHeight / 2);
19
+ setPlacementX(flipX ? 'end' : 'start');
20
+ setPlacementY(flipY ? 'top' : 'bottom');
21
+ ref.current.style.left = `${x + (flipX ? -20 : 5)}px`;
22
+ ref.current.style.top = `${y + (flipY ? -20 : 5)}px`;
23
+ }
24
+ }, [x, y, parentWidth, parentHeight]);
25
+ return (_jsx("div", { ref: ref, className: classes.tooltipAnchor, children: ref && ref.current ? (_jsx(Popper, { open: true, anchorEl: ref.current, container: getTooltipContainer, transition: true, placement: `${placementY}-${placementX}`, children: _jsx(Paper, { elevation: 4, className: classes.tooltipContent, children: children }) })) : null }));
26
+ }
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import Tooltip from './Tooltip';
4
+ /**
5
+ * A tooltip component that also incorporates a crosshair element.
6
+ * @param {object} props
7
+ * @param {string} props.parentUuid A unique identifier corresponding to the plot
8
+ * with which this scatterplot is associated.
9
+ * @param {string} props.sourceUuid A unique identifier corresponding to the plot
10
+ * from which this tooltip originated.
11
+ * @param {number} props.x The x coordinate for the tooltip.
12
+ * @param {number} props.y The y coordinate for the tooltip.
13
+ * @param {number} props.parentWidth The width of the parent plot container element.
14
+ * @param {number} props.parentHeight The height of the parent plot container element.
15
+ * @param {React.Component} props.children The tooltip contents as a react component.
16
+ */
17
+ export default function Tooltip2D(props) {
18
+ const { parentUuid, sourceUuid, x, y, parentWidth, parentHeight, children, } = props;
19
+ // Check if out of bounds.
20
+ if (x < 0 || x > parentWidth || y < 0 || y > parentHeight) {
21
+ return null;
22
+ }
23
+ // Show tooltip or crosshair?
24
+ const isTooltipVisible = (parentUuid === sourceUuid);
25
+ const crosshairWidth = 1;
26
+ return (_jsx(_Fragment, { children: isTooltipVisible ? (_jsx(Tooltip, { x: x, y: y, parentWidth: parentWidth, parentHeight: parentHeight, children: children })) : (_jsxs(_Fragment, { children: [x !== null ? (_jsx("div", { className: "cell-emphasis-crosshair", style: {
27
+ left: `${x - crosshairWidth / 2}px`,
28
+ top: 0,
29
+ width: `${crosshairWidth}px`,
30
+ height: `${parentHeight}px`,
31
+ } })) : null, y !== null ? (_jsx("div", { className: "cell-emphasis-crosshair", style: {
32
+ left: 0,
33
+ top: `${y - crosshairWidth / 2}px`,
34
+ width: `${parentWidth}px`,
35
+ height: `${crosshairWidth}px`,
36
+ } })) : null] })) }));
37
+ }
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ export default function TooltipContent(props) {
4
+ const { info, } = props;
5
+ return (_jsx("table", { children: _jsx("tbody", { children: Object.entries(info).map(([key, value]) => (_jsxs("tr", { children: [_jsx("th", { children: key }), _jsx("td", { children: value })] }, key))) }) }));
6
+ }
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Tooltip2D } from './Tooltip2D';
2
+ export { default as Tooltip } from './Tooltip';
3
+ export { default as TooltipContent } from './TooltipContent';
package/dist/styles.js ADDED
@@ -0,0 +1,24 @@
1
+ import { makeStyles } from '@material-ui/core/styles';
2
+ export const styles = makeStyles(() => ({
3
+ tooltipAnchor: {
4
+ position: 'relative',
5
+ width: '0px',
6
+ height: '0px',
7
+ pointerEvents: 'none',
8
+ userSelect: 'none',
9
+ },
10
+ tooltipContent: {
11
+ opacity: 0.9,
12
+ padding: '5px',
13
+ pointerEvents: 'none',
14
+ '& table > tbody > tr > th, & table > tbody > tr > td': {
15
+ fontSize: '80%',
16
+ opacity: 0.8,
17
+ outline: 0,
18
+ padding: '0 2px',
19
+ },
20
+ '& table': {
21
+ borderCollapse: 'collapse',
22
+ },
23
+ },
24
+ }));
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@vitessce/tooltip",
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/vit-s": "2.0.0-beta.0"
18
+ },
19
+ "devDependencies": {
20
+ "react": "^18.0.0",
21
+ "vite": "^3.0.0",
22
+ "vitest": "^0.23.4"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
26
+ },
27
+ "scripts": {
28
+ "start": "tsc --watch",
29
+ "build": "tsc",
30
+ "test": "pnpm exec vitest --run -r ../../ --dir ."
31
+ }
32
+ }