@vitessce/tooltip 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.
@@ -0,0 +1,2 @@
1
+ export default function Tooltip(props: any): JSX.Element;
2
+ //# sourceMappingURL=Tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../src/Tooltip.js"],"names":[],"mappings":"AAKA,yDA+CC"}
@@ -1,9 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React, { useEffect, useRef, useState } from 'react';
3
- import Paper from '@material-ui/core/Paper';
4
- import Popper from '@material-ui/core/Popper';
3
+ import { Paper, Popper } from '@material-ui/core';
5
4
  import { useVitessceContainer } from '@vitessce/vit-s';
6
- import { styles } from './styles';
5
+ import { styles } from './styles.js';
7
6
  export default function Tooltip(props) {
8
7
  const { x, y, parentWidth, parentHeight, children, } = props;
9
8
  const ref = useRef();
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A tooltip component that also incorporates a crosshair element.
3
+ * @param {object} props
4
+ * @param {string} props.parentUuid A unique identifier corresponding to the plot
5
+ * with which this scatterplot is associated.
6
+ * @param {string} props.sourceUuid A unique identifier corresponding to the plot
7
+ * from which this tooltip originated.
8
+ * @param {number} props.x The x coordinate for the tooltip.
9
+ * @param {number} props.y The y coordinate for the tooltip.
10
+ * @param {number} props.parentWidth The width of the parent plot container element.
11
+ * @param {number} props.parentHeight The height of the parent plot container element.
12
+ * @param {React.Component} props.children The tooltip contents as a react component.
13
+ */
14
+ export default function Tooltip2D(props: {
15
+ parentUuid: string;
16
+ sourceUuid: string;
17
+ x: number;
18
+ y: number;
19
+ parentWidth: number;
20
+ parentHeight: number;
21
+ children: React.Component;
22
+ }): JSX.Element | null;
23
+ //# sourceMappingURL=Tooltip2D.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tooltip2D.d.ts","sourceRoot":"","sources":["../src/Tooltip2D.js"],"names":[],"mappings":"AAcA;;;;;;;;;;;;GAYG;AACH;IAVyB,UAAU,EAAxB,MAAM;IAEQ,UAAU,EAAxB,MAAM;IAEQ,CAAC,EAAf,MAAM;IACQ,CAAC,EAAf,MAAM;IACQ,WAAW,EAAzB,MAAM;IACQ,YAAY,EAA1B,MAAM;IACiB,QAAQ;uBA6DzC"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { makeStyles } from '@material-ui/core/styles';
4
- import Tooltip from './Tooltip';
3
+ import { makeStyles } from '@material-ui/core';
4
+ import Tooltip from './Tooltip.js';
5
5
  const useStyles = makeStyles(theme => ({
6
6
  cellEmphasisCrosshair: {
7
7
  zIndex: 50,
@@ -0,0 +1,2 @@
1
+ export default function TooltipContent(props: any): JSX.Element;
2
+ //# sourceMappingURL=TooltipContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TooltipContent.d.ts","sourceRoot":"","sources":["../src/TooltipContent.js"],"names":[],"mappings":"AAEA,gEAiBC"}
@@ -0,0 +1,5 @@
1
+ export { default as Tooltip2D } from "./Tooltip2D.js";
2
+ export { default as Tooltip } from "./Tooltip.js";
3
+ export { default as TooltipContent } from "./TooltipContent.js";
4
+ export { styles as useTooltipStyles } from "./styles.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export { default as Tooltip2D } from './Tooltip2D.js';
2
+ export { default as Tooltip } from './Tooltip.js';
3
+ export { default as TooltipContent } from './TooltipContent.js';
4
+ export { styles as useTooltipStyles } from './styles.js';
@@ -0,0 +1,2 @@
1
+ export const styles: (props?: any) => import("@material-ui/core/styles/withStyles").ClassNameMap<"tooltipAnchor" | "tooltipContent">;
2
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.js"],"names":[],"mappings":"AAEA,qIAgCI"}
@@ -0,0 +1,34 @@
1
+ import { makeStyles } from '@material-ui/core';
2
+ export const styles = makeStyles(theme => ({
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
+ backgroundColor: theme.palette.gridLayoutBackground,
15
+ '& table > tbody > tr > th, & table > tbody > tr > td': {
16
+ border: 'none',
17
+ fontSize: '12px',
18
+ lineHeight: 1.43,
19
+ opacity: 0.8,
20
+ outline: 0,
21
+ padding: '0 2px !important',
22
+ textAlign: 'left',
23
+ color: theme.palette.tooltipText,
24
+ backgroundColor: theme.palette.gridLayoutBackground,
25
+ },
26
+ '& table > tr:nth-child(2)': {
27
+ backgroundColor: 'inherit !important',
28
+ },
29
+ '& table': {
30
+ borderCollapse: 'collapse',
31
+ marginBottom: '0px',
32
+ },
33
+ },
34
+ }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/tooltip",
3
- "version": "2.0.3-beta.0",
3
+ "version": "3.0.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -8,25 +8,34 @@
8
8
  "url": "git+https://github.com/vitessce/vitessce.git"
9
9
  },
10
10
  "license": "MIT",
11
+ "type": "module",
11
12
  "main": "dist/index.js",
12
13
  "files": [
13
- "dist"
14
+ "src",
15
+ "dist",
16
+ "dist-tsc"
14
17
  ],
15
18
  "dependencies": {
16
19
  "@material-ui/core": "~4.12.3",
17
- "@vitessce/vit-s": "2.0.3-beta.0"
20
+ "@vitessce/vit-s": "3.0.0"
18
21
  },
19
22
  "devDependencies": {
20
23
  "react": "^18.0.0",
21
- "vite": "^3.0.0",
24
+ "vite": "^4.3.0",
22
25
  "vitest": "^0.23.4"
23
26
  },
24
27
  "peerDependencies": {
25
28
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
26
29
  },
27
30
  "scripts": {
28
- "start": "tsc --watch",
29
- "build": "tsc",
31
+ "bundle": "pnpm exec vite build -c ../../scripts/vite.config.js",
30
32
  "test": "pnpm exec vitest --run -r ../../ --dir ."
33
+ },
34
+ "module": "dist/index.js",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist-tsc/index.d.ts",
38
+ "import": "./dist/index.js"
39
+ }
31
40
  }
32
41
  }
package/src/Tooltip.js ADDED
@@ -0,0 +1,53 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { Paper, Popper } from '@material-ui/core';
3
+ import { useVitessceContainer } from '@vitessce/vit-s';
4
+ import { styles } from './styles.js';
5
+
6
+ export default function Tooltip(props) {
7
+ const {
8
+ x,
9
+ y,
10
+ parentWidth,
11
+ parentHeight,
12
+ children,
13
+ } = props;
14
+ const ref = useRef();
15
+ const classes = styles();
16
+ const [placementX, setPlacementX] = useState('start');
17
+ const [placementY, setPlacementY] = useState('bottom');
18
+
19
+ const getTooltipContainer = useVitessceContainer(ref);
20
+
21
+ // Do collision detection based on the bounds of the tooltip ancestor element.
22
+ useEffect(() => {
23
+ if (ref && ref.current) {
24
+ const flipX = (x > parentWidth / 2);
25
+ const flipY = (y > parentHeight / 2);
26
+ setPlacementX(flipX ? 'end' : 'start');
27
+ setPlacementY(flipY ? 'top' : 'bottom');
28
+ ref.current.style.left = `${x + (flipX ? -20 : 5)}px`;
29
+ ref.current.style.top = `${y + (flipY ? -20 : 5)}px`;
30
+ }
31
+ }, [x, y, parentWidth, parentHeight]);
32
+
33
+ return (
34
+ <div
35
+ ref={ref}
36
+ className={classes.tooltipAnchor}
37
+ >
38
+ {ref && ref.current ? (
39
+ <Popper
40
+ open
41
+ anchorEl={ref.current}
42
+ container={getTooltipContainer}
43
+ transition
44
+ placement={`${placementY}-${placementX}`}
45
+ >
46
+ <Paper elevation={4} className={classes.tooltipContent}>
47
+ {children}
48
+ </Paper>
49
+ </Popper>
50
+ ) : null}
51
+ </div>
52
+ );
53
+ }
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import { makeStyles } from '@material-ui/core';
3
+ import Tooltip from './Tooltip.js';
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,4 @@
1
+ export { default as Tooltip2D } from './Tooltip2D.js';
2
+ export { default as Tooltip } from './Tooltip.js';
3
+ export { default as TooltipContent } from './TooltipContent.js';
4
+ export { styles as useTooltipStyles } from './styles.js';
package/src/styles.js ADDED
@@ -0,0 +1,35 @@
1
+ import { makeStyles } from '@material-ui/core';
2
+
3
+ export const styles = makeStyles(theme => ({
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
+ backgroundColor: theme.palette.gridLayoutBackground,
16
+ '& table > tbody > tr > th, & table > tbody > tr > td': {
17
+ border: 'none',
18
+ fontSize: '12px',
19
+ lineHeight: 1.43,
20
+ opacity: 0.8,
21
+ outline: 0,
22
+ padding: '0 2px !important',
23
+ textAlign: 'left',
24
+ color: theme.palette.tooltipText,
25
+ backgroundColor: theme.palette.gridLayoutBackground,
26
+ },
27
+ '& table > tr:nth-child(2)': {
28
+ backgroundColor: 'inherit !important',
29
+ },
30
+ '& table': {
31
+ borderCollapse: 'collapse',
32
+ marginBottom: '0px',
33
+ },
34
+ },
35
+ }));
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
- }));
File without changes