Skip to content

Commit

Permalink
Simplify with placement:right
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 1, 2023
1 parent 4f440c9 commit 782b2b8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 37 deletions.
16 changes: 2 additions & 14 deletions plugins/dotplot-view/src/DotplotView/components/DotplotTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,17 @@ type Coord = [number, number] | undefined
export const TooltipWhereMouseovered = observer(function ({
model,
mouserect,
mouserectClient,
xdistance,
ydistance,
}: {
model: DotplotViewModel
mouserect: Coord
mouserectClient: Coord
xdistance: number
ydistance: number
}) {
const { classes } = useStyles()
const { hview, vview, viewHeight } = model
const theme = useTheme()
const x = (mouserectClient?.[0] || 0) - (xdistance < 0 ? 0 : 0)
const y = (mouserectClient?.[1] || 0) - (ydistance < 0 ? 0 : 0)

const { refs, floatingStyles, context } = useFloating({
open: true,
onOpenChange: () => {},
placement: xdistance < 0 ? 'left' : 'right',
})

Expand All @@ -72,7 +64,6 @@ export const TooltipWhereMouseovered = observer(function ({
ref={refs.setFloating}
style={{
...floatingStyles,
transform: `translate(${Math.round(x)}px,${Math.round(y)}px)`,
zIndex: 100000,
pointerEvents: 'none',
}}
Expand Down Expand Up @@ -107,12 +98,10 @@ export const TooltipWhereClicked = observer(function ({
const y = (mousedownClient?.[1] || 0) - (ydistance < 0 ? 0 : 0)

const { refs, floatingStyles, context } = useFloating({
open: true,
onOpenChange: () => {},
placement: xdistance < 0 ? 'left' : 'right',
placement: xdistance < 0 ? 'right' : 'left',
})

const clientPoint = useClientPoint(context)
const clientPoint = useClientPoint(context, { x, y })
const { getFloatingProps } = useInteractions([clientPoint])

const popperTheme = theme?.components?.MuiPopper
Expand All @@ -123,7 +112,6 @@ export const TooltipWhereClicked = observer(function ({
ref={refs.setFloating}
style={{
...floatingStyles,
transform: `translate(${Math.round(x)}px,${Math.round(y)}px)`,
zIndex: 100000,
pointerEvents: 'none',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ const DotplotViewInternal = observer(function ({
<TooltipWhereMouseovered
model={model}
mouserect={mouserect}
mouserectClient={mouserectClient}
xdistance={xdistance}
ydistance={ydistance}
/>
) : null}
{validSelect ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const LinearSyntenyRendering = observer(function ({
height={height}
/>
{model.mouseoverId && tooltip && currX && currY ? (
<SyntenyTooltip x={currX} y={currY} title={tooltip} />
<SyntenyTooltip title={tooltip} />
) : null}
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,12 @@ const useStyles = makeStyles()(theme => ({
},
}))

const SyntenyTooltip = observer(function ({
x,
y,
title,
}: {
x: number
y: number
title: string
}) {
const SyntenyTooltip = observer(function ({ title }: { title: string }) {
const theme = useTheme()
const { classes } = useStyles()

const { refs, floatingStyles, context } = useFloating({
open: true,
onOpenChange: () => {},
placement: 'right',
})

const clientPoint = useClientPoint(context)
Expand All @@ -60,7 +51,6 @@ const SyntenyTooltip = observer(function ({
ref={refs.setFloating}
style={{
...floatingStyles,
transform: `translate(${Math.round(x + 15)}px,${Math.round(y)}px)`,
zIndex: 100000,
pointerEvents: 'none',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ const Tooltip = observer(function ({
const y = clientMouseCoord[1]

const { refs, floatingStyles, context } = useFloating({
open: true,
onOpenChange: () => {},
placement: 'right',
})

const clientPoint = useClientPoint(context)
const clientPoint = useClientPoint(context, { x, y })
const { getFloatingProps } = useInteractions([clientPoint])

const contents = featureUnderMouse
Expand All @@ -84,7 +83,6 @@ const Tooltip = observer(function ({
ref={refs.setFloating}
style={{
...floatingStyles,
transform: `translate(${Math.round(x)}px,${Math.round(y)}px)`,
zIndex: 100000,
pointerEvents: 'none',
}}
Expand Down
9 changes: 5 additions & 4 deletions plugins/wiggle/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ const Tooltip = observer(function Tooltip({
const { refs, floatingStyles, context } = useFloating({
open: true,
onOpenChange: () => {},
placement: 'right',
})

const clientPoint = useClientPoint(context)
const x = clientMouseCoord[0] + 5
const y = useClientY ? clientMouseCoord[1] : clientRect?.top || 0
const clientPoint = useClientPoint(context, { x, y })
const { getFloatingProps } = useInteractions([clientPoint])

const popperTheme = theme?.components?.MuiPopper
const x = clientMouseCoord[0] + 5
const y = useClientY ? clientMouseCoord[1] : clientRect?.top || 0

return featureUnderMouse ? (
<>
<Portal container={popperTheme?.defaultProps?.container}>
Expand All @@ -88,7 +90,6 @@ const Tooltip = observer(function Tooltip({
ref={refs.setFloating}
style={{
...floatingStyles,
transform: `translate(${Math.round(x)}px,${Math.round(y)}px)`,
zIndex: 100000,
pointerEvents: 'none',
}}
Expand Down

0 comments on commit 782b2b8

Please sign in to comment.