Skip to content

Commit 8d3cfeb

Browse files
committed
- Add port support which distinguishes when the node has multiple outputs.
- Add arrow for targets
1 parent 28b3692 commit 8d3cfeb

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

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

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,39 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
185185
ancestors.pairs.forEach(p => {
186186
// Highlight ancestor and their ancestor
187187
document.querySelector(`#node-${p[0]}`)?.setAttribute("style", "outline: 1px solid #85A2FE !important;")
188-
189188
// Get edge size of parent ancestor to apply the right edge stroke
190-
const strokeSize = getEdgeSize(parseInt((document.querySelector(`#node-${p[1]}`) as HTMLElement)?.dataset?.size || '')) + 1
191-
document.querySelector(`[data-cell-id='${p[0]}-${p[1]}']`)?.childNodes.forEach(k =>
192-
(k as HTMLElement)
193-
.setAttribute(
194-
"style",
195-
`stroke: #85A2FE; stroke-linecap: butt; stroke-width: ${strokeSize}px`
196-
)
197-
)
189+
const edge = graph.getCellById(`${p[0]}-${p[1]}`)
190+
edge.setAttrs({
191+
line: {
192+
stroke: '#85A2FE',
193+
strokeWidth: (edge.getAttrs() as any)?.line?.strokeWidth,
194+
targetMarker: {
195+
name: 'block',
196+
stroke: '#85A2FE',
197+
fill: '#85A2FE',
198+
},
199+
},
200+
})
201+
})
202+
})
203+
204+
graph.on("node:mouseleave", x => {
205+
const {id} = x.node.getData()
206+
const ancestors = GetAncestors(data, id, {found: false, pairs: []})
207+
ancestors.pairs.forEach(p => {
208+
document.querySelector(`#node-${p[0]}`)?.setAttribute("style", "")
209+
const edge = graph.getCellById(`${p[0]}-${p[1]}`)
210+
edge.setAttrs({
211+
line: {
212+
stroke: isDarkTheme ? '#6B6B6B' : '#8992B3',
213+
strokeWidth: (edge.getAttrs() as any)?.line?.strokeWidth,
214+
targetMarker: {
215+
name: 'block',
216+
fill: isDarkTheme ? '#6B6B6B' : '#8992B3',
217+
stroke: isDarkTheme ? '#6B6B6B' : '#8992B3',
218+
}
219+
},
220+
})
198221
})
199222
})
200223

@@ -237,15 +260,6 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
237260

238261
ele?.addEventListener('mousedown', mouseDownHandler)
239262

240-
graph.on("node:mouseleave", x => {
241-
const {id} = x.node.getData()
242-
const ancestors = GetAncestors(data, id, {found: false, pairs: []})
243-
ancestors.pairs.forEach(p => {
244-
document.querySelector(`#node-${p[0]}`)?.setAttribute("style", "")
245-
document.querySelector(`[data-cell-id='${p[0]}-${p[1]}']`)?.childNodes.forEach(k => (k as HTMLElement).setAttribute("style", ""))
246-
})
247-
})
248-
249263
resize()
250264

251265
const result = Hierarchy.compactBox(data, {
@@ -297,6 +311,20 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
297311
}
298312

299313

314+
const portId = data.id + '-source'
315+
let targetPort = {}
316+
const targetItem: any = []
317+
if (info.parentId) {
318+
targetItem.push({id: `${info.id}-${info.parentId}-target`, group: `${info.parentId}-target`})
319+
targetPort[info.parentId+'-target'] = {
320+
position: { name: 'bottom' },
321+
attrs: {
322+
circle: {
323+
r: 0
324+
}
325+
}
326+
}
327+
}
300328
model.nodes?.push({
301329
id: data.id,
302330
x: (data.x || 0) + document.body.clientWidth / 2,
@@ -309,6 +337,25 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
309337
stroke: 'transparent',
310338
},
311339
},
340+
ports: {
341+
groups: {
342+
[portId]: {
343+
position: { name: 'top' },
344+
attrs: {
345+
circle: {
346+
r: 0
347+
}
348+
}
349+
},
350+
...targetPort,
351+
},
352+
items: [
353+
...data.children.map(c => ({
354+
id: `${data.id}-${c.id}`, group: portId
355+
})),
356+
...targetItem,
357+
],
358+
},
312359
})
313360
}
314361
if (data.children) {
@@ -317,8 +364,14 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
317364

318365
model.edges?.push({
319366
id: `${data.id}-${item.id}`,
320-
source: data.id,
321-
target: item.id,
367+
source: {
368+
cell: data.id,
369+
port: `${data.id}-${item.id}`,
370+
},
371+
target: {
372+
cell: item.id,
373+
port: `${data.id}-${item.id}`
374+
},
322375
router: {
323376
name: 'manhattan',
324377
args: {
@@ -338,7 +391,11 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
338391
line: {
339392
stroke: isDarkTheme ? '#6B6B6B' : '#8992B3',
340393
strokeWidth: getEdgeSize(itemRecords),
341-
targetMarker: null,
394+
targetMarker: {
395+
name: 'block',
396+
fill: isDarkTheme ? '#6B6B6B' : '#8992B3',
397+
stroke: isDarkTheme ? '#6B6B6B' : '#8992B3',
398+
},
342399
},
343400
},
344401
})

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ export function ProfileNode(props: INodeProps) {
8585
}
8686

8787
const infoData = data ? data : type
88-
8988
return (
90-
<div className="ProfileContainer" id={`node-${id}`} data-size={counter || size || recordsProduced}>
89+
<div className="ProfileContainer" id={`node-${id}`}>
9190
<div className="Main">
9291
<div className="InfoData">
9392
<EuiToolTip delay='long' content={infoData}><span>{infoData}</span></EuiToolTip>

0 commit comments

Comments
 (0)