// NOTE!:
// graph.cloneSubgraph() won't work because it won't change source and target port id.
// ui.Clipboard won't work because of cloneSubgraph()
const graph = new joint.dia.Graph({}, {
cellNamespace: joint.shapes
});
const paper = new joint.dia.Paper({
el: document.getElementById('paper'),
width: 600,
height: 600,
gridSize: 20,
model: graph,
async: true,
sorting: joint.dia.Paper.sorting.APPROX,
cellViewNamespace: joint.shapes
});
const Rect = joint.shapes.standard.Rectangle.define('Rect', {
ports: {
items: [{}, {}]
}
}, {
initialize: function(options) {
if (!options || !options.id) {
if (!options) options = {};
const id = options.id = this.generateId();
this.set('id', id, { silent: true });
}
this._initializePorts();
joint.dia.Cell.prototype.initialize.call(this, options);
},
_isValidPortId: function(id) {
return (typeof id === 'string') && id.startsWith(this.id);
// return id !== null && id !== undefined && !joint.util.isObject(id);
},
generatePortId() {
return `${this.id}:${this.generateId()}`;
},
// Note: this change can be added to the JointJS right now
// The existing ID can not be passed to the constructor of the clone
clone: function(opt) {
opt = opt || {};
if (!opt.deep) {
// Shallow cloning.
var clone = new this.constructor(joint.util.omit(this.attributes, ['id', 'embeds', 'parent']));
// var clone = Backbone.Model.prototype.clone.apply(this, arguments);
// We don't want the clone to have the same ID as the original.
// clone.set('id', this.generateId());
// A shallow cloned element does not carry over the original embeds.
// clone.unset('embeds');
// And can not be embedded in any cell
// as the clone is not part of the graph.
//...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.