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

            Line data    Source code
       1              : <template>
       2           87 :   <div class="isolate">
       3              :     <div v-if="hasActivePopup" class="fixed inset-0" @click="hideModal"></div>
       4              : 
       5              :     <div class="pointer-events-none absolute inset-x-0 bottom-0 flex">
       6              :       <div
       7              :         role="toolbar"
       8              :         :aria-label="t('graphCanvasMenu.canvasToolbar')"
       9              :         class="pointer-events-auto ml-auto flex max-w-full min-w-0 gap-1 overflow-x-auto floating-panel"
      10              :         @wheel="canvasInteractions.handleWheel"
      11              :       >
      12              :         <CanvasModeSelector
      13              :           :button-styles="stringifiedMinimapStyles.buttonStyles"
      14              :         />
      15              : 
      16              :         <div class="h-[27px] w-px self-center bg-border" />
      17              : 
      18              :         <Button
      19              :           :tooltip="fitViewLabel"
      20              :           variant="textonly"
      21              :           :aria-label="fitViewLabel"
      22              :           :style="stringifiedMinimapStyles.buttonStyles"
      23              :           class="size-8 p-0"
      24              :           @click="() => commandStore.execute('Comfy.Canvas.FitView')"
      25              :         >
      26              :           <i class="icon-[lucide--focus]" aria-hidden="true" />
      27              :         </Button>
      28              : 
      29              :         <Button
      30              :           :tooltip="t('zoomControls.label')"
      31              :           variant="textonly"
      32              :           :class="cn('w-15 p-0', isModalVisible && 'not-active:bg-muted')"
      33              :           :aria-label="t('zoomControls.label')"
      34              :           data-testid="zoom-controls-button"
      35              :           :style="stringifiedMinimapStyles.buttonStyles"
      36              :           @click="toggleModal"
      37              :         >
      38              :           <span class="inline-flex items-center gap-1 px-2 text-xs">
      39              :             <span>{{ canvasStore.appScalePercentage }}%</span>
      40              :             <i class="icon-[lucide--chevron-down]" aria-hidden="true" />
      41              :           </span>
      42              :         </Button>
      43              : 
      44              :         <div class="h-[27px] w-px self-center bg-border" />
      45              : 
      46              :         <Button
      47              :           :tooltip="minimapLabel"
      48              :           variant="textonly"
      49              :           :aria-label="minimapLabel"
      50              :           data-testid="toggle-minimap-button"
      51              :           :style="stringifiedMinimapStyles.buttonStyles"
      52              :           :class="
      53              :             cn(
      54              :               'size-8 p-0',
      55              :               settingStore.get('Comfy.Minimap.Visible') && 'not-active:bg-muted'
      56              :             )
      57              :           "
      58              :           @click="onMinimapToggleClick"
      59              :         >
      60              :           <i class="icon-[lucide--map]" aria-hidden="true" />
      61              :         </Button>
      62              : 
      63              :         <Button
      64              :           :tooltip="linkVisibilityLabel"
      65              :           variant="textonly"
      66              :           :class="cn('size-8 p-0', linkHidden && 'not-active:bg-muted')"
      67              :           :aria-label="linkVisibilityLabel"
      68              :           data-testid="toggle-link-visibility-button"
      69              :           :style="stringifiedMinimapStyles.buttonStyles"
      70              :           @click="onLinkVisibilityToggleClick"
      71              :         >
      72              :           <i class="icon-[lucide--route-off]" aria-hidden="true" />
      73              :         </Button>
      74              :       </div>
      75              :     </div>
      76              :     <ZoomControlsModal :visible="isModalVisible" @close="hideModal" />
      77              :   </div>
      78              : </template>
      79              : 
      80              : <script setup lang="ts">
      81              : import { computed, onBeforeUnmount, onMounted } from 'vue'
      82              : import { useI18n } from 'vue-i18n'
      83              : 
      84              : import Button from '@comfyorg/design-system/button/Button'
      85              : import { useZoomControls } from '@/composables/useZoomControls'
      86              : import { LiteGraph } from '@/lib/litegraph/src/litegraph'
      87              : import { useSettingStore } from '@/platform/settings/settingStore'
      88              : import { useTelemetry } from '@comfyorg/telemetry'
      89              : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
      90              : import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions'
      91              : import { useMinimap } from '@/renderer/extensions/minimap/composables/useMinimap'
      92              : import { useCommandStore } from '@/platform/keybindings/commandStore'
      93              : import { cn } from '@comfyorg/tailwind-utils'
      94              : 
      95              : import CanvasModeSelector from './CanvasModeSelector.vue'
      96              : import ZoomControlsModal from './modals/ZoomControlsModal.vue'
      97              : 
      98           68 : const { t } = useI18n()
      99           68 : const commandStore = useCommandStore()
     100           68 : const { formatKeySequence } = useCommandStore()
     101           68 : const canvasStore = useCanvasStore()
     102           68 : const settingStore = useSettingStore()
     103           68 : const canvasInteractions = useCanvasInteractions()
     104           68 : const minimap = useMinimap()
     105              : 
     106           68 : const { isModalVisible, toggleModal, hideModal, hasActivePopup } =
     107              :   useZoomControls()
     108              : 
     109           68 : const stringifiedMinimapStyles = computed(() => {
     110           68 :   const buttonKeys = ['borderRadius']
     111           68 :   const additionalButtonStyles = {
     112              :     border: 'none'
     113              :   }
     114              : 
     115           68 :   const containerStyles = minimap.containerStyles.value
     116              : 
     117              :   const buttonStyles = {
     118              :     ...Object.fromEntries(
     119              :       Object.entries(containerStyles).filter(([key]) =>
     120              :         buttonKeys.includes(key)
     121              :       )
     122              :     ),
     123              :     ...additionalButtonStyles
     124              :   }
     125           68 :   return { buttonStyles }
     126              : })
     127              : 
     128              : // Computed properties for reactive states
     129           68 : const linkHidden = computed(
     130              :   () => settingStore.get('Comfy.LinkRenderMode') === LiteGraph.HIDDEN_LINK
     131              : )
     132              : 
     133              : // Computed properties for command text
     134           68 : const fitViewCommandText = computed(() =>
     135              :   formatKeySequence(
     136              :     commandStore.getCommand('Comfy.Canvas.FitView')
     137              :   ).toUpperCase()
     138              : )
     139           68 : const minimapCommandText = computed(() =>
     140              :   formatKeySequence(
     141              :     commandStore.getCommand('Comfy.Canvas.ToggleMinimap')
     142              :   ).toUpperCase()
     143              : )
     144              : 
     145              : // Computed properties for tooltip and aria-label texts
     146           68 : const fitViewLabel = computed(() => {
     147           68 :   const label = t('graphCanvasMenu.fitView')
     148           68 :   const shortcut = fitViewCommandText.value
     149           68 :   return shortcut ? `${label} (${shortcut})` : label
     150              : })
     151           68 : const minimapLabel = computed(() => {
     152           77 :   const label = settingStore.get('Comfy.Minimap.Visible')
     153              :     ? t('zoomControls.hideMinimap')
     154              :     : t('zoomControls.showMinimap')
     155           77 :   const shortcut = minimapCommandText.value
     156           77 :   return shortcut ? `${label} (${shortcut})` : label
     157              : })
     158           68 : const linkVisibilityLabel = computed(() =>
     159              :   linkHidden.value
     160              :     ? t('graphCanvasMenu.showLinks')
     161              :     : t('graphCanvasMenu.hideLinks')
     162              : )
     163           68 : onMounted(() => {
     164           68 :   canvasStore.initScaleSync()
     165              : })
     166              : 
     167              : /**
     168              :  * Track minimap toggle button click and execute the command.
     169              :  */
     170           68 : const onMinimapToggleClick = () => {
     171            5 :   useTelemetry()?.trackUiButtonClicked({
     172              :     button_id: 'graph_menu_minimap_toggle_clicked',
     173              :     element_group: 'graph_menu'
     174              :   })
     175            5 :   void commandStore.execute('Comfy.Canvas.ToggleMinimap')
     176              : }
     177              : 
     178              : /**
     179              :  * Track hide/show links button click and execute the command.
     180              :  */
     181           68 : const onLinkVisibilityToggleClick = () => {
     182            2 :   useTelemetry()?.trackUiButtonClicked({
     183              :     button_id: 'graph_menu_hide_links_toggle_clicked',
     184              :     element_group: 'graph_menu'
     185              :   })
     186            2 :   void commandStore.execute('Comfy.Canvas.ToggleLinkVisibility')
     187              : }
     188              : 
     189           68 : onBeforeUnmount(() => {
     190            1 :   canvasStore.cleanupScaleSync()
     191              : })
     192              : </script>
        

Generated by: LCOV version 2.0-1