1
0
Fork 0

The graphviewer will now start with a random vertex

This commit is contained in:
Michael Hackstein 2014-06-26 10:54:07 +02:00
parent 4d1357c465
commit 97309a837b
4 changed files with 33 additions and 4 deletions

View File

@ -188,6 +188,14 @@ function GharialAdapter(nodes, edges, viewer, config) {
return;
}
result = result[0];
if (result.length === 0) {
if (callback) {
callback({
errorCode: 404
});
}
return;
}
var inserted = {},
n = absAdapter.insertNode(result[0].vertex),
oldLength = nodes.length;

View File

@ -208,6 +208,20 @@ function GraphViewer(svg, width, height, adapterConfig, config) {
}
});
};
this.loadGraphWithRandomStart = function(callback) {
adapter.loadRandomNode(function (node) {
if (node.errorCode) {
callback(node);
return;
}
node._expanded = true;
self.start();
if (_.isFunction(callback)) {
callback();
}
});
};
this.loadGraphWithAttributeValue = function(attribute, value, callback) {
adapter.loadInitialNodeByAttributeValue(attribute, value, function (node) {

View File

@ -2,7 +2,7 @@
/*global document, $, _ */
/*global EventDispatcherControls, NodeShaperControls, EdgeShaperControls */
/*global LayouterControls, GharialAdapterControls*/
/*global GraphViewer, d3, window*/
/*global GraphViewer, d3, window, alert*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
///
@ -448,7 +448,15 @@ function GraphViewerUI(container, adapterConfig, optWidth, optHeight, viewerConf
createColourList();
if (startNode) {
graphViewer.loadGraph(startNode);
if (typeof startNode === "string") {
graphViewer.loadGraph(startNode);
} else {
graphViewer.loadGraphWithRandomStart(function(node) {
if (node && node.errorCode) {
alert("Sorry your graph seems to be empty");
}
});
}
}
this.changeWidth = function(w) {

View File

@ -25,12 +25,11 @@
var adapterConfig = {
type: "gharial",
graphName: name,
graph: name,
baseUrl: require("internal").arango.databasePrefix("/")
};
var width = $("#content").width() - 75;
$("#content").html("");
this.ui = new GraphViewerUI($("#content")[0], adapterConfig, width, 680, {});
this.ui = new GraphViewerUI($("#content")[0], adapterConfig, width, 680, {}, true);
},
addNewGraph: function(e) {