Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run a graph with my own node in Node JS and in the browser? #480

Open
LeMoussel opened this issue May 30, 2024 · 0 comments
Open

Comments

@LeMoussel
Copy link

I want to run a graph with my own nodes in NodeJS.
How can I set a node that can run in NodeJS and in the browser?

Specific node: special.js

(function (global) {
    var LiteGraph = global.LiteGraph;

    class SpecialConstNumber {
        constructor() {
            this.title = "Const Special";
            this.desc = "Constant special";
            this.color = '#222234'
            this.bgcolor = '#333257'
            this.addOutput("value", "special");
            this.addProperty("value", 1.0);
        }

        onExecute() {
            this.setOutputData(0, this.properties["value"]);
        }

        onDrawBackground(ctx) {
            //show the current value
            this.outputs[0].label = this.properties["value"];
        }

        getTitle() {
            if (this.flags.collapsed) {
                return this.properties.value;
            }
            return this.title;
        };

        setValue(v) {
            this.setProperty("value", v);
        }
    }
    LiteGraph.registerNodeType("special/const_number", SpecialConstNumber);
})(this);

in Browser

<!DOCTYPE html>
<html lang="fr">

<head>
    <meta charset="UTF-8">
    <title>GraphJS UI</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="./style.css" />

    <link rel="stylesheet" type="text/css" href="./lib/litegraph.css" />
    <script type="text/javascript" src="./lib/litegraph.js"></script>

    <script type="text/javascript" src="./scripts/nodes/special.js"></script>

with Node.js
How can I import special.js ?

import { LGraph, LiteGraph } from 'litegraph.js';
// Import `special.js` ??????

let graphData = JSON.parse(readFileSync("new.lgraph", "utf8"));

const graph = new LGraph(graphData);
graph.runStep() // ERROR Dont'know 'SpecialConstNumber' node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant