Skip to content

Commit 3a2b2f9

Browse files
huchenleigithub-actions
andauthored
Add toggle link visibility button on canvas menu (#1070)
* Basic link visibility toggle * Icon change * nit * Update litegraph * nit * Add playwright test * Update test expectations [skip ci] --------- Co-authored-by: github-actions <github-actions@github.com>
1 parent a19f713 commit 3a2b2f9

11 files changed

+104
-15
lines changed

browser_tests/graphCanvasMenu.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from '@playwright/test'
2+
import { comfyPageFixture as test } from './ComfyPage'
3+
4+
test.describe('Graph Canvas Menu', () => {
5+
test.beforeEach(async ({ comfyPage }) => {
6+
// Set link render mode to spline to make sure it's not affected by other tests'
7+
// side effects.
8+
await comfyPage.setSetting('Comfy.LinkRenderMode', 2)
9+
})
10+
11+
test('Can toggle link visibility', async ({ comfyPage }) => {
12+
// Note: `Comfy.Graph.CanvasMenu` is disabled in comfyPage setup.
13+
// so no cleanup is needed.
14+
await comfyPage.setSetting('Comfy.Graph.CanvasMenu', true)
15+
16+
const button = comfyPage.page.getByTestId('toggle-link-visibility-button')
17+
await button.click()
18+
await comfyPage.nextFrame()
19+
await expect(comfyPage.canvas).toHaveScreenshot(
20+
'canvas-with-hidden-links.png'
21+
)
22+
const hiddenLinkRenderMode = await comfyPage.page.evaluate(() => {
23+
return window['LiteGraph'].HIDDEN_LINK
24+
})
25+
expect(await comfyPage.getSetting('Comfy.LinkRenderMode')).toBe(
26+
hiddenLinkRenderMode
27+
)
28+
29+
await button.click()
30+
await comfyPage.nextFrame()
31+
await expect(comfyPage.canvas).toHaveScreenshot(
32+
'canvas-with-visible-links.png'
33+
)
34+
expect(await comfyPage.getSetting('Comfy.LinkRenderMode')).not.toBe(
35+
hiddenLinkRenderMode
36+
)
37+
})
38+
})
Loading
Loading

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@atlaskit/pragmatic-drag-and-drop": "^1.2.1",
66-
"@comfyorg/litegraph": "^0.7.83",
66+
"@comfyorg/litegraph": "^0.7.84",
6767
"@primevue/themes": "^4.0.5",
6868
"@vitejs/plugin-vue": "^5.0.5",
6969
"@vueuse/core": "^11.0.0",

src/components/graph/GraphCanvasMenu.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
<i-simple-line-icons:cursor v-else />
3939
</template>
4040
</Button>
41+
<Button
42+
severity="secondary"
43+
:icon="linkHidden ? 'pi pi-eye-slash' : 'pi pi-eye'"
44+
v-tooltip.left="t('graphCanvasMenu.toggleLinkVisibility')"
45+
@click="
46+
() =>
47+
commandStore.getCommandFunction('Comfy.Canvas.ToggleLinkVisibility')()
48+
"
49+
data-testid="toggle-link-visibility-button"
50+
/>
4151
</ButtonGroup>
4252
</template>
4353

@@ -46,11 +56,19 @@ import ButtonGroup from 'primevue/buttongroup'
4656
import Button from 'primevue/button'
4757
import { useCommandStore } from '@/stores/commandStore'
4858
import { useCanvasStore } from '@/stores/graphStore'
59+
import { useSettingStore } from '@/stores/settingStore'
4960
import { useI18n } from 'vue-i18n'
61+
import { LiteGraph } from '@comfyorg/litegraph'
62+
import { computed } from 'vue'
5063
5164
const { t } = useI18n()
5265
const commandStore = useCommandStore()
5366
const canvasStore = useCanvasStore()
67+
const settingStore = useSettingStore()
68+
69+
const linkHidden = computed(
70+
() => settingStore.get('Comfy.LinkRenderMode') === LiteGraph.HIDDEN_LINK
71+
)
5472
5573
let interval: number | null = null
5674
const repeat = (command: string) => {

src/extensions/core/linkRenderMode.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const ext = {
1010
name: 'Link Render Mode',
1111
defaultValue: 2,
1212
type: 'combo',
13-
// @ts-expect-error
14-
options: [...LiteGraph.LINK_RENDER_MODES, 'Hidden'].map((m, i) => ({
15-
value: i,
16-
text: m,
17-
selected: i == app.canvas.links_render_mode
18-
})),
19-
onChange(value) {
13+
options: [
14+
{ value: LiteGraph.STRAIGHT_LINK, text: 'Straight' },
15+
{ value: LiteGraph.LINEAR_LINK, text: 'Linear' },
16+
{ value: LiteGraph.SPLINE_LINK, text: 'Spline' },
17+
{ value: LiteGraph.HIDDEN_LINK, text: 'Hidden' }
18+
],
19+
onChange(value: number) {
2020
app.canvas.links_render_mode = +value
21-
app.graph.setDirtyCanvas(true)
21+
app.canvas.setDirty(/* fg */ false, /* bg */ true)
2222
}
2323
})
2424
}

src/i18n.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ const messages = {
100100
zoomOut: 'Zoom Out',
101101
resetView: 'Reset View',
102102
selectMode: 'Select Mode',
103-
panMode: 'Pan Mode'
103+
panMode: 'Pan Mode',
104+
toggleLinkVisibility: 'Toggle Link Visibility'
104105
}
105106
},
106107
zh: {
@@ -194,6 +195,14 @@ const messages = {
194195
upscale: '2 Pass Upscale',
195196
flux_schnell: 'Flux Schnell'
196197
}
198+
},
199+
graphCanvasMenu: {
200+
zoomIn: '放大',
201+
zoomOut: '缩小',
202+
resetView: '重置视图',
203+
selectMode: '选择模式',
204+
panMode: '平移模式',
205+
toggleLinkVisibility: '切换链接可见性'
197206
}
198207
}
199208
// TODO: Add more languages

