currently I am trying to set up a Petrinet generator as jupyter widget. Therefore I am using the cookiecutter-ts-widget template, which means i am implementing the frontend logics in typescript. I am happy with the progress and everything works fine except the tokens of my places are not rendered.
Here is how I am creating an Example on the 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
}
By console-logging you can see that the tokens are in the respective cells (e.g. tokens: 1) but are not rendered even though the whole graph is rendered perfectly fine.
Further i noticed that the pn.Place
cells only contain the following flags:
{PORTS: 16, RENDER: 64, RESIZE: 8, ROTATE: 32, TOOLS: 4, TRANSLATE: 2, UPDATE: 1}
According to my understanding there should be a TOKENS
flag as well, which is checked on and finally tokens are added in the background in form of dynamic HTML.
A correct example of a Cell containing tokens:
<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>
versus my cell (containing non rendered tokens):
<circle class="root" id="v-7" r="25" fill="#ffffff" stroke="red" transform="translate(25, 25)" stroke-width="3"></circle>
<g class="tokens"></g>
Does anyone have any ideas on how to get the initializer of a new Place (i.e. new pn.Place()
) to add a TOKENS
-flag internally?
Or alternatively do you know how i could add this flag myself?
Any help is appreciated!
Actually after posting this question on their GitHub i received an answer which turned out to be the solution. You need to specify the cellNamespace for the graph and the cellViewNamespace for the paper object.
See here: https://github.com/clientIO/joint/issues/1579
const namespace = joint.shapes; // e.g. { standard: { Rectangle: RectangleElementClass }}
const graph = new joint.dia.Graph({ /* attributes of the graph */ }, { cellNamespace: namespace });
const paper = new joint.dia.Paper({ cellViewNamespace: namespace });
As kumilingus pointed out, this should be fixed with release of jointjs v4 by making the namespace mandatory.