目前我正在尝试将 Petrinet 生成器设置为 jupyter 小部件。因此,我使用的是 cookiecutter-ts-widget 模板,这意味着我正在 typescript 中实现前端逻辑。我对进展感到满意,一切正常,除了我的地方的令牌没有被渲染。
这是我在以下位置创建示例的方式joint.dia.Paper
:
PetriView.graph = new joint.dia.Graph();
PetriView.pn = joint.shapes.pn;
PetriView.paper = new joint.dia.Paper({
el: document.createElement("div"),
width: this.width,
height: this.height,
gridSize: PetriView.gridSize,
defaultAnchor: { name: 'perpendicular' },
defaultConnectionPoint: { name: 'boundary' },
model: PetriView.graph,
linkPinning: false, // prevent dangling links
interactive: function() { return true }, // make cells draggable
});
private firstExample() {
this.clearAll();
// Define Places
var pReady = new PetriView.pn.Place({
position: { x: 140, y: 50 },
attrs: {
'.label': {
'text': 'ready',
'fill': '#7c68fc' },
'.root': {
'stroke': '#7c68fc',
'stroke-width': 3,
},
'.alot > text': {
'fill': '#fe854c',
'font-family': 'Courier New',
'font-size': 20,
'font-weight': 'bold',
'ref-x': 0.5,
'ref-y': 0.5,
'y-alignment': -0.5,
'transform': null as any
},
'.tokens > circle': {
'fill': '#7a7e9b'
}
},
'tokens': 1,
});
var pIdle = pReady.clone()
.attr('.label/text', 'idle')
.position(140, 260)
.set('tokens', 2);
*[...]*
// Define Transitions
var tProduce = new PetriView.pn.Transition({
size: { width: 30, height: 40 },
position: { x: 50, y: 160 },
attrs: {
'.label': {
'text': 'produce',
'fill': '#fe854f'
},
'.root': {
'fill': '#9586fd',
'stroke': '#7c68fc'
},
'rect': {
width: 12,
height: 50,
fill: '#000000',
stroke: '#000000',
"stroke-width": 3,
},
}
});
var tSend = tProduce.clone()
.attr('.label/text', 'send')
.position(270, 160);
*[...]*
// add cells to graph and create links
PetriView.graph.addCell([pReady, pIdle, buffer, cAccepted, cReady, tProduce, tSend, tAccept, tConsume]);
PetriView.graph.addCell([
PetriView.link(tProduce, pReady), PetriView.link(pReady, tSend), PetriView.link(tSend, pIdle), PetriView.link(pIdle, tProduce),
PetriView.link(tSend, buffer), PetriView.link(buffer, tAccept), PetriView.link(tAccept, cAccepted),
PetriView.link(cAccepted, tConsume), PetriView.link(tConsume, cReady), PetriView.link(cReady, tAccept)
]);
return PetriView.graph
}
通过控制台记录,您可以看到标记位于相应的单元格中(例如标记:1),但即使整个图形渲染得非常好,也不会渲染。此外,我注意到pn.Place
单元格仅包含以下标志:
{PORTS: 16, RENDER: 64, RESIZE: 8, ROTATE: 32, TOOLS: 4, TRANSLATE: 2, UPDATE: 1}
根据我的理解,也应该有一个TOKENS
标志,它被选中,最后以动态 HTML 的形式在后台添加标记。
包含标记的 Cell 的正确示例:
<circle class="root" id="v-8" r="25" fill="#ffffff" stroke="#7c68fc" transform="translate(25, 25)" stroke-width="3"></circle>
<g class="tokens two">
<circle id="v-10" fill="#7a7e9b" r="5" transform="translate(19, 25)"></circle>
<circle id="v-11" fill="#7a7e9b" r="5" transform="translate(31, 25)"></circle>
</g>
与我的单元格(包含未呈现的标记)相比:
<circle class="root" id="v-7" r="25" fill="#ffffff" stroke="red" transform="translate(25, 25)" stroke-width="3"></circle>
<g class="tokens"></g>
有没有人对如何让新 Place 的初始化程序(即new pn.Place()
)在内部添加TOKENS
-flag 有任何想法?或者你知道我如何自己添加这个标志吗?
任何帮助表示赞赏!