Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Tutorial not clear (Read 6107 times)
mandz
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Mar 12th, 2013
Tutorial not clear
May 8th, 2013 at 3:31am
Print Post  
After following your advice as in this post: http://mindfusion.eu/Forum/YaBB.pl?num=1366070876/2#2, I tried your first tutorial (http://www.mindfusion.eu/onlinehelp/jsdiagram/index.htm), but it does not make sense.  At what stage is the Javascript code called?

This is my code:
Code (HTML)
Select All
@{
    ViewBag.Title = "Index";
}

<script src="MicrosoftAjax.js" type="text/javascript"></script>
<script src="MindFusion.Diagramming.js" type="text/javascript"></script>
<script src="Tutorial1.js" type="text/javascript"></script>

<h2>Index</h2>

<!-- The Diagram component is bound to the canvas element below -->
<div style="width:900px; height:500px; overflow:auto; border: 1px solid;">

<canvas id="diagram" width="2100" height="2100">
    This page requires a browser that supports HTML 5 Canvas element.
</canvas>

</div> 



and the JS:
Code (Javascript)
Select All
var Diagram = MindFusion.Diagramming.Diagram;
var DiagramLink = MindFusion.Diagramming.DiagramLink;
var ShapeNode = MindFusion.Diagramming.ShapeNode;

var Rect = MindFusion.Drawing.Rect;
var LayeredLayout = MindFusion.Graphs.LayeredLayout;

var diagram;

Sys.Application.add_load(function (sender, args) {
    // create a Diagram component that wraps the "diagram" canvas
    diagram = $create(Diagram, null, null, null, $get("diagram"));
});

var request = new Sys.Net.WebRequest();
request.set_url("TextFile1.txt");
request.set_httpVerb("GET");
request.add_completed(onResponse);
request.invoke();

function onResponse(executor, eventArgs) {
    if (executor.get_responseAvailable) {
        var json = executor.get_responseData();
        var graph = Sys.Serialization.JavaScriptSerializer.deserialize(json);
        buildDiagram(graph);
    }
}

function buildDiagram(graph) {
    var nodeMap = [];
    var bounds = new Rect(0, 0, 18, 8);

    // load node data
    var nodes = graph.nodes;
    Array.forEach(nodes, function (node) {
        var diagramNode = diagram.getFactory().createShapeNode(bounds);
        nodeMap[node.id] = diagramNode;
        diagramNode.setText(node.name);
        diagramNode.setBrush("LightCyan");
    });

    // load link data
    var links = graph.links;
    Array.forEach(links, function (link) {
        diagram.getFactory().createDiagramLink(
            nodeMap[link.origin],
            nodeMap[link.target]);
    });
}

// arrange the graph
var layout = new LayeredLayout();
layout.nodeDistance = 10;
layout.layerDistance = 10;
diagram.arrange(layout); 



As you can see, I'm not a JS developer, but a C# and your tutorial is really very vague.  Any chance that you could add the source code for your examples to the tutorial pages?  Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Tutorial not clear
Reply #1 - May 8th, 2013 at 8:35am
Print Post  
You can find the full source code in the "samples\tutorial1.js" file in the folder where you unzipped the JsDiagram archive. From what I can see, the difference from your code is that ours runs the request from within the load handler (this corresponds to a Page_Load or Window_Load handler in C# code):

Code
Select All
Sys.Application.add_load(function (sender, args)
{
	// create a Diagram component that wraps the "diagram" canvas
	diagram = $create(Diagram, null, null, null, $get("diagram"));
	diagram.setLinkHeadShapeSize(2);

	// pretent we are calling a web service
	var request = new Sys.Net.WebRequest();
	request.set_url("Tutorial1.txt");
	request.set_httpVerb("GET");
	request.add_completed(onResponse);
	request.invoke();
	...
}); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
mandz
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Mar 12th, 2013
Re: Tutorial not clear
Reply #2 - May 9th, 2013 at 12:30am
Print Post  
I have 5 tutorials in my samples.zip file, but they are the MVC ones.  I wasn't aware that I need to install the Javascript components to see an example of how to build the diagram on the client side with the MVC controls.  I'll download and install that too.  Thanks
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint