-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FE] feat#254 그래프 hover시에 툴팁으로 커밋 정보 안내, UX 개선 #294
Changes from all commits
5502f84
6d6b781
9887d5f
eac6546
0d0badc
202cd8a
64f816c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import * as d3 from "d3"; | ||
|
||
import color from "../../design-system/tokens/color"; | ||
|
||
import { InitialDataProps } from "./parsing"; | ||
|
||
interface TooltipProps { | ||
text: string; | ||
value: string; | ||
id: string; | ||
} | ||
|
||
export default function renderTooltip( | ||
svg: d3.Selection<SVGGElement | null, unknown, null, undefined>, | ||
d: d3.HierarchyPointNode<InitialDataProps>, | ||
) { | ||
const tooltipStyle = { | ||
width: 220, | ||
height: 40, | ||
borderRadius: 5, | ||
position: `translate(${d.x - 110},${d.y - 60})`, | ||
}; | ||
|
||
const transparentRectPosition = "translate(95, 40)"; | ||
|
||
const tooltipDataFormat = [ | ||
{ | ||
text: "Commit Hash: ", | ||
value: d.data.id.slice(0, 7), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해시 7자리만 보여주는 거 너무 좋아요! |
||
id: "text", | ||
}, | ||
{ | ||
text: "Commit Message: ", | ||
value: d.data.message, | ||
id: "value", | ||
}, | ||
]; | ||
|
||
// hover 시 보이는 툴팁 | ||
const tooltip = svg | ||
.select("#node") | ||
.append("g") | ||
.attr("id", "tooltip") | ||
.attr("tabindex", 0) | ||
.attr("transform", tooltipStyle.position); | ||
|
||
tooltip | ||
.append("rect") | ||
.attr("width", tooltipStyle.width) | ||
.attr("height", tooltipStyle.height) | ||
.attr("rx", tooltipStyle.borderRadius) | ||
.attr("ry", tooltipStyle.borderRadius) | ||
.attr("fill", color.$semantic.bgDefault) | ||
.attr("stroke", color.$scale.grey300); | ||
|
||
// 투명한 네모를 위에 위치시키기 | ||
tooltip | ||
.append("rect") | ||
.attr("width", 30) | ||
.attr("height", 30) | ||
// 요기 바꿔보심 돼여 | ||
.attr("fill", "transparent") | ||
.style("cursor", "pointer") | ||
.attr("transform", transparentRectPosition); | ||
Comment on lines
+56
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 방법도 있네요 굿굿!👍👍👍👍 |
||
|
||
tooltip | ||
.append("text") | ||
.attr("x", 0) | ||
.attr("y", 16.5) | ||
.selectAll("tspan") | ||
.data(tooltipDataFormat) | ||
.enter() | ||
.append("tspan") | ||
.attr("x", 6) | ||
.attr("dy", (_: TooltipProps, index: number) => index * 15) // Adjust the line height as needed | ||
.text((tooltipData: TooltipProps) => tooltipData.text) | ||
.attr("fill", color.$scale.grey600) | ||
.append("tspan") | ||
.attr("fill", color.$scale.grey700) | ||
.text((tooltipData: TooltipProps) => tooltipData.value) | ||
.attr("id", (tooltipData: TooltipProps) => tooltipData.id) | ||
.each(() => { | ||
const currentValueNode: d3.Selection< | ||
SVGTSpanElement | null, | ||
unknown, | ||
HTMLElement, | ||
undefined | ||
> = d3.select("#value"); | ||
|
||
if (!currentValueNode.empty() && currentValueNode.node()) { | ||
const tspanMaxWidth = 110; | ||
const originalText = currentValueNode.text(); | ||
if (currentValueNode.node()!.getComputedTextLength() < tspanMaxWidth) { | ||
return; | ||
} | ||
|
||
let start = 0; | ||
let end = tspanMaxWidth; | ||
let mid; | ||
while (start < end) { | ||
mid = Math.floor((start + end) / 2); | ||
const truncatedText = `${originalText.slice(0, mid)}...`; | ||
currentValueNode.text(truncatedText); // Set text here for width calculation | ||
const textWidth = | ||
currentValueNode?.node()?.getComputedTextLength() || 0; | ||
if (textWidth > tspanMaxWidth) { | ||
end = mid; | ||
} else { | ||
start = mid + 1; | ||
} | ||
} | ||
const truncatedText = `${originalText.slice(0, start - 1)}...`; | ||
currentValueNode.text(truncatedText); | ||
Comment on lines
+96
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말줄임에 이분 탐색이 사용되다니 신기해요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 맞습니다!!🤩 |
||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderTooltip
을 호출하는 쪽에서 타입 가드하면 여기 타입을 좁힐 수 있을 거 같지만..아직 D3 타입이 익숙하지 않아서 모르겠네요. 나중에 개선하면 좋을 것 같아요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞아요ㅠㅠ 저도 이걸로 고민했는데 당장은 떠오르지 않아서 우선 IDE에 뜨는 타입대로 작성하였습니다! 추후에 수정해볼게요!