# compute-nodes

> Compute any logic or data transformation using visual nodes!

Latest version **0.3.0** (published 2020-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install compute-nodes
pnpm add compute-nodes
yarn add compute-nodes
bun add compute-nodes
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2020-09-19 |
| First published | 2020-05-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 478.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | MateusMP |
| Maintainers | mateusmp |

## Links

- npm: https://www.npmjs.com/package/compute-nodes
- Repository: https://github.com/MateusMP/compute-nodes
- Homepage: https://github.com/MateusMP/compute-nodes#readme
- Issues: https://github.com/MateusMP/compute-nodes/issues
- npm.io page: https://npm.io/package/compute-nodes

## Recent versions

- 0.3.0 (latest) — 2020-09-19
- 0.2.2 — 2020-06-06
- 0.2.1 — 2020-06-05
- 0.2.0 — 2020-06-01
- 0.1.0 — 2020-05-18

## README

# compute-nodes

> Create any logic or data transformation using visual nodes!


![Alt text](.github/images/node-example.png?raw=true "Compute Nodes")

[Online Demo!](https://mateusmp.github.io/compute-nodes/)

## Install

```bash
npm install --save compute-nodes
```

## Usage

See examples/ to have a better idea of how to use this framework.
```bash
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:
```ts
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
```tsx
// 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
```tsx
// 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](https://github.com/MateusMP)

---
_Source: https://npm.io/package/compute-nodes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
