Skip to content

Commit

Permalink
fix: πŸ› [ToolTip] Fixed position on DragAndDrop event
Browse files Browse the repository at this point in the history
Fixed toolTip position, changed height of task and added rows color

βœ… Closes: #147
  • Loading branch information
CrisGrud committed Nov 15, 2023
1 parent bda3c94 commit 02884b8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/grid/Row/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { memo, useMemo } from "react";

import { KonvaLine } from "../../@konva";
import { KonvaGroup, KonvaLine, KonvaRect } from "../../@konva";
import { useTimelineContext } from "../../timeline/TimelineContext";

interface GridRowProps {
Expand All @@ -16,7 +16,14 @@ const GridRow = ({ index }: GridRowProps) => {

const yPos = useMemo(() => rowHeight * (index + 1), [index, rowHeight]);

return <KonvaLine points={[drawRangeStart, yPos, drawRangeEnd, yPos]} stroke={themeColor} />;
const fill = useMemo(() => (index % 2 === 0 ? "#F0F0F0" : "rgb(255,255,255)"), [index]);

return (
<KonvaGroup>
<KonvaLine points={[drawRangeStart, yPos, drawRangeEnd, yPos]} stroke={themeColor} />
<KonvaRect x={drawRangeStart} y={yPos} width={drawRangeEnd - drawRangeStart} height={rowHeight} fill={fill} />
</KonvaGroup>
);
};

export default memo(GridRow);
11 changes: 9 additions & 2 deletions src/resources/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { memo, useMemo } from "react";

import { KonvaGroup, KonvaLine, KonvaText } from "../../../@konva";
import { KonvaGroup, KonvaLine, KonvaRect, KonvaText } from "../../../@konva";
import { useTimelineContext } from "../../../timeline/TimelineContext";
import { DEFAULT_STROKE_WIDTH, DEFAULT_TEXT_SIZE } from "../../../utils/dimensions";
import { Resource, RESOURCE_HEADER_WIDTH, RESOURCE_TEXT_OFFSET } from "../../utils/resources";
Expand Down Expand Up @@ -33,6 +33,8 @@ const ResourceHeader = ({ index, isLast = false, resource }: ResourceHeaderProps

const yCoordinate = useMemo(() => rowHeight * index, [index, rowHeight]);

const fill = useMemo(() => (index % 2 === 0 ? "#F0F0F0" : "rgb(255,255,255)"), [index]);

return (
<KonvaGroup y={yCoordinate}>
<KonvaText
Expand All @@ -43,7 +45,12 @@ const ResourceHeader = ({ index, isLast = false, resource }: ResourceHeaderProps
verticalAlign="middle"
x={RESOURCE_TEXT_OFFSET}
/>
{!isLast && <KonvaLine points={rowPoints} stroke={themeColor} strokeWidth={DEFAULT_STROKE_WIDTH} />}
{!isLast && (
<KonvaGroup>
<KonvaLine points={rowPoints} stroke={themeColor} strokeWidth={DEFAULT_STROKE_WIDTH} />
<KonvaRect x={0} y={rowHeight} width={RESOURCE_HEADER_WIDTH} height={rowHeight} fill={fill} />
</KonvaGroup>
)}
</KonvaGroup>
);
};
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/components/Task/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const Task = ({ data, fill = TASK_DEFAULT_FILL, onLeave, onOver, x, y, width, fi
resolution: { sizeInUnits, unit },
resources,
rowHeight,
drawRange,
} = useTimelineContext();

const { id: taskId, completedPercentage } = data;
Expand Down Expand Up @@ -142,9 +143,9 @@ const Task = ({ data, fill = TASK_DEFAULT_FILL, onLeave, onOver, x, y, width, fi
return;
}

callback(taskId, point);
callback(taskId, { ...point, x: point.x + drawRange.start });
},
[taskId]
[taskId, drawRange]
);

const onClick = useCallback(() => onTaskClick && onTaskClick(data), [data, onTaskClick]);
Expand Down Expand Up @@ -225,7 +226,7 @@ const Task = ({ data, fill = TASK_DEFAULT_FILL, onLeave, onOver, x, y, width, fi

const opacity = useMemo(() => (dragging || resizing ? 0.5 : 1), [dragging, resizing]);

const taskHeight = useMemo(() => rowHeight * 0.8, [rowHeight]);
const taskHeight = useMemo(() => rowHeight * 0.7, [rowHeight]);

const textOffsets = useMemo(() => taskHeight / 3, [taskHeight]);

Expand Down
11 changes: 2 additions & 9 deletions src/tasks/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { FC, useMemo } from "react";
import React, { FC } from "react";
import { Label, Tag, Text } from "react-konva";

import { useTimelineContext } from "../../../timeline/TimelineContext";
import { KonvaPoint } from "../../../utils/konva";
import { TaskData } from "../../utils/tasks";

Expand All @@ -18,14 +17,8 @@ const TASK_TOOLTIP_SHADOW_SIZE = 10;
* This component renders a task tooltip inside a canvas.
*/
const TaskTooltip: FC<TaskTooltipProps> = ({ task: { label: taskLabel }, x, y }) => {
const {
drawRange: { start: drawRangeStart },
} = useTimelineContext();

const xPos = useMemo(() => x + drawRangeStart, [drawRangeStart, x]);

return (
<Label x={xPos} y={y} opacity={0.75}>
<Label x={x} y={y} opacity={0.75}>
<Tag
fill={TASK_TOOLTIP_BACKGROUND}
lineJoin="round"
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/utils/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface TaskData<T extends TimeRange = TimeRange> {

type FilteredTasks = Operation<TaskData<InternalTimeRange>>;

const TASK_OFFSET_Y = 0.1;
const TASK_OFFSET_Y = 0.15;

export const TASK_BORDER_RADIUS = 4;

Expand Down

0 comments on commit 02884b8

Please sign in to comment.