code: function(graph, opt) {
  
          opt = opt || {};
  
          var glGraphType = joint.util.pick(opt, 'directed', 'compound', 'multigraph');
          var glGraph = new graphlib.Graph(glGraphType);
          var setNodeLabel = opt.setNodeLabel || joint.util.noop;
          var setEdgeLabel = opt.setEdgeLabel || joint.util.noop;
          var setEdgeName = opt.setEdgeName || joint.util.noop;
          var collection = graph.get('cells');
  
          for (var i = 0, n = collection.length; i < n; i++) {
  
              var cell = collection.at(i);
              if (cell.isLink()) {
  
                  var source = cell.get('source');
                  var target = cell.get('target');
  
                  // Links that end at a point are ignored.
                  if (!source.id || !target.id) break;
  
                  // Note that if we are creating a multigraph we can name the edges. If
                  // we try to name edges on a non-multigraph an exception is thrown.
                  glGraph.setEdge(source.id, target.id, setEdgeLabel(cell), setEdgeName(cell));
  
              } else {
  
                  glGraph.setNode(cell.id, setNodeLabel(cell));
  
                  // For the compound graphs we have to take embeds into account.
                  if (glGraph.isCompound() && cell.has('parent')) {
                      var parentId = cell.get('parent');
                      if (collection.has(parentId)) {
                          // Make sure the parent cell is included in the graph (this can
                          // happen when the layout is run on part of the graph only).
                          glGraph.setParent(cell.id, parentId);
                      }
                  }
              }
          }
  
          return glGraph;
      }
docs: Create new graphlib graph from existing JointJS graph.