ユーザー定義要素として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