JavaScript. , GoJS: http://gojs.net/latest/samples/stateChart.html.
:
// The nodes are all of the states.
var nodeDataArray = [
{
id: 'Locked',
data: { canOpen: false },
transitions: {
'turnstile/coin/inserted': 'Unlocked',
'turnstile/handle/pushed': 'Locked'
}
},
{
id: 'Unlocked',
data: { canOpen: true },
transitions: {
'turnstile/coin/inserted': 'Unlocked',
'turnstile/handle/pushed': 'Locked'
}
}
];
:

, http://gojs.net/temp/stateChartGeneration.html. , , . , . , , . , , , GoJS: http://gojs.net.
, , , . a/b/c.
FSM, . . : http://gojs.net/latest/samples/logicCircuit.html.
, HTML:
function init() {
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagram",
{
initialContentAlignment: go.Spot.Center,
layout: $(go.ForceDirectedLayout),
"toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom,
"clickCreatingTool.archetypeNodeData": { text: "new node" },
"undoManager.isEnabled": true
});
myDiagram.addDiagramListener("Modified", function(e) {
var button = document.getElementById("SaveButton");
if (button) button.disabled = !myDiagram.isModified;
var idx = document.title.indexOf("*");
if (myDiagram.isModified) {
if (idx < 0) document.title += "*";
} else {
if (idx >= 0) document.title = document.title.substr(0, idx);
}
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Shape, "Circle",
{
parameter1: 20,
fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }),
stroke: "black",
portId: "",
fromLinkable: true,
fromLinkableSelfNode: true,
fromLinkableDuplicates: true,
toLinkable: true,
toLinkableSelfNode: true,
toLinkableDuplicates: true,
cursor: "pointer"
}),
$(go.TextBlock,
{
font: "bold 11pt helvetica, bold arial, sans-serif",
editable: true
},
new go.Binding("text", "id").makeTwoWay())
);
myDiagram.nodeTemplate.selectionAdornmentTemplate =
$(go.Adornment, "Spot",
$(go.Panel, "Auto",
$(go.Shape, { fill: null, stroke: "blue", strokeWidth: 2 }),
$(go.Placeholder)
),
$("Button",
{
alignment: go.Spot.TopRight,
click: addNodeAndLink
},
$(go.Shape, "PlusLine", { desiredSize: new go.Size(6, 6) })
)
);
function addNodeAndLink(e, obj) {
var adorn = obj.part;
e.handled = true;
var diagram = adorn.diagram;
diagram.startTransaction("Add State");
var fromNode = adorn.adornedPart;
var fromData = fromNode.data;
var toData = { text: "new" };
var p = fromNode.location.copy();
p.x += 200;
toData.loc = go.Point.stringify(p);
var model = diagram.model;
model.addNodeData(toData);
var linkdata = {
from: model.getKeyForNodeData(fromData),
to: model.getKeyForNodeData(toData),
text: "transition"
};
model.addLinkData(linkdata);
var newnode = diagram.findNodeForData(toData);
diagram.select(newnode);
diagram.commitTransaction("Add State");
diagram.scrollToRect(newnode.actualBounds);
}
myDiagram.linkTemplate =
$(go.Link,
{
curve: go.Link.Bezier, curviness: 40, adjusting: go.Link.Stretch,
reshapable: true, relinkableFrom: true, relinkableTo: true
},
new go.Binding("points").makeTwoWay(),
new go.Binding("curviness", "curviness"),
$(go.Shape,
{ strokeWidth: 1.5 }),
$(go.Shape,
{ toArrow: "standard", stroke: null }),
$(go.Panel, "Auto",
$(go.Shape,
{
fill: $(go.Brush, "Radial",
{ 0: "rgb(240, 240, 240)", 0.3: "rgb(240, 240, 240)", 1: "rgba(240, 240, 240, 0)" }),
stroke: null
}),
$(go.TextBlock, "transition",
{
textAlign: "center",
font: "10pt helvetica, arial, sans-serif",
stroke: "black",
margin: 4,
editable: true
},
new go.Binding("text", "text").makeTwoWay())
)
);
var nodeDataArray = [
{
id: 'Locked',
data: { canOpen: false },
transitions: {
'turnstile/coin/inserted': 'Unlocked',
'turnstile/handle/pushed': 'Locked'
}
},
{
id: 'Unlocked',
data: { canOpen: true },
transitions: {
'turnstile/coin/inserted': 'Unlocked',
'turnstile/handle/pushed': 'Locked'
}
}
];
var linkDataArray = [];
nodeDataArray.forEach(function(d) {
if (d.transitions) {
for (var t in d.transitions) {
linkDataArray.push({
from: d.id,
to: d.transitions[t],
text: t
})
}
}
})
myDiagram.model = $(go.GraphLinksModel,
{
nodeKeyProperty: "id",
nodeDataArray: nodeDataArray,
linkDataArray: linkDataArray
});
}