> function init(){
> d3.json("/tgac/miso/d3graph/project", function(json) {
> mainjson = json;
> json.x0 = 800;
> json.y0 = 0;
> updatetree(root = json);
>
>
> changetree();
> });
>
> }
> init();
Lars
You can't really make it wait, you can only simulate that by setting a timer to
call a function. Unless you wait actively by checking e.g. a variable in a loop.
I wouldn't recommend that though as it puts heavy load on the CPU.
> My future plan is to show like "Graph Loading" in flash or GIF style
> I can not use in this way.
You certainly could. I've done this here for example:
http://www.larsko.org/v/mpte/
Lars
function init() {
showLoadingScreen();
d3.json("path/to/file.json", function(data) {
hideLoadingScreen();
displayTheData();
});
}
These are asynchronous callbacks; you wait for them to complete
(synchronize) by putting your code inside the callback.
Mike
The timeout you set only applies to the computer that the javascript is executed
on. You would have to do something like
function waitFor(m, f) {
if(m > 0) {
// check again in 1 second
setTimeout(function() { waitFor(m, f); }, 1000);
} else {
f();
}
}
var mutex = 1; // asynchronous function call sets mutex to 0 at some point
waitFor(mutex, otherFunction());
In any case you would have to wrap the call to otherFunction() so that it gets
called at the appropriate time.
Lars