• Stars
    star
    542
  • Rank 79,206 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Graphsource

npm Commitizen friendly npm downloads

Diagram is the tool for displaying node based systems.

This package contains one dependency.

Getting started

Javascript

import { Diagram } from 'graphsource'
class App {
  constructor() {
    const root = document.getElementById("root");
    if (!root) {
      throw new Error("No root html element");
    }
    this.diagram = new Diagram(root, {});
    this.diagram.setNodes([
        {
            "name": "Query",
            "type": "type",
            "id": "1",
            "description": "",
            "inputs": [
                "2"
            ],
            "outputs": [],
            "options": [
                "query"
            ]
        },
        {
            "name": "pizzas",
            "type": "Pizza",
            "id": "2",
            "inputs": [],
            "outputs": [
                "2"
            ],
            "description":"get all pizzas a a a from the database",
            "options": [
                "array",
                "required"
            ]
        },
        {
            "name": "Pizza",
            "type": "type",
            "id": "3",
            "description": "Main type of the schema",
            "inputs": [
                "4",
            ],
            "outputs": [],
            "options": []
        },
        {
            "name": "name",
            "type": "String",
            "id": "4",
            "inputs": [],
            "outputs": [
                "3"
            ],
            "options": [
                "required"
            ]
        }
    ])
  }
}
new App()

TypeScript

import { Diagram, NodeDefinition, AcceptedNodeDefinition } from 'graphsource'
this.diagram = new Diagram(document.getElementById("root"));
this.diagram.setNodes
]);

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

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:

  • 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
  • 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

  • Pan - press and hold Left Mouse Button and move mouse
  • Move - press and hold Left Mouse Button on node
  • CLICK ON NODE TYPE - if node is a children of other node it centers view on parent node
  • SHIFT + Left Mouse Button Click - select multiple nodes

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

More Repositories

1

graphql-editor

๐Ÿ“บ Visual Editor & GraphQL IDE.
TypeScript
5,934
star
2

graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation โšกโšกโšก for browser,nodejs and react native ( apollo compatible )
TypeScript
1,885
star
3

gql

Very simple CLI for many GraphQL schemas in the cloud. Provides autocompletion for GraphQL queries
Go
119
star
4

graphql-editor-cli

๐Ÿ˜ฑ GraphQL Editor Official CLI - Generate and maintain GraphQL Backend and GraphQL Server
TypeScript
76
star
5

graphql-backend-template-dgraph

Dgraph GraphQL Editor template for backend using very fast dgraph golang database server under the hood
46
star
6

ts-api-faker

Micro api faker written in TypeScript which returns faked data from JSON queries
TypeScript
45
star
7

graphql-ssg

GraphQL data based Static Site Generator.
TypeScript
30
star
8

stucco

FaaS like GraphQL runtime
Go
28
star
9

stucco-js

GraphQL server. JavaScript runtime for stucco - GraphQL backend
TypeScript
26
star
10

transform-graphql

โš™๏ธ Transformer function to transform GraphQL Directives. Create model CRUD directive for example
TypeScript
24
star
11

graphql-js-tree

Simpler structure for GraphQL AST
TypeScript
18
star
12

graphql-blog

Official GraphQLBlog repository. Add your blog posts as pull request!
JavaScript
12
star
13

sloth

Slothking.online CLI for file generation and live replace
JavaScript
11
star
14

.graph

World is moving towards graph sourced systems. This is a .graph format for storing data structure without types.
7
star
15

zeit-aurora-integration

Integration of zeit now with AWS Aurora - Easy serverless SQL database
TypeScript
6
star
16

graphql-react-admin

Admin components for GraphQL schemas
TypeScript
5
star
17

graphql-form

GraphQL Form. Driver driven forms in react
TypeScript
3
star
18

landing-page

HTML
3
star
19

hydra-ide

React wrapped monaco editor used in all graphql editor repositories
TypeScript
2
star
20

gei-users

GraphQL Editor integration for stucco. Allows basic username/password authentication flow
TypeScript
2
star
21

node

Nodejs server for slothking
TypeScript
2
star
22

graphql-docs-dryad

TypeScript
2
star
23

vs-code-theme

GraphQL Editor Vscode Dark Theme
2
star
24

graphql-editor-integrations

Backend integrations for GraphQL Editor CLI and Stucco infrastructure
TypeScript
2
star
25

graphql-dryad

GraphQL JAMstack rendering engine
TypeScript
2
star
26

i-graphql

GraphQL Friendly ORM for MongoDB and GraphQL Zeus - right now in alpha stage
TypeScript
2
star
27

graphql-guide

GraphQL Editor
1
star
28

state

State manager for typescript frontend & slothking
TypeScript
1
star
29

jobscontroller

A very simple controller to launch one off jobs in kubernetes cluster
Go
1
star
30

backend-nodets-boilerplate

Boilerplate for use with sloth CLI and node server.
JavaScript
1
star