Skip to content

Commit 7c38d91

Browse files
committed
Highlight ancestors on child node hover
1 parent 5b2b181 commit 7c38d91

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

redisinsight/ui/src/packages/ri-explain/src/Explain.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,34 +138,31 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
138138
graph.on("resize", () => graph.centerContent())
139139
graph.on("node:mouseenter", x => {
140140
const {id} = x.node.getData()
141+
// Find ancestors of a node
141142
const ancestors = GetAncestors(data, id, {found: false, pairs: []})
142-
if (ancestors.found) {
143-
ancestors.pairs.forEach(p => {
144-
const parentNode = document.querySelector(`#node-${p[0]}`)
145-
parentNode?.classList.add('ProfileContainerHover')
146-
document.querySelector(`[data-cell-id='${p[0]}-${p[1]}']`)?.childNodes.forEach((k: any) => {
147-
148-
const entityNode = document.querySelector(`#node-${p[1]}`) as any
149-
150-
const strokeSize = getEdgeSize(parseInt(entityNode?.dataset?.size)) + 1;
151-
k.setAttribute("style", `stroke: #85A2FE; stroke-linecap: butt; stroke-width: ${strokeSize}px`)
152-
})
153-
})
154-
}
143+
ancestors.pairs.forEach(p => {
144+
// Highlight ancestor and their ancestor
145+
document.querySelector(`#node-${p[0]}`)?.setAttribute("style", "border: 1px solid #85A2FE !important;")
146+
147+
// Get edge size of parent ancestor to apply the right edge stroke
148+
const strokeSize = getEdgeSize(parseInt((document.querySelector(`#node-${p[1]}`) as HTMLElement)?.dataset?.size || '')) + 1
149+
document.querySelector(`[data-cell-id='${p[0]}-${p[1]}']`)?.childNodes.forEach(k =>
150+
(k as HTMLElement)
151+
.setAttribute(
152+
"style",
153+
`stroke: #85A2FE; stroke-linecap: butt; stroke-width: ${strokeSize}px`
154+
)
155+
)
156+
})
155157
})
156158

157159
graph.on("node:mouseleave", x => {
158160
const {id} = x.node.getData()
159161
const ancestors = GetAncestors(data, id, {found: false, pairs: []})
160-
if (ancestors.found) {
161-
ancestors.pairs.forEach(p => {
162-
const parentNode = document.querySelector(`#node-${p[0]}`)
163-
parentNode?.classList.remove('ProfileContainerHover')
164-
document.querySelector(`[data-cell-id='${p[0]}-${p[1]}']`)?.childNodes.forEach(k => {
165-
(k as any).setAttribute("style", "")
166-
})
167-
})
168-
}
162+
ancestors.pairs.forEach(p => {
163+
document.querySelector(`#node-${p[0]}`)?.setAttribute("style", "")
164+
document.querySelector(`[data-cell-id='${p[0]}-${p[1]}']`)?.childNodes.forEach(k => (k as HTMLElement).setAttribute("style", ""))
165+
})
169166
})
170167

171168
function resize() {

redisinsight/ui/src/packages/ri-explain/src/Node.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ interface INodeProps {
1212

1313
export function ExplainNode(props: INodeProps) {
1414
const propData: EntityInfo = (props as any).node.getData()
15-
const { type, data, snippet } = propData
15+
const { id, type, data, snippet } = propData
1616
return (
17-
<div className="ExplainContainer">
17+
<div className="ExplainContainer" id={`node-${id}`}>
1818
<div className="Main">
1919
<div className="Info">
2020
<div>{data ? data : type}</div>

redisinsight/ui/src/packages/ri-explain/src/styles/styles.less

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@
8080
background-color: var(--tooltip-background) !important;
8181
}
8282

83-
.ProfileContainerHover {
84-
border: 1px solid #85A2FE !important;
85-
86-
width: 50px;
87-
}
88-
8983
.ProfileContainer {
9084
width: 320px;
9185
min-height: 84px;
@@ -106,7 +100,8 @@
106100
color: var(--text-color);
107101

108102
&:hover {
109-
border: 1px solid #85A2FE !important;
103+
border: 2px solid #85A2FE !important;
104+
box-sizing: border-box;
110105
}
111106

112107
.Main {
@@ -197,7 +192,8 @@
197192
background-color: var(--node-background);
198193

199194
&:hover {
200-
border: 1px solid #85A2FE !important;
195+
border: 2px solid #85A2FE !important;
196+
box-sizing: border-box;
201197
}
202198

203199
.Main {

0 commit comments

Comments
 (0)