How to use the jointjs.layout function in jointjs

To help you get started, we’ve selected a few jointjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tilk / digitaljs / src / index.js View on Github external
return !link;
                } else if (e === 'source') { 
                    const ps = vs.model.ports[ms.getAttribute('port')];
                    if (typeof ps !== 'object' || ps.dir !== 'out' || ps.bits !== vl.model.get('bits'))
                        return false;
                    return true;
                }
            }
        });
        paper.$el.addClass('djs');
        paper.freeze();
        // required for the paper to visualize the graph (jointjs bug?)
        graph.resetCells(graph.getCells());
        // lazy graph layout
        if (!graph.get('laid_out')) {
            joint.layout.DirectedGraph.layout(graph, {
                nodeSep: 20,
                edgeSep: 0,
                rankSep: 110,
                rankDir: "LR",
                dagre: dagre,
                graphlib: graphlib
            });
            graph.set('laid_out', true);
        }
        paper.unfreeze({
            progress(done, processed, total) {
                if (done) {
                    paper.fitToContent({ padding: 30, allowNewOrigin: 'any' });
                    if (opts.onDone) opts.onDone();
                }
            }
github epam / pipeline-builder / src / visual / Visualizer.js View on Github external
const newCells = createSubstituteCells(this._graph);
    const settings = {
      marginX: 100,
      marginY: 10,
      rankSep: 100,
      nodeSep: 80,
      rankDir: 'LR',
      setLinkVertices: false,
      resizeClusters: true,
      setPosition: (element, glNode) => {
        element.proto.set('position', {
          x: glNode.x - glNode.width / 2,
          y: glNode.y - glNode.height / 2 });
      }, // setVertices is ignored
    };
    joint.layout.DirectedGraph.layout(newCells, settings);
  }
github Novvum / graphql-birdseye / src / jointjs / index.ts View on Github external
async renderElements(typeMap = this.typeMap, activeType = this.activeType) {
    const toRenderTypes: FilteredGraphqlOutputType[] = this.getToRenderTypes(
      typeMap,
      activeType
    );
    this.startLoading();
    await this.removeUnusedElements(toRenderTypes);
    await this.addNewElements(toRenderTypes);
    joint.layout.DirectedGraph.layout(this.graph, {
      nodeSep: 200,
      rankSep: 400,
      rankDir: "LR",
      setPosition: (element: any, glNode: any) => {
        element.set(
          "position",
          {
            x: glNode.x - glNode.width / 2,
            y: glNode.y - glNode.height / 2
          },
          { cacheOnly: false /* will not update links yet */ }
        );
      },
      setVertices: (link: any, points: any) => {
        link.unset("vertices", { silent: true });
        // this.adjustVertices(link);
github tilk / digitaljs / src / cells / fsm.js View on Github external
displayEditor(evt) {
        evt.stopPropagation();
        const div = $('<div>', {
            title: "FSM: " + this.model.get('label')
        }).appendTo('html &gt; body');
        const pdiv = $('<div>').appendTo(div);
        const graph = this.model.fsmgraph;
        const paper = new joint.dia.Paper({
            el: pdiv,
            model: graph
        });
        // to visualize the cells
        graph.resetCells(graph.getCells());
        // lazy layout
        if (!graph.get('laid_out')) {
            joint.layout.DirectedGraph.layout(graph, {
                dagre: dagre,
                graphlib: graphlib
            });
            graph.set('laid_out', true);
        }
        // auto-resizing
        this.listenTo(graph, 'change:position', (elem) =&gt; {
            paper.fitToContent({ padding: 30, allowNewOrigin: 'any' });
        });
        paper.fitToContent({ padding: 30, allowNewOrigin: 'any' });
        const maxWidth = $(window).width() * 0.9;
        const maxHeight = $(window).height() * 0.9;
        div.dialog({
            width: Math.min(maxWidth, pdiv.outerWidth() + 60), 
            height: Math.min(maxHeight, pdiv.outerHeight() + 60),
            close: () =&gt; {</div></div>
github CapsicoHealth / Tilda / docs / chrome-extension / js / test2.js View on Github external
var lab = makeLink(ea, eb);
    var lbc = makeLink(eb, ec);
    var lbd = makeLink(eb, ed);
    var lbe = makeLink(eb, ee);
    var lbf = makeLink(eb, ef);
    var lbg = makeLink(eb, eg);
    var lhg = makeLink(eh, eg);

    group.embed(topGroup).embed(bottomGroup);
    topGroup.embed(eb).embed(eh);
    bottomGroup.embed(ec).embed(ed).embed(ee).embed(ef);

    graph.addCell([group, topGroup, bottomGroup, ea, eb, ec, ed, ed, ee, ef, eg, eh, lab, lbc, lbd, lbe, lbf, lbg, lhg]);

    joint.layout.DirectedGraph.layout(graph, {
        setLinkVertices: false,
        rankDir: 'TB',
        marginX: 50,
        marginY: 50,
        clusterPadding: { top: 30, left: 10, right: 10, bottom: 10 }
    });    
  }
  return init;