GithubHelp home page GithubHelp logo

mateusmp / compute-nodes Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 1.0 3.92 MB

Compute any logic or data transformation using visual nodes!

HTML 1.97% JavaScript 1.02% TypeScript 88.47% CSS 8.34% Shell 0.20%
visual-nodes node-graph compute-graph nodes react

compute-nodes's Introduction

compute-nodes

Create any logic or data transformation using visual nodes!

Alt text

Online Demo!

Install

npm install --save compute-nodes

Usage

See examples/ to have a better idea of how to use this framework.

cd examples
npm start

In short, you need to define a resolver that will process the data from the nodes and associate any data between the node connections.

1- Define and register some nodes:

class SomeNode extends CanvasNode {
    data: {
      x,
      y,
      z
    }

    // Define some metadata
    // This can be defined anywhere, you will need to specify this later
    // Specify the input and output format
    static InputFormat = {
      in1: {
        type: "any",
        visualName: "Input 1"
      }
    };
    static OutputFormat = {
      out1: {
        type: "any",
        visualName: "Output 1"
      },
      anynamehere: {
        type: "any",
        visualName: "Output 2"
      }
    };

    // Provide a construct method:
    static Construct = (args) => {
      // Feel free to do any special initialization
      return new SomeNode(args);
    }

    // LocalResolve is just an example using a Local Node Resolver
    // You can implement any kind of resolver, that can use a backend
    // to generate some data, for instance.
    // @See example/src/resolver/LocalNodeResolver.ts
    static LocalResolve = (node, input) => {
      return {
        out1: input.in1 + 10,
        anynamehere: input.in1 * 10;
      }
    }
}

2- Register your types

// Create a NodeRegistry and register your types:
const nodeRegistry = new LocalNodeRegistry();

// Register type allow you to pass in some properties that are merged with the ones
// found in the class definition provided in the first argument
// This may be useful to override part of the behaviour of some node type
// Or in case you don't have the definition of some properties at compile time, for instance
nodeRegistry.registerType(SomeNode, {
    render: (props) => <SomeNodeVisualComponent {...props}/>, /*...others...*/});

3- Setup a node resolver and provide it to a canvas

// Create your node resolver
const resolver = new LocalNodeResolver(nodeRegistry)

// And provide the resolver to a canvas component
function NodeGraphCanvas() {
  return <Canvas resolver={resolver}/>
}

License

MIT © MateusMP

compute-nodes's People

Contributors

dependabot[bot] avatar mateusmp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dseeni

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.