Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { emDashPipe } from '../../../../utils/pipes';
import { formatDateOnly } from 'shared';

interface GanttToolTipProps {
xCoordinate: number;
yCoordinate: number;
title: string;
startDate?: Date;
Expand All @@ -14,6 +15,7 @@ interface GanttToolTipProps {
}

const GanttToolTip: React.FC<GanttToolTipProps> = ({
xCoordinate,
yCoordinate,
title,
startDate,
Expand All @@ -22,15 +24,18 @@ const GanttToolTip: React.FC<GanttToolTipProps> = ({
lowerRightDisplay
}) => {
const theme = useTheme();
const xCoordinate = window.innerWidth - 375 - 35;
const tooltipWidth = 375;
const horizontalPadding = 16;
const left = Math.min(Math.max(horizontalPadding, xCoordinate + 12), window.innerWidth - tooltipWidth - horizontalPadding);

return (
<Box
style={{
position: 'fixed',
left: `${xCoordinate}px`,
left: `${left}px`,
top: `${yCoordinate + 20}px`,
zIndex: 4,
width: 375
width: tooltipWidth
}}
>
<Box color={'white'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,25 @@ interface GanttChartSectionProps<T> {
}

interface GanttTooltipLayerProps {
updateRef: MutableRefObject<(options: OnMouseOverOptions | undefined, y?: number) => void>;
updateRef: MutableRefObject<(options: OnMouseOverOptions | undefined, x?: number, y?: number) => void>;
}

const GanttTooltipLayer: React.FC<GanttTooltipLayerProps> = ({ updateRef }) => {
const [tooltipOptions, setTooltipOptions] = useState<OnMouseOverOptions | undefined>(undefined);
const [cursorX, setCursorX] = useState(0);
const [cursorY, setCursorY] = useState(0);

updateRef.current = (options, y = 0) => {
updateRef.current = (options, x = 0, y = 0) => {
setTooltipOptions(options);
if (options && x !== undefined && x !== null) setCursorX(x);
if (options && y !== undefined && y !== null) setCursorY(y);
};

if (!tooltipOptions) return null;

return (
<GanttToolTip
xCoordinate={cursorX}
yCoordinate={cursorY}
title={tooltipOptions.name}
startDate={tooltipOptions.start}
Expand Down Expand Up @@ -73,11 +76,11 @@ const GanttChartSection = <T,>({
const archerRef = useRef<ArcherContainerRef>(null);
const handleToggle = useCallback(() => archerRef.current?.refreshScreen(), []);

const updateTooltip = useRef<(options: OnMouseOverOptions | undefined, y?: number) => void>(() => {});
const updateTooltip = useRef<(options: OnMouseOverOptions | undefined, x?: number, y?: number) => void>(() => {});

const handleOnMouseOver = useCallback(
(e: React.MouseEvent, task: OnMouseOverOptions) => {
if (!isEditMode) updateTooltip.current(task, e.clientY);
if (!isEditMode) updateTooltip.current(task, e.clientX, e.clientY);
},
[isEditMode]
);
Expand Down
Loading