src/stores/commandStore.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useSettingStore } from '@/stores/settingStore'
77
import { useToastStore } from '@/stores/toastStore'
88
import { showTemplateWorkflowsDialog } from '@/services/dialogService'
99
import { useQueueStore } from './queueStore'
10+
import { LiteGraph } from '@comfyorg/litegraph'
1011

1112
export interface ComfyCommand {
1213
id: string
@@ -15,7 +16,7 @@ export interface ComfyCommand {
1516
label?: string | (() => string)
1617
icon?: string | (() => string)
1718
tooltip?: string | (() => string)
18-
shortcut?: string
19+
versionAdded?: string
1920
}
2021

2122
const getTracker = () =>
@@ -206,6 +207,29 @@ export const useCommandStore = defineStore('command', () => {
206207
function: () => {
207208
app.canvas['read_only'] = !app.canvas['read_only']
208209
}
210+
},
211+
{
212+
id: 'Comfy.Canvas.ToggleLinkVisibility',
213+
icon: 'pi pi-eye',
214+
label: 'Toggle Link Visibility',
215+
versionAdded: '1.3.6',
216+
217+
function: (() => {
218+
let lastLinksRenderMode = LiteGraph.SPLINE_LINK
219+
220+
return () => {
221+
const currentMode = settingStore.get('Comfy.LinkRenderMode')
222+
223+
if (currentMode === LiteGraph.HIDDEN_LINK) {
224+
// If links are hidden, restore the last positive value or default to spline mode
225+
settingStore.set('Comfy.LinkRenderMode', lastLinksRenderMode)
226+
} else {
227+
// If links are visible, store the current mode and hide links
228+
lastLinksRenderMode = currentMode
229+
settingStore.set('Comfy.LinkRenderMode', LiteGraph.HIDDEN_LINK)
230+
}
231+
}
232+
})()
209233
}
210234
]
211235

0 commit comments

Comments
 (0)