File size: 2,996 Bytes
1e3b872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { app } from "../../../scripts/app.js";
import { addMenuHandler, addNode } from "./common/utils.js";

const nodePxOffsets = 80;

function getXYInputNodes() {
    return [
        "XY Input: Seeds++ Batch",
        "XY Input: Add/Return Noise",
        "XY Input: Steps",
        "XY Input: CFG Scale",
        "XY Input: Sampler/Scheduler",
        "XY Input: Denoise",
        "XY Input: VAE",
        "XY Input: Prompt S/R",
        "XY Input: Aesthetic Score",
        "XY Input: Refiner On/Off",
        "XY Input: Checkpoint",
        "XY Input: Clip Skip",
        "XY Input: LoRA",
        "XY Input: LoRA Plot",
        "XY Input: LoRA Stacks",
        "XY Input: Control Net",
        "XY Input: Control Net Plot",
        "XY Input: Manual XY Entry"
    ];
}

function showAddXYInputMenu(type, e, menu, node) {
    const specialNodes = [
        "XY Input: LoRA Plot",
        "XY Input: Control Net Plot",
        "XY Input: Manual XY Entry"
    ];
    
    const values = getXYInputNodes().map(nodeType => {
        return {
            content: nodeType,
            callback: function() {
                const newNode = addNode(nodeType, node);

                // Calculate the left shift based on the width of the new node
                const shiftX = -(newNode.size[0] + 35);
                newNode.pos[0] += shiftX;

                if (specialNodes.includes(nodeType)) {
                    newNode.pos[1] += 20;
                    // Connect both outputs to the XY Plot's 2nd and 3rd input.
                    newNode.connect(0, node, 1);
                    newNode.connect(1, node, 2);
                } else if (type === 'X') {
                    newNode.pos[1] += 20;
                    newNode.connect(0, node, 1);  // Connect to 2nd input
                } else {
                    newNode.pos[1] += node.size[1] + 45;
                    newNode.connect(0, node, 2);  // Connect to 3rd input
                }
            }
        };
    });

    new LiteGraph.ContextMenu(values, {
        event: e,
        callback: null,
        parentMenu: menu,
        node: node
    });
    return false;
}

app.registerExtension({
    name: "efficiency.addXYinputs",
    async beforeRegisterNodeDef(nodeType, nodeData, app) {
        if (nodeData.name === "XY Plot") {
            addMenuHandler(nodeType, function(insertOption) {
                insertOption({
                    content: "โœ๏ธ Add ๐š‡ input...",
                    has_submenu: true,
                    callback: (value, options, e, menu, node) => showAddXYInputMenu('X', e, menu, node)
                });
                insertOption({
                    content: "โœ๏ธ Add ๐šˆ input...",
                    has_submenu: true,
                    callback: (value, options, e, menu, node) => showAddXYInputMenu('Y', e, menu, node)
                });
            });
        }
    },
});