1
0
Fork 0

GraphViewer: Implemented Random Vertex on collection switch (#611)

This commit is contained in:
Michael Hackstein 2013-10-28 11:32:25 +01:00
parent a322c71083
commit 416d24a1c7
2 changed files with 24 additions and 1 deletions

View File

@ -337,6 +337,18 @@ function ArangoAdapter(nodes, edges, config) {
self.loadNode = function(nodeId, callback) { self.loadNode = function(nodeId, callback) {
self.loadNodeFromTreeById(nodeId, callback); self.loadNodeFromTreeById(nodeId, callback);
}; };
self.loadRandomNode = function(callback) {
var self = this;
getNRandom(1, function(list) {
var r = list[0];
if (r._id) {
self.loadInitialNode(r._id, callback);
return;
}
return;
});
};
self.loadInitialNode = function(nodeId, callback) { self.loadInitialNode = function(nodeId, callback) {
absAdapter.cleanUp(); absAdapter.cleanUp();

View File

@ -83,10 +83,15 @@ function ArangoAdapterControls(list, adapter) {
selected: adapter.getGraphName() selected: adapter.getGraphName()
} }
] ]
},{
type: "checkbox",
text: "Start with random vertex",
id: "random",
selected: true
},{ },{
type: "checkbox", type: "checkbox",
id: "undirected", id: "undirected",
selected: (adapter.getDirection() === "any"), selected: (adapter.getDirection() === "any")
}], function () { }], function () {
var nodes = $("#" + idprefix + "node_collection") var nodes = $("#" + idprefix + "node_collection")
.children("option") .children("option")
@ -101,12 +106,17 @@ function ArangoAdapterControls(list, adapter) {
.filter(":selected") .filter(":selected")
.text(), .text(),
undirected = !!$("#" + idprefix + "undirected").attr("checked"), undirected = !!$("#" + idprefix + "undirected").attr("checked"),
random = !!$("#" + idprefix + "random").attr("checked"),
selected = $("input[type='radio'][name='loadtype']:checked").attr("id"); selected = $("input[type='radio'][name='loadtype']:checked").attr("id");
if (selected === idprefix + "collections") { if (selected === idprefix + "collections") {
adapter.changeToCollections(nodes, edges, undirected); adapter.changeToCollections(nodes, edges, undirected);
} else { } else {
adapter.changeToGraph(graph, undirected); adapter.changeToGraph(graph, undirected);
} }
if (random) {
adapter.loadRandomNode(callback);
return;
}
if (_.isFunction(callback)) { if (_.isFunction(callback)) {
callback(); callback();
} }
@ -163,6 +173,7 @@ function ArangoAdapterControls(list, adapter) {
edges = $("#" + idprefix + "edgecollection").attr("value"), edges = $("#" + idprefix + "edgecollection").attr("value"),
undirected = !!$("#" + idprefix + "undirected").attr("checked"); undirected = !!$("#" + idprefix + "undirected").attr("checked");
adapter.changeTo(nodes, edges, undirected); adapter.changeTo(nodes, edges, undirected);
} }
); );
}); });