Hey Nico
it's doesn't work the rGraph Change on the fly on my Sample Code...
I have 3 different Methods teste for change the rgraph...
my Goal is:
onload show me rgraph -> json;
then i would change the rgraph, not add Nodes or trees, a completle
new rgraph in the same show.
my Sample:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HTML:
include Jit.js
include script.js
<body onload="init();">
<script>
var json = {
"id": "0",
"name": "1",
"children": []
}
var json1 = {
"id": "0",
"name": "Severin",
"children": [{
"id": "1",
"name": "Mad",
"children": []},
{
"id": "2",
"name": "Mad",
"children": []},
{
"id": "3",
"name": "Tom",
"children": [{
"id": "4",
"name": "Mad",
"children": []},
{
"id": "5",
"name": "Fred",
"children": []
}]
}]
};
var json2 = {
"id": "0",
"name": "Clarissa",
"children": [{
"id": "2",
"name": "Chiara",
"children": [{
"id": "3",
"name": "Hedi",
"children": []},
{
"id": "4",
"name": "Juliet",
"children": []},
{
"id": "5",
"name": "Anna",
"children": []
}]
}]
};
var json3 = {
"id": "0",
"name": "Elefant",
"children": [{
"id": "2",
"name": "Giraffe",
"children": [{
"id": "3",
"name": "Mouse",
"children": []
}]
}]
};
</script>
<div id="container">
<div id="center-container">
<div id="infovis"></div>
</div>
<div id="right-container">
<h4>Global Options</h4>
<table>
<tr>
<td>
<input type="button" value="Refresh"
onclick="window.location = window.location" />
</td>
</tr>
</table>
<h4>Refresh</h4>
<table>
<tr>
<td>
<input type="button" value="JSON 1 Tree"
onclick="refreshTree1()" />
<input type="button" value="JSON 2 Tree" onclick="refreshTree2()" /
>
<input type="button" value="JSON 3 Tree" onclick="refreshTree3()" /
>
</td>
</tr>
</table>
</div>
<div id="log"></div>
</div>
</body>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Javascript:
var refreshTree1 = function(){
rgraph.op.sum(json1, {
type: 'fade:seq',
duration: 150,
fps: 30,
hideLabels: false,
onComplete: function(){
}
});
};
var refreshTree2 = function(){
var lbs = rgraph.fx.labels;
for (var label in lbs) {
if (lbs[label] && lbs[label].id != rgraph.root) {
lbs[label].parentNode.removeChild(lbs[label]);
}
}
rgraph.loadJSON(json2);
rgraph.refresh();
var subnodes =
Graph.Util.getSubnodes(rgraph.graph.getNode(rgraph.root), 0);
var map = [];
for (var i = 0; i < subnodes.length; i++) {
node = subnodes[i].id;
rgraph.controller.onCreateLabel(rgraph.graph.getNode(node), node);
}
rgraph.refresh();
};
var refreshTree3 = function(){
var lbs = rgraph.fx.labels;
for (var label in lbs) {
if (lbs[label] && lbs[label].id != rgraph.root) {
lbs[label].parentNode.removeChild(lbs[label]);
}
}
rgraph.loadJSON(json3);
rgraph.refresh();
var subnodes =
Graph.Util.getSubnodes(rgraph.graph.getNode(rgraph.root), 0);
var map = [];
for (var i = 0; i < subnodes.length; i++) {
node = subnodes[i].id;
rgraph.controller.onCreateLabel(rgraph.graph.getNode(node), node);
// rgraph.controller.onPlaceLabel(rgraph.graph.getNode(node), node);
}
rgraph.refresh();
};
function init(){
var infovis = document.getElementById('infovis');
var w = infovis.offsetWidth, h = infovis.offsetHeight;
var canvas = new Canvas('mycanvas', {
'injectInto': 'infovis',
'width': w,
'height': h,
'backgroundCanvas': {
'styles': {
'strokeStyle': '#444'
},
'impl': {
'init': function(){},
'plot': function(canvas, ctx){
var times = 6, d = 100;
var pi2 = Math.PI * 2;
for (var i = 1; i <= times; i++) {
ctx.beginPath();
ctx.arc(0, 0, i * d, 0, pi2, true);
ctx.stroke();
ctx.closePath();
}
}
}
}
});
rgraph = new RGraph(canvas, {
Node: {
color: '#ccddee'
},
Edge: {
color: '#772277'
},
onCreateLabel: function(domElement, node){
domElement.innerHTML =
node.name;
},
onPlaceLabel: function(domElement, node){
var style = domElement.style;
style.display = '';
var left = parseInt(style.left);
var w = domElement.offsetWidth;
style.left = (left - w / 2) + 'px';
}
});
rgraph.loadJSON(json);
rgraph.refresh();
}
So many thanks for helping
Severin