GithubHelp home page GithubHelp logo

doc22940 / diagram Goto Github PK

View Code? Open in Web Editor NEW

This project forked from graphql-editor/diagram

0.0 0.0 0.0 2.08 MB

โ˜Š Tool for making node graphs. Inspired by dependency graph. Used mainly for automation services ๐Ÿ“ˆ

License: MIT License

JavaScript 1.18% TypeScript 98.10% HTML 0.72%

diagram's Introduction

Graphsource

npm Commitizen friendly npm downloads

Diagram is the tool for making node based systems. Define your own behaviour of this react based diagram system and create your tool. Visual programming is trending right now so this is a good basis.

Providing highest level of abstracion and theming graphsource is the most powerful package around the ecosystem. This package contains one dependency.

Getting started

Javascript

import { Diagram } from 'graphsource'
this.diagram = new Diagram(document.getElementById("root"));
const createOND = (name) => ({
  name: `${name}Node`,
  description: `${name} object node`,
  inputs: [],
  outputs: []
});
const options = [
  {
    name: "required",
    help:
      "Check this if this node is required for creation of the type or is required in input | interface"
  },
  {
    name: "array",
    help:
      "Check this if you want a list here for example 'Hello' is a String however ['Hello', 'Me', 'World', 'Sloth'] its an array of strings"
  }
];
this.diagram!.setDefinitions([
  {
    type: "dummy",
    help: "Hello I am dummy node this is help I do display",
    node: createOND("dummy"),
    options,
    root: true,
    acceptsInputs: (d, defs) =>
      defs.map(
        def =>
          ({
            definition: def
          })
      ),
    acceptsOutputs: (d, defs) =>
      defs.map(
        def =>
          ({
            definition: def
          })
      )
  }
]);

TypeScript

import { Diagram, NodeDefinition, AcceptedNodeDefinition } from 'graphsource'
this.diagram = new Diagram(document.getElementById("root"));
const createOND = (name: string): NodeDefinition["node"] => ({
  name: `${name}Node`,
  description: `${name} object node`,
  inputs: [],
  outputs: []
});
const options: NodeOption[] = [
  {
    name: "required",
    help:
      "Check this if this node is required for creation of the type or is required in input | interface"
  },
  {
    name: "array",
    help:
      "Check this if you want a list here for example 'Hello' is a String however ['Hello', 'Me', 'World', 'Sloth'] its an array of strings"
  }
];
this.diagram!.setDefinitions([
  {
    type: "dummy",
    help: "Hello I am dummy node this is help I do display",
    node: createOND("dummy"),
    options,
    root: true,
    acceptsInputs: (d, defs) =>
      defs.map(
        def =>
          ({
            definition: def
          } as AcceptedNodeDefinition)
      ),
    acceptsOutputs: (d, defs) =>
      defs.map(
        def =>
          ({
            definition: def
          } as AcceptedNodeDefinition)
      )
  }
]);

Light mode

Diagram is in dark mode by defult, but You can easily change the theme to light one. Just add the options while creating Diagram.

import { Diagram, DefaultDiagramThemeLight } from 'graphsource'
this.diagram = new Diagram(document.getElementById("root"),
{
  theme: DefaultDiagramThemeLight
});

Develop & Contribute

$ git clone https://github.com/graphql-editor/diagram
$ npm install
$ npm run start

Creating new nodes

Press RMB to open menu pointing on diagram

Add to your project

$ npm install graphsource

Listening to diagram events

It's possible to attach to certain events that occur inside the diagram. You can do it by using familiar .on() syntax, e.g.:

this.diagram = new Diagram(/* ... */);
/* ... */
this.diagram.on(EVENT_NAME, () => {
  // callback
});

Here is the list of all subscribable events:

  • DataModelChanged - fires when a data model (nodes, links placement and content) was changed
  • ViewModelChanged - fires when a view model (pan, zoom) was changed
  • NodeMoving - fires when node is being moved
  • NodeMoved - fires when node stops being moved
  • NodeSelected - fires when node(s) was selected
  • NodeCreated - fires when node was created
  • NodeDeleted - fires when node was deleted
  • NodeChanged - fires when node was modified
  • LinkCreated - fires when a link was created
  • LinkDeleted - fires when a link was deleted
  • LinkMoved - fires when a link stops being moved
  • UndoRequested - fires when undo was requested
  • RedoRequested - fires when redo was requested

You can unsubscribe your listener either by using .off(), or by invoking unsubscriber function that is being returned from .on():

this.diagram = new Diagram(/* ... */);
const callback = (nodeList) => {
  console.log('Nodes are moving!', nodeList);
};
this.diagram.on('NodeMoving', callback); // callback will be fired
// ...
this.diagram.off('NodeMoving', callback); // callback will not be fired anymore
this.diagram = new Diagram(/* ... */);
const callback = () => {
  console.log('node moving!');
};
const unsubscriber = this.diagram.on('NodeMoving', callback); // callback will be fired
// ...
unsubscriber(); // callback will not be fired anymore

Serialisation of data

const diagram = new Diagram(/* ... */);
const callback = ({nodes, links}) => {
  // Here you receive nodes and links after Serialisation
};
this.diagram.on('DataModelChanged', callback); // callback will be fired

Docs

To generate docs simply type:

npm run docs

Controls

  • Create - press and hold right mouse button and choose node -> Left Mouse Button click
  • Pan - press and hold Left Mouse Button and move mouse
  • Move - press and hold Left Mouse Button on node
  • RIGHT MOUSE CLICK on node - node actions
  • CLICK ON NODE INPUT - open new nodes menu
  • CLICK ON NODE TYPE - if node is a children of other node it centers view on parent node
  • Rename - To rename node simply start typing when one node is selected
  • Rename description - To rename node description clik right mouse button on node and click renameDescription
  • SHIFT + Left Mouse Button Click - select multiple nodes
  • Delete - Click delete button when node/nodes are selected or right click -> delete

Contribute

Feel free to contact us and contribute in graphql editor project. [email protected]

  1. fork this repo
  2. Create your feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Used by

Here is Live Demo of diagram used to create node based graphql system

diagram's People

Contributors

aexol avatar agallardol avatar annalysiuk avatar dlukanin avatar hubertzubsh avatar hzub avatar mike-dax avatar palid avatar tknickman avatar

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.