MCPcopy Index your code
hub / github.com/deepnote/deepnote / renderTreeNode

Function renderTreeNode

packages/cli/src/commands/dag.ts:294–352  ·  view source on GitHub ↗

* Render a node and its subtree in tree format. * @param varsDisplay - Optional variable flow annotation (e.g., " via x, y"). When provided, uses arrow connector.

(
  nodeId: string,
  prefix: string,
  isLast: boolean,
  childrenMap: Map<string, { id: string; variables: string[] }[]>,
  nodeMap: Map<string, DagNode>,
  blockMap: BlockMap,
  rendered: Set<string>,
  c: ReturnType<typeof getChalk>,
  varsDisplay = ''
)

Source from the content-addressed store, hash-verified

292 * @param varsDisplay - Optional variable flow annotation (e.g., " via x, y"). When provided, uses arrow connector.
293 */
294function renderTreeNode(
295 nodeId: string,
296 prefix: string,
297 isLast: boolean,
298 childrenMap: Map<string, { id: string; variables: string[] }[]>,
299 nodeMap: Map<string, DagNode>,
300 blockMap: BlockMap,
301 rendered: Set<string>,
302 c: ReturnType<typeof getChalk>,
303 varsDisplay = ''
304): void {
305 const info = blockMap.get(nodeId)
306 const node = nodeMap.get(nodeId)
307 const label = info?.label ?? nodeId
308
309 // Tree connectors: use arrow (─►) for child nodes with variable flow, plain (──) for roots
310 const isChildNode = varsDisplay !== ''
311 const connector = isLast ? (isChildNode ? '└─► ' : '└── ') : isChildNode ? '├─► ' : '├── '
312 const childPrefix = isLast ? ' ' : '│ '
313
314 // Check if this node was already rendered (DAG handling)
315 const alreadyRendered = rendered.has(nodeId)
316 rendered.add(nodeId)
317
318 // Render the node line
319 const typeIndicator = c.dim(`[${info?.type ?? 'unknown'}]`)
320 if (alreadyRendered) {
321 output(`${prefix}${connector}${c.cyan(label)} ${typeIndicator}${varsDisplay} ${c.yellow('*')}`)
322 return
323 }
324
325 output(`${prefix}${connector}${c.cyan(label)} ${typeIndicator}${varsDisplay}`)
326
327 // Show defined variables if any
328 const outputVars = node?.outputVariables ?? []
329 if (outputVars.length > 0) {
330 output(`${prefix}${childPrefix}${c.dim('defines:')} ${c.green(outputVars.join(', '))}`)
331 }
332
333 // Get and render children
334 const children = buildSortedChildren(nodeId, childrenMap, nodeMap)
335 for (let i = 0; i < children.length; i++) {
336 const child = children[i]
337 const isLastChild = i === children.length - 1
338 const childVarsDisplay = child.variables.length > 0 ? c.dim(` via ${child.variables.join(', ')}`) : ''
339
340 renderTreeNode(
341 child.id,
342 prefix + childPrefix,
343 isLastChild,
344 childrenMap,
345 nodeMap,
346 blockMap,
347 rendered,
348 c,
349 childVarsDisplay
350 )
351 }

Callers 1

outputDagShowFunction · 0.85

Calls 2

outputFunction · 0.90
buildSortedChildrenFunction · 0.85

Tested by

no test coverage detected