1
0
Fork 0

GraphViewer: Fixed Bug in load Graph by Attribute. Now this works and can be used in demo

This commit is contained in:
Michael Hackstein 2013-03-26 13:56:00 +01:00
parent e2068ece03
commit 7e8607ffed
3 changed files with 58 additions and 14 deletions

View File

@ -156,6 +156,10 @@
viewer.loadGraph($("#startNode").attr("value"));
}
function loadGraphFromAttribute() {
viewer.loadGraphWithAttributeValue($("#attribute").attr("value"), $("#value").attr("value"));
}
function createViewer() {
var nshape,
nlabel,
@ -368,6 +372,32 @@
</div>
</fieldset>
</form>
<br />
<form action="javascript:void(0);" autocomplete="on" class="form-vertical" id="creationDialog2">
<fieldset>
<div class="control-group">
<div class="controls">
<input type="text" id="attribute" placeholder="Attribute" />
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="text" id="value" placeholder="Value" />
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary" onclick="loadGraphFromAttribute()">Load</button>
</div>
</div>
<div class="control-group">
<div class="controls">
<button id="createNode" type="submit" class="btn btn-primary">Create Node</button>
</div>
</div>
</fieldset>
</form>
</body>
</html>

View File

@ -165,6 +165,7 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
insertEdge(edge);
});
});
console.log(result);
if (callback) {
callback(result[0].vertex);
}
@ -261,20 +262,21 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
};
self.loadNodeFromTreeByAttributeValue = function(attribute, value, callback) {
var loadNodeQuery =
"FOR n IN " + nodeCollection
+ "FILTER n." + attribute + " == \"" + value + "\""
+ "LET links = ("
+ " FOR l IN " + edgeCollection
+ " FILTER n._id == l._from"
+ " FOR t IN " + nodeCollection
+ " FILTER t._id == l._to"
+ " RETURN t._id"
+ ")"
+ "RETURN MERGE(n, {\"children\" : links})";
sendQuery(loadNodeQuery, function(res) {
parseResultOfQuery(res, callback);
var traversal = "FOR n in "
+ nodeCollection
+ " FILTER n." + attribute
+ " == " + JSON.stringify(value)
+ " RETURN TRAVERSAL("
+ nodeCollection + ", "
+ edgeCollection + ", "
+ "n._id, "
+ "\"outbound\", {"
+ "strategy: \"depthfirst\","
+ "maxDepth: 1,"
+ "paths: true"
+ "})";
sendQuery(traversal, function(res) {
parseResultOfTraversal(res, callback);
});
};

View File

@ -258,6 +258,18 @@ function GraphViewer(svg, width, height,
});
};
self.loadGraphWithAttributeValue = function(attribute, value) {
nodes.length = 0;
edges.length = 0;
adapter.loadNodeFromTreeByAttributeValue(attribute, value, function (node) {
node._expanded = true;
node.x = width / 2;
node.y = height / 2;
node.fixed = true;
start();
});
};
self.rebind = function(eventConfig) {
bindEventsFromConfig(eventConfig);
};