@vitessce/tooltip 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.
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/tooltip",
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,13 +8,14 @@
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",
17
- "@vitessce/vit-s": "2.0.2"
18
+ "@vitessce/vit-s": "2.0.3"
18
19
  },
19
20
  "devDependencies": {
20
21
  "react": "^18.0.0",
@@ -25,8 +26,7 @@
25
26
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
26
27
  },
27
28
  "scripts": {
28
- "start": "tsc --watch",
29
- "build": "tsc",
29
+ "bundle": "pnpm exec vite build -c ../../scripts/vite.config.js",
30
30
  "test": "pnpm exec vitest --run -r ../../ --dir ."
31
31
  }
32
32
  }
package/src/Tooltip.js ADDED
@@ -0,0 +1,54 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import Paper from '@material-ui/core/Paper';
3
+ import Popper from '@material-ui/core/Popper';
4
+ import { useVitessceContainer } from '@vitessce/vit-s';
5
+ import { styles } from './styles';
6
+
7
+ export default function Tooltip(props) {
8
+ const {
9
+ x,
10
+ y,
11
+ parentWidth,
12
+ parentHeight,
13
+ children,
14
+ } = props;
15
+ const ref = useRef();
16
+ const classes = styles();
17
+ const [placementX, setPlacementX] = useState('start');
18
+ const [placementY, setPlacementY] = useState('bottom');
19
+
20
+ const getTooltipContainer = useVitessceContainer(ref);
21
+
22
+ // Do collision detection based on the bounds of the tooltip ancestor element.
23
+ useEffect(() => {
24
+ if (ref && ref.current) {
25
+ const flipX = (x > parentWidth / 2);
26
+ const flipY = (y > parentHeight / 2);
27
+ setPlacementX(flipX ? 'end' : 'start');
28
+ setPlacementY(flipY ? 'top' : 'bottom');
29
+ ref.current.style.left = `${x + (flipX ? -20 : 5)}px`;
30
+ ref.current.style.top = `${y + (flipY ? -20 : 5)}px`;
31
+ }
32
+ }, [x, y, parentWidth, parentHeight]);
33
+
34
+ return (
35
+ <div
36
+ ref={ref}
37
+ className={classes.tooltipAnchor}
38
+ >
39
+ {ref && ref.current ? (
40
+ <Popper
41
+ open
42
+ anchorEl={ref.current}
43
+ container={getTooltipContainer}
44
+ transition
45
+ placement={`${placementY}-${placementX}`}
46
+ >
47
+ <Paper elevation={4} className={classes.tooltipContent}>
48
+ {children}
49
+ </Paper>
50
+ </Popper>
51
+ ) : null}
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import { makeStyles } from '@material-ui/core/styles';
3
+ import Tooltip from './Tooltip';
4
+
5
+ const useStyles = makeStyles(theme => ({
6
+ cellEmphasisCrosshair: {
7
+ zIndex: 50,
8
+ position: 'absolute',
9
+ pointerEvents: 'none',
10
+ boxSizing: 'border-box',
11
+ backgroundColor: theme.palette.secondaryForeground,
12
+ },
13
+ }));
14
+
15
+ /**
16
+ * A tooltip component that also incorporates a crosshair element.
17
+ * @param {object} props
18
+ * @param {string} props.parentUuid A unique identifier corresponding to the plot
19
+ * with which this scatterplot is associated.
20
+ * @param {string} props.sourceUuid A unique identifier corresponding to the plot
21
+ * from which this tooltip originated.
22
+ * @param {number} props.x The x coordinate for the tooltip.
23
+ * @param {number} props.y The y coordinate for the tooltip.
24
+ * @param {number} props.parentWidth The width of the parent plot container element.
25
+ * @param {number} props.parentHeight The height of the parent plot container element.
26
+ * @param {React.Component} props.children The tooltip contents as a react component.
27
+ */
28
+ export default function Tooltip2D(props) {
29
+ const {
30
+ parentUuid,
31
+ sourceUuid,
32
+ x,
33
+ y,
34
+ parentWidth,
35
+ parentHeight,
36
+ children,
37
+ } = props;
38
+
39
+ const classes = useStyles();
40
+
41
+ // Check if out of bounds.
42
+ if (x < 0 || x > parentWidth || y < 0 || y > parentHeight) {
43
+ return null;
44
+ }
45
+ // Show tooltip or crosshair?
46
+ const isTooltipVisible = (parentUuid === sourceUuid);
47
+ const crosshairWidth = 1;
48
+ return (
49
+ <>
50
+ {isTooltipVisible ? (
51
+ <Tooltip
52
+ x={x}
53
+ y={y}
54
+ parentWidth={parentWidth}
55
+ parentHeight={parentHeight}
56
+ >
57
+ {children}
58
+ </Tooltip>
59
+ ) : (
60
+ <>
61
+ {x !== null ? (
62
+ <div
63
+ className={classes.cellEmphasisCrosshair}
64
+ style={{
65
+ left: `${x - crosshairWidth / 2}px`,
66
+ top: 0,
67
+ width: `${crosshairWidth}px`,
68
+ height: `${parentHeight}px`,
69
+ }}
70
+ />
71
+ ) : null}
72
+ {y !== null ? (
73
+ <div
74
+ className={classes.cellEmphasisCrosshair}
75
+ style={{
76
+ left: 0,
77
+ top: `${y - crosshairWidth / 2}px`,
78
+ width: `${parentWidth}px`,
79
+ height: `${crosshairWidth}px`,
80
+ }}
81
+ />
82
+ ) : null}
83
+ </>
84
+ )}
85
+ </>
86
+ );
87
+ }
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ export default function TooltipContent(props) {
4
+ const {
5
+ info,
6
+ } = props;
7
+
8
+ return (
9
+ <table>
10
+ <tbody>
11
+ {Object.entries(info).map(([key, value]) => (
12
+ <tr key={key}>
13
+ <th>{key}</th>
14
+ <td>{value}</td>
15
+ </tr>
16
+ ))}
17
+ </tbody>
18
+ </table>
19
+ );
20
+ }
package/src/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/src/styles.js ADDED
@@ -0,0 +1,25 @@
1
+ import { makeStyles } from '@material-ui/core/styles';
2
+
3
+ export const styles = makeStyles(() => ({
4
+ tooltipAnchor: {
5
+ position: 'relative',
6
+ width: '0px',
7
+ height: '0px',
8
+ pointerEvents: 'none',
9
+ userSelect: 'none',
10
+ },
11
+ tooltipContent: {
12
+ opacity: 0.9,
13
+ padding: '5px',
14
+ pointerEvents: 'none',
15
+ '& table > tbody > tr > th, & table > tbody > tr > td': {
16
+ fontSize: '80%',
17
+ opacity: 0.8,
18
+ outline: 0,
19
+ padding: '0 2px',
20
+ },
21
+ '& table': {
22
+ borderCollapse: 'collapse',
23
+ },
24
+ },
25
+ }));
package/dist/Tooltip.js DELETED
@@ -1,26 +0,0 @@
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
- }
package/dist/Tooltip2D.js DELETED
@@ -1,48 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { makeStyles } from '@material-ui/core/styles';
4
- import Tooltip from './Tooltip';
5
- const useStyles = makeStyles(theme => ({
6
- cellEmphasisCrosshair: {
7
- zIndex: 50,
8
- position: 'absolute',
9
- pointerEvents: 'none',
10
- boxSizing: 'border-box',
11
- backgroundColor: theme.palette.secondaryForeground,
12
- },
13
- }));
14
- /**
15
- * A tooltip component that also incorporates a crosshair element.
16
- * @param {object} props
17
- * @param {string} props.parentUuid A unique identifier corresponding to the plot
18
- * with which this scatterplot is associated.
19
- * @param {string} props.sourceUuid A unique identifier corresponding to the plot
20
- * from which this tooltip originated.
21
- * @param {number} props.x The x coordinate for the tooltip.
22
- * @param {number} props.y The y coordinate for the tooltip.
23
- * @param {number} props.parentWidth The width of the parent plot container element.
24
- * @param {number} props.parentHeight The height of the parent plot container element.
25
- * @param {React.Component} props.children The tooltip contents as a react component.
26
- */
27
- export default function Tooltip2D(props) {
28
- const { parentUuid, sourceUuid, x, y, parentWidth, parentHeight, children, } = props;
29
- const classes = useStyles();
30
- // Check if out of bounds.
31
- if (x < 0 || x > parentWidth || y < 0 || y > parentHeight) {
32
- return null;
33
- }
34
- // Show tooltip or crosshair?
35
- const isTooltipVisible = (parentUuid === sourceUuid);
36
- const crosshairWidth = 1;
37
- 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: classes.cellEmphasisCrosshair, style: {
38
- left: `${x - crosshairWidth / 2}px`,
39
- top: 0,
40
- width: `${crosshairWidth}px`,
41
- height: `${parentHeight}px`,
42
- } })) : null, y !== null ? (_jsx("div", { className: classes.cellEmphasisCrosshair, style: {
43
- left: 0,
44
- top: `${y - crosshairWidth / 2}px`,
45
- width: `${parentWidth}px`,
46
- height: `${crosshairWidth}px`,
47
- } })) : null] })) }));
48
- }
@@ -1,6 +0,0 @@
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/styles.js DELETED
@@ -1,24 +0,0 @@
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
- }));