Я пытаюсь построить график из файла xml, но загружаю только узлы, основанные на определенных критериях... я могу получить все вершины для добавления с помощью циклов for, которые включают функции декодирования и добавления,
проблема с краями.. я могу заставить их иметь источники, но цели всегда заканчиваются нулевыми
среди многих вещей, которые я пробовал, окончательная версия добавляет узлы xml в массив, и только после того, как все вершины добавлены в граф, я декодирую ребра... но это все равно не работает...
function get_selected(main_class, filename){
"use strict";
var node, i, j, req, root, decj, deci, enc, dec, data, parent, graph, main_class_node, child_nodes, edges, destinations;
deci = new mxCodec();
decj = new mxCodec();
graph = new mxGraph();
parent = graph.getDefaultParent();
req = mxUtils.load(filename);
root = req.getDocumentElement();
child_nodes = [];
edges = [];
destinations = [];
mxLog.show();
for (i=0; i < root.childNodes[0].childNodes.length; i ++) {
// Get the main cell and add it to the graph
if (root.childNodes[0].childNodes[i].id == main_class) {
node = deci.decode(root.childNodes[0].childNodes[i]);
main_class_node = graph.getModel().add(parent, node);
}
//get all the children of the main cell and add them to the graph
else if (root.childNodes[0].childNodes[i].outerHTML.indexOf('parent="' + main_class + '"') != -1 ) {
node = decj.decode(root.childNodes[0].childNodes[i]);
graph.getModel().add(main_class_node, node);
child_nodes.push(node.id);
}
}
for (j=0; j < child_nodes.length; j ++) {
for (i=0; i < root.childNodes[0].childNodes.length; i ++) {
//get all the edges originating in any of the "chidren" and add them to the graph
if (root.childNodes[0].childNodes[i].outerHTML.indexOf('source="' + child_nodes[j] + '"') != -1 ) {
node = root.childNodes[0].childNodes[i];
//graph.getModel().add(parent, node);
edges.push(node);
}
}
}
for (j=0; j < edges.length; j ++) {
for (i=0; i < root.childNodes[0].childNodes.length; i ++) {
//get the target of each of the edges and and add them to the graph
if (root.childNodes[0].childNodes[i].id == "attr-" + edges[j].id.split('-')[1]) {
node = deci.decode(root.childNodes[0].childNodes[i]);
graph.getModel().add(parent, node);
}
}
}
dec = new mxCodec();
for (j=0; j < edges.length; j ++) {
node = dec.decode(edges[j]);
graph.getModel().add(parent, node);
}
enc = new mxCodec();
data = enc.encode(graph.getModel());
return mxUtils.getXml(data);
}