Skip to content

Commit

Permalink
feat: 노드 hover시에 툴팁 삭제되게 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yunchaehyun authored and flydog98 committed Dec 14, 2023
1 parent 5239699 commit 21bee84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/frontend/src/components/graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ function renderD3(svgRef: RefObject<SVGGElement>, data: InitialDataProps[]) {
"fill",
(d: d3.HierarchyPointNode<InitialDataProps>) => d.data?.color ?? "",
);

svg.select("#node").on("mouseout", (event) => {
const nodeNotHovered = !(
event.relatedTarget.nodeName === "rect" ||
event.relatedTarget.nodeName === "tspan"
);

if (nodeNotHovered) {
svg.select("#tooltip").remove();
}
});
}

interface GraphProps {
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/components/graph/renderTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function renderTooltip(
position: `translate(${d.x - 110},${d.y - 60})`,
};

const transparentRectPosition = "translate(85, 40)";
const transparentRectPosition = "translate(95, 40)";

const tooltipDataFormat = [
{
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function renderTooltip(
// 요기나
.attr("fill", "transparent")
// 요기 바꿔보심 돼여
// .attr("stroke", color.$scale.grey300)
.attr("stroke", color.$scale.grey300)
.attr("transform", transparentRectPosition);

tooltip
Expand Down Expand Up @@ -91,6 +91,9 @@ export default function renderTooltip(
if (!currentValueNode.empty() && currentValueNode.node()) {
const tspanMaxWidth = 110;
const originalText = currentValueNode.text();
if (currentValueNode.node()!.getComputedTextLength() < tspanMaxWidth) {
return;
}

let start = 0;
let end = tspanMaxWidth;
Expand Down

0 comments on commit 21bee84

Please sign in to comment.