Hi people
I’ try to draw a Finite-State machine (http://en.wikipedia.org/wiki/Finite-state_machine). But I need to draw the elements dynamically. For this I used the following code (Im using jQuery Too):
var diagram = new go.Diagram("canvas"); var $$ = go.GraphObject.make; diagram.initialContentAlignment = go.Spot.Center; diagram.undoManager.isEnabled = false; diagram.isReadOnly = true diagram.allowSelect = false; diagram.initialAutoScale = go.Diagram.Uniform; var state = [{text: 'q0', initial: true, final: false}, {text: 'q1', initial: false, final: true}]; $.each(state , function (i, v) { var node = new go.Node(go.Panel.Auto); var shape = new go.Shape(); shape.figure = "Circle"; if (v.final) shape.figure = "Ring"; if (v.initial) { shape.fill = "lightblue"; } else { shape.fill = "White"; } node.key = v.text; node.add(shape); var textblock = new go.TextBlock(); textblock.text = v.text; textblock.margin = 15; node.add(textblock); diagram.add(node); }); with this the result is:What can I do??Well, that is ok. Now, I need to draw the transitions between q0 and q1. I try to draw using GraphLinksModel, but i cant. I've also tried using this: var initialNode = diagram.findNodeForKey(v.Initial); var finalNode = diagram.findNodeForKey(v.Final); var link = new go.Link(); link.fromNode = initialNode; link.toNode = finalNode; diagram.add(link);
Thanks
<span id=“result_” =“short_text”="" lang=“en”><span =“hps”="">The result <span =“hps”="">should be <span =“hps”="">something like: