flowhub / the-graph

SVG custom elements for FBP graph editing and visualization. Used in noflo/noflo-ui
https://flowhub.github.io/the-graph/demo-full.html
MIT License
1.01k stars 179 forks source link

how to use the-graph-editor #144

Closed yosiat closed 10 years ago

yosiat commented 10 years ago

Hi,

I am trying on my local machine, and I am getting the next errors in the console - screen shot 2014-05-06 at 7 48 14 pm

No noflo directory at all under bower_components and no require. What should I do in order to fix it?

forresto commented 10 years ago

Sorry about that.

I need to make a component.json to pull that in. You can save this built noflo.js http://the-grid.github.io/the-graph/bower_components/noflo/browser/noflo.js to that location if you want a quick hack.

yosiat commented 10 years ago

Thanks @forresto it works!

Does the "the-graph" have any documentation? I want to use it in my project.

forresto commented 10 years ago

If you want compatibility with a full FBP IDE, you can wire in with FlowHub by making your runtime talk the FBP protocol: http://noflojs.org/documentation/protocol/ . FlowHub (noflo-ui) provides lots of stuff around the-graph, like a component library, journal for undo/redo, browser storage, and github connection.

To use just the-graph, you'll have to hook into the noflo graph events.

yosiat commented 10 years ago

I want to use the "the-graph", How can I learn for example how to add a node with input and output port?

forresto commented 10 years ago

OK, I made a basic demo that shows making a custom component library and adding nodes:

http://the-grid.github.io/the-graph/the-graph-editor/demo-simple.html

The relevant code:

    // The graph editor
    var editor = document.getElementById('editor');

    // Component library
    var library = {
      basic: {
        name: 'basic',
        description: 'basic demo component',
        icon: 'eye',
        inports: [
          {'name': 'in', 'type': 'all'}
        ],
        outports: [
          {'name': 'out', 'type': 'all'}
        ]
      }
    };
    editor.$.graph.library = library;

    // Load empty graph
    var graph = {};
    editor.graph = graph;

    // Add node button
    var addnode = function () {
      var id = Math.round(Math.random()*100000).toString(36);
      var component = 'basic';
      var metadata = {
        label: 'label',
        x: Math.round(Math.random()*800),
        y: Math.round(Math.random()*600)
      };
      var newNode = editor.nofloGraph.addNode(id, component, metadata);
      console.log(newNode);
    };
    document.getElementById("addnode").addEventListener("click", addnode);
yosiat commented 10 years ago

hi @forresto , thank you for the simple demo!