LCOV - code coverage report
Current view: top level - src/components/graph - NodeTooltip.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 31.4 % 51 16
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2            8 :   <div
       3              :     v-show="tooltipText"
       4              :     ref="tooltipRef"
       5              :     class="node-tooltip z-overlay"
       6              :     :style="{ left, top }"
       7              :   >
       8              :     {{ tooltipText }}
       9              :   </div>
      10              : </template>
      11              : 
      12              : <script setup lang="ts">
      13              : import { useEventListener } from '@vueuse/core'
      14              : import { nextTick, ref } from 'vue'
      15              : 
      16              : import { resolveNodeDefSlotText, resolveNodeDefText } from '@/i18n'
      17              : import {
      18              :   LiteGraph,
      19              :   isOverNodeInput,
      20              :   isOverNodeOutput
      21              : } from '@/lib/litegraph/src/litegraph'
      22              : import { useSettingStore } from '@/platform/settings/settingStore'
      23              : import { app as comfyApp } from '@/scripts/app'
      24              : import { isDOMWidget } from '@/scripts/domWidget'
      25              : import { useNodeDefStore } from '@/stores/nodeDefStore'
      26              : 
      27            8 : let idleTimeout: number
      28            8 : const nodeDefStore = useNodeDefStore()
      29            8 : const settingStore = useSettingStore()
      30            8 : const tooltipRef = ref<HTMLDivElement | undefined>()
      31            8 : const tooltipText = ref('')
      32            8 : const left = ref<string>()
      33            8 : const top = ref<string>()
      34              : 
      35           21 : function hideTooltip() {
      36           21 :   if (!tooltipText.value) return
      37            0 :   tooltipText.value = ''
      38              : }
      39              : 
      40            0 : async function showTooltip(tooltip: string | null | undefined) {
      41            0 :   if (!tooltip) return
      42              : 
      43            0 :   left.value = comfyApp.canvas.mouse[0] + 'px'
      44            0 :   top.value = comfyApp.canvas.mouse[1] + 'px'
      45            0 :   tooltipText.value = tooltip
      46              : 
      47            0 :   await nextTick()
      48              : 
      49            0 :   const rect = tooltipRef.value?.getBoundingClientRect()
      50            0 :   if (!rect) return
      51              : 
      52            0 :   if (rect.right > window.innerWidth) {
      53            0 :     left.value = comfyApp.canvas.mouse[0] - rect.width + 'px'
      54              :   }
      55              : 
      56            0 :   if (rect.top < 0) {
      57            0 :     top.value = comfyApp.canvas.mouse[1] + rect.height + 'px'
      58              :   }
      59              : }
      60              : 
      61            0 : function onIdle() {
      62            0 :   const { canvas } = comfyApp
      63            0 :   const node = canvas?.node_over
      64            0 :   if (!node || node.flags?.ghost) return
      65              : 
      66            0 :   const ctor = node.constructor as { title_mode?: 0 | 1 | 2 | 3 }
      67            0 :   const nodeType = node.type ?? ''
      68            0 :   const nodeDef = nodeDefStore.nodeDefsByName[nodeType]
      69              : 
      70            0 :   if (
      71              :     ctor.title_mode !== LiteGraph.NO_TITLE &&
      72              :     canvas.graph_mouse[1] < node.pos[1] // If we are over a node, but not within the node then we are on its title
      73              :   ) {
      74            0 :     return showTooltip(
      75              :       resolveNodeDefText('description', nodeType, nodeDef?.description)
      76              :     )
      77              :   }
      78              : 
      79            0 :   if (node.flags?.collapsed) return
      80              : 
      81            0 :   const inputSlot = isOverNodeInput(
      82              :     node,
      83              :     canvas.graph_mouse[0],
      84              :     canvas.graph_mouse[1],
      85              :     [0, 0]
      86              :   )
      87            0 :   if (inputSlot !== -1) {
      88            0 :     const inputName = node.inputs[inputSlot].name
      89            0 :     return showTooltip(
      90              :       resolveNodeDefSlotText(
      91              :         'tooltip',
      92              :         nodeType,
      93              :         inputName,
      94              :         nodeDef?.inputs[inputName]?.tooltip
      95              :       )
      96              :     )
      97              :   }
      98              : 
      99            0 :   const outputSlot = isOverNodeOutput(
     100              :     node,
     101              :     canvas.graph_mouse[0],
     102              :     canvas.graph_mouse[1],
     103              :     [0, 0]
     104              :   )
     105            0 :   if (outputSlot !== -1) {
     106            0 :     return showTooltip(
     107              :       resolveNodeDefSlotText(
     108              :         'tooltip',
     109              :         nodeType,
     110              :         outputSlot,
     111              :         nodeDef?.outputs[outputSlot]?.tooltip
     112              :       )
     113              :     )
     114              :   }
     115              : 
     116            0 :   const widget = comfyApp.canvas.getWidgetAtCursor()
     117              :   // Dont show for DOM widgets, these use native browser tooltips as we dont get proper mouse events on these
     118            0 :   if (widget && !isDOMWidget(widget)) {
     119            0 :     const translatedTooltip = resolveNodeDefSlotText(
     120              :       'tooltip',
     121              :       nodeType,
     122              :       widget.name,
     123              :       nodeDef?.inputs[widget.name]?.tooltip
     124              :     )
     125              :     // Widget tooltip can be set dynamically, current translation collection does not support this.
     126            0 :     return showTooltip(widget.tooltip ?? translatedTooltip)
     127              :   }
     128              : }
     129              : 
     130            8 : const onMouseMove = (e: MouseEvent) => {
     131           14 :   hideTooltip()
     132           14 :   clearTimeout(idleTimeout)
     133              : 
     134           14 :   if ((e.target as Node).nodeName !== 'CANVAS') return
     135            0 :   idleTimeout = window.setTimeout(
     136              :     onIdle,
     137              :     settingStore.get('LiteGraph.Node.TooltipDelay')
     138              :   )
     139              : }
     140              : 
     141            8 : useEventListener(window, 'mousemove', onMouseMove)
     142            8 : useEventListener(window, 'click', hideTooltip)
     143              : </script>
     144              : 
     145              : <style lang="css" scoped>
     146              : .node-tooltip {
     147              :   pointer-events: none;
     148              :   background: var(--input);
     149              :   border-radius: 5px;
     150              :   box-shadow: 0 0 5px rgb(0 0 0 / 0.4);
     151              :   color: var(--foreground);
     152              :   left: 0;
     153              :   max-width: 30vw;
     154              :   padding: 4px 8px;
     155              :   position: absolute;
     156              :   top: 0;
     157              :   transform: translate(5px, calc(-100% - 5px));
     158              :   white-space: pre-wrap;
     159              : }
     160              : </style>
        

Generated by: LCOV version 2.0-1