Comments (13)
OK, I clearly haven't found the time yet, but it's still on my todo to build out some samples with things like this.
from treant-js.
Did you figure out how to do this ?
from treant-js.
Did you figure out how to do this ?
from treant-js.
I'll see if I can find some time this weekend to share an example that shows how to add child nodes; however it's generally not done by manipulating the array directly.
from treant-js.
Thanks @dlgoodchild , I am using this amazing library now, can you please give me some tip how to do that? by recreating the chart everytime the data is changed? but the size / position of the chart could be changed
from treant-js.
Hi guys this is how I got it to work. Thanks dlgoodchild for for keeping this code up to date.
var chart = new Treant(simple_chart_config, null, $); // initialises the tree when the page loads
var
$('body').on('click', '.Treant .node', function() {
var
$oNodes.removeClass( 'selected' );
$oNode.addClass( 'selected' );
let node = $oNode.data( 'treenode' );
});
//gets an array with data that you want to dynamically load to the tree
$.ajax({
url :'',
method : 'POST', // form submit method get/post
data : {},
ContentType : 'application/json',
dataType: 'json',
success: function(data){
$.each(data, function (i, node) {
var hid = node.id // you must have a unique id in each element of the json array
var node_info = $(node.parent).data('treenode'); // assigns data to each node foreach element in the json array
var detail = { // create the actual node with the element information
'text': {'name': data.name}, //each name in the json array you received
HTMLid: hid, // assigns an id used to for connecting the nodes
};
chart.tree.addNode(node_info, detail); // loads the data into and adds to the tree dynamically
}
});
},
});
})
from treant-js.
@chaddwick25 I'm trying to wrap my head around your solution, to no avail. Can you upload a working example to JSFiddle or something? Also, is there a way to add and remove nodes on the tree and have the tree change? (Without having to do any XMLHttpRequest requests)
from treant-js.
@n8jadams I dont know how to do it without using XMLHttpRequest requests. Sorry
from treant-js.
@n8jadams Which part are you having difficulty understanding?
from treant-js.
@chaddwick25 Can you show an example of a json file (with the array that's dynamically loaded) that is read in by the AJAX request?
from treant-js.
{
"data":{
"chart":{
"container": "#viz-jig-chart",
"connectors":{
"type": "step"
},
"node":{
"collapsable":true,
"HTMLclass":"nodeDefault"
}
},
"nodeStructure":{
"text": {
"name": "Main Viz-Jig Progress"
},
"HTMLid": "root",
"children": [
{
"text": {
"name": "First child"
},
"HTMLid": "1"
},
{
"text": {
"name": "Second child"
},
"HTMLid": "2"
}
]
}
}
}
from treant-js.
the same data you would use to create an initial node, you'd use to add to the tree. the key things from my last post are:
init the tree and store it.
var chart = new Treant(simple_chart_config, null, $);
call the tree and using the property add the node.
chart.tree.addNode(node_info, detail);
define all existing and new nodes in the tree
var
weather you choose to do an ajax call or not, you need to call this: chart.tree.addNode(node_info, detail);
from treant-js.
The solution I went with was an internal model of the tree that I convert to a treant-format structure and then destroy and rebuild the tree with that treant structure representation of MY tree.
As treant manipulates the model it is sent, this was a mess until I created a 'COPY' of the data by serialising and deserialising the objects to/from JSON. That way you add/edit/move/remove nodes in your internal structure, then build a treant-alike structure and send THAT to treant.
I have code, but it is currently proprietary (and badly written undoubtedly).
from treant-js.
Related Issues (20)
- the chart is loaded one time and the next chart is not loaded properly. HOT 1
- Contact me inside collapsible node not working HOT 1
- how to add text on the connect edge? HOT 1
- keep collapsible state on refresh HOT 1
- Connector over connector problem HOT 1
- Is a chart created using treant.js able to be made responsive? HOT 1
- Show text on arrow HOT 1
- over 100 nodes HOT 2
- react-native app HOT 1
- Doesn't work on NPM HOT 2
- subTeeSeparation HOT 1
- How to add a "marriage" node and connector? HOT 2
- Browser error when load 20000 nodes. HOT 3
- Align children
- Bug: text.data-foo doesn't work for JSON format HOT 2
- How to add node to top of clicked node HOT 1
- Compiling LaTeX in Treant nodes
- collapsable - Error when there is a lot of json data
- Fork with moving from javascript to typescript [RELEASE IS PUBLISHED] HOT 1
- Repaint when tree is hidden
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from treant-js.