diff --git a/js/apps/system/aardvark/frontend/js/graphViewer/graph/gharialAdapter.js b/js/apps/system/aardvark/frontend/js/graphViewer/graph/gharialAdapter.js index a87808d692..035e96589e 100644 --- a/js/apps/system/aardvark/frontend/js/graphViewer/graph/gharialAdapter.js +++ b/js/apps/system/aardvark/frontend/js/graphViewer/graph/gharialAdapter.js @@ -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; diff --git a/js/apps/system/aardvark/frontend/js/graphViewer/graphViewer.js b/js/apps/system/aardvark/frontend/js/graphViewer/graphViewer.js index 5a4794f017..02934440cd 100644 --- a/js/apps/system/aardvark/frontend/js/graphViewer/graphViewer.js +++ b/js/apps/system/aardvark/frontend/js/graphViewer/graphViewer.js @@ -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) { diff --git a/js/apps/system/aardvark/frontend/js/graphViewer/ui/graphViewerUI.js b/js/apps/system/aardvark/frontend/js/graphViewer/ui/graphViewerUI.js index 34460a1ff0..8a12445340 100644 --- a/js/apps/system/aardvark/frontend/js/graphViewer/ui/graphViewerUI.js +++ b/js/apps/system/aardvark/frontend/js/graphViewer/ui/graphViewerUI.js @@ -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) { diff --git a/js/apps/system/aardvark/frontend/js/views/graphManagementView.js b/js/apps/system/aardvark/frontend/js/views/graphManagementView.js index 5d277a5640..ba6128127c 100644 --- a/js/apps/system/aardvark/frontend/js/views/graphManagementView.js +++ b/js/apps/system/aardvark/frontend/js/views/graphManagementView.js @@ -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) {