我想在JointJS中创建a rectangle with 4 ports, one in each side作为用户定义的元素。在JointJS中,如何用端口创建一个用户定义的元素
我需要创建一个用户定义的元素,因为我需要在鼠标启动时显示工具提示。所以我需要一个标记标记。但我有端口问题。这是我的实现:
var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
el: $('#paper'),
width: 400,
height: 200,
gridSize: 20,
model: graph
});
joint.shapes.devs.CircleModel = joint.shapes.devs.Model.extend({
markup: '<g class="rotatable"><g class="scalable"><rect class="body"/></g><text class="label"/><g class="inPorts"/><g class="outPorts"/><title /></g>',
/*
portMarkup: '<g class="port port<%= id %>"><circle class="port-body"/><text class="port-label"/></g>',
*/
defaults: joint.util.deepSupplement({
type: 'devs.CircleModel',
attrs: {
title: {text: 'Static Tooltip'},
'.body': {
r: 50,
cx: 50,
stroke: 'blue',
fill: 'lightblue'
},
'.label': {
text: 'Model',
'ref-y': 0.5,
'y-alignment': 'middle'
},
'.port-body': {
width: 10,
height: 10,
x: -5,
stroke: 'gray',
fill: 'lightgray',
magnet: 'active'
}
}
}, joint.shapes.devs.Model.prototype.defaults)
});
joint.shapes.devs.CircleModelView = joint.shapes.devs.ModelView;
var rect = new joint.shapes.devs.CircleModel({
position: {
x: 150,
y: 50
},
size: {
width: 100,
height: 100
},
ports: {
groups: {
'top': {
// port position definition
position: 'top',
label: {
// label layout definition:
position: {
name: 'manual', args: {
y: 5,
attrs: { '.': { 'text-anchor': 'middle' } }
}
}
}
},
'down': {
position: 'bottom',
label: {
position: {
name: 'bottom', args: { y: -5 }
}
}
},
'right': {
position: 'right',
label: {
position: {
name: 'bottom', args: { y: -5 }
}
}
},
'left': {
position: 'left',
label: {
position: {
name: 'bottom', args: { y: -5 }
}
}
}
}
}
});
rect.addPort({ group: 'top', attrs: { 'text': { text: 'T' } } });
rect.addPort({ group: 'down', attrs: { 'text': { text: 'D' } } });
rect.addPort({ group: 'right', attrs: { 'text': { text: 'R' } } });
rect.addPort({ group: 'left', attrs: { 'text': { text: 'L' } } });
graph.addCell(rect);
所有的代码是在这里:https://jsfiddle.net/fraverta/ustp4tcj/2/
我不明白为什么不显示端口为圆。有人能帮助我吗?
你在创建circleModel的时候搞砸了。 https://jsfiddle.net/ustp4tcj/3/ – Dino