Skip to content

Commit 5ee5f81

Browse files
committed
Merge branch 'v1.1'
2 parents ce396a9 + 731e954 commit 5ee5f81

File tree

17 files changed

+359
-126
lines changed

17 files changed

+359
-126
lines changed

app/components/graph/graph.ctrl.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
*
55
* @param $scope
66
* @param {$q} $q
7+
* @param {$location} $location
78
* @param {$log} $log
89
* @param Filters
910
* @param {ClassExtractor} ClassExtractor
1011
* @param {RelationExtractor} RelationExtractor
1112
* @param TypeExtractor
1213
* @param DetailExtractor
13-
* @param RequestConfig
1414
* @param Requests
15+
* @param RequestConfig
1516
* @param Prefixes
1617
* @param StopWatch
18+
* @param Data
19+
* @param View
20+
* @param Promises
1721
*/
18-
function graphCtrl($scope, $q, $log, Filters, ClassExtractor, RelationExtractor, TypeExtractor, DetailExtractor,
19-
RequestConfig, Requests, Prefixes, StopWatch) {
22+
function graphCtrl($scope, $q, $location, $log, Filters, ClassExtractor, RelationExtractor, TypeExtractor,
23+
DetailExtractor, Requests, RequestConfig, Prefixes, StopWatch, Data, View, Promises) {
2024
'ngInject';
2125

2226
/* jshint validthis: true */
@@ -36,7 +40,8 @@ function graphCtrl($scope, $q, $log, Filters, ClassExtractor, RelationExtractor,
3640
vm.showEndpointUrl = __SHOW_ENDPOINT__; // eslint-disable-line no-undef
3741
// jshint ignore:end
3842

39-
vm.endpointURL = RequestConfig.getEndpointURL();
43+
vm.requestedEndpoint = $location.search()['endpointURL'];
44+
vm.endpointURL = (vm.requestedEndpoint !== undefined) ? vm.requestedEndpoint : RequestConfig.getEndpointURL();
4045
vm.data = {};
4146
vm.data.nodes = [];
4247

@@ -129,10 +134,51 @@ function graphCtrl($scope, $q, $log, Filters, ClassExtractor, RelationExtractor,
129134
}
130135
};
131136

137+
/**
138+
* Stop the extraction by rejecting all promises.
139+
*/
140+
vm.stopLoading = function () {
141+
Promises.rejectAll();
142+
StopWatch.stop();
143+
};
144+
145+
/**
146+
* First clear all loaded data, then restart Loading
147+
*/
148+
vm.restartLoading = function () {
149+
Data.clearAll();
150+
vm.classes = [];
151+
StopWatch.stop();
152+
153+
$log.warn('[Graph] Restart loading...');
154+
155+
vm.startLoading();
156+
};
157+
132158
/**
133159
* Start loading data requesting classes. For each class request referring types and search class-class relations.
134160
*/
135161
vm.startLoading = function () {
162+
if (vm.endpointURL === undefined || vm.endpointURL === '') {
163+
Data.clearAll();
164+
RequestConfig.setEndpointURL();
165+
Data.initMaps();
166+
View.reset();
167+
168+
// do not try to query an empty url
169+
return;
170+
} else {
171+
if (vm.endpointURL !== RequestConfig.getEndpointURL()) {
172+
Data.clearAll();
173+
RequestConfig.setEndpointURL(vm.endpointURL);
174+
Data.initMaps();
175+
View.reset();
176+
}
177+
178+
// insert endpoint URL if missing
179+
$location.search('endpointURL', vm.endpointURL);
180+
}
181+
136182
StopWatch.start();
137183
ClassExtractor.requestClasses().then(function extractForClasses(newClasses) {
138184

@@ -142,7 +188,7 @@ function graphCtrl($scope, $q, $log, Filters, ClassExtractor, RelationExtractor,
142188
if (newClasses.length === 0) {
143189
$log.debug('[Graph] No new classes!');
144190
} else {
145-
for (var i = 0; i < newClasses.length; i++) {
191+
for (let i = 0; i < newClasses.length; i++) {
146192
vm.classes.push(newClasses[i]);
147193
}
148194
}

app/components/graph/nodelink-graph.drv.js

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import d3 from 'd3';
1414
* @param Filters
1515
* @param {Geometry} Geometry
1616
* @param Utils
17+
* @param Requests
1718
*
1819
* @returns {{restrict: string, scope: {data: string, onClick: string}, link: link}}
1920
*/
20-
function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geometry, Utils) {
21+
function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geometry, Utils, Requests, View) {
2122

2223
'ngInject';
2324

@@ -29,6 +30,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
2930
},
3031
link: function (scope, element, attrs) {
3132
var margin = parseInt(attrs.margin) || 20;
33+
var width = 0;
3234
var height = parseInt(attrs.height) || $window.innerHeight;
3335

3436
var colorRange = [d3.rgb('#3366CC'), d3.rgb('#EE2867')];
@@ -43,14 +45,21 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
4345

4446
var root = svg.append('g');
4547

48+
let notification = svg.append('g')
49+
.attr('id', 'notification');
50+
let notificationText = notification.append('text')
51+
.attr('class', 'notification')
52+
.style('opacity', 0.0);
53+
4654
var lastUpdate = null;
4755

4856
var minUpdateInterval = 1500;
4957

5058
// Browser onresize event
5159
$window.onresize = function () {
5260
height = $window.innerHeight;
53-
svg.attr('height', height-60);
61+
svg.attr('height', Math.max(height - 60, 0));
62+
scope.drawPlaceholder(scope.data, width, height);
5463
scope.$apply();
5564
};
5665

@@ -68,6 +77,9 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
6877
scope.loopSpline = {};
6978
scope.linearLine = {};
7079

80+
scope.translate = View.getTranslate();
81+
scope.scale = View.getScale();
82+
7183
scope.color = d3.scale.linear().domain([1, Prefixes.size()])
7284
.interpolate(d3.interpolateHsl)
7385
.range(colorRange);
@@ -79,7 +91,8 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
7991
'showTypes': Filters.getIncludeLiterals(),
8092
'showLoops': Filters.getIncludeLoops(),
8193
'showDisjointNode': Filters.getIncludeDisjointNode(),
82-
'showSubclassRelations': Filters.getIncludeSubclassRelations()
94+
'showSubclassRelations': Filters.getIncludeSubclassRelations(),
95+
'loading': (Requests.getPendingRequests() > 0)
8396
};
8497

8598
scope.$watch(function () {
@@ -171,6 +184,11 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
171184
scope.render(scope.data);
172185
});
173186

187+
scope.$on('pending-requests-changed', function(event, pending) {
188+
scope.data.loading = (pending > 0);
189+
scope.drawPlaceholder(scope.data, width, height);
190+
});
191+
174192
scope.lineColor = d3.scale.log()
175193
.base(2)
176194
.domain([1, 32])
@@ -284,6 +302,13 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
284302

285303
scope.redraw = function () {
286304
root.attr('transform', 'translate(' + d3.event.translate + ')' + 'scale(' + d3.event.scale + ')');
305+
306+
// save current view
307+
View.setTranslate(d3.event.translate);
308+
View.setScale(d3.event.scale);
309+
310+
scope.scale = d3.event.scale;
311+
scope.translate = d3.event.translate;
287312
};
288313

289314
/**
@@ -623,6 +648,43 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
623648
return node;
624649
};
625650

651+
/**
652+
* Draws or redraws a placeholder on the graph while classes are loaded or no endpoint is selected.
653+
*/
654+
scope.drawPlaceholder = function (data, width, height) {
655+
if (data.nodes.size === 0) {
656+
$log.debug(`[Graph] Redraw placeholder! Loading: ${scope.data.loading}`);
657+
let boxHeight = 35;
658+
let transitionDuration = 750;
659+
660+
if (scope.data.loading) {
661+
let boxWidth = 200;
662+
let centerX = (width - boxWidth) / 2;
663+
let centerY = Math.max(((height - boxHeight) / 2), 50);
664+
665+
notificationText.text('Loading classes...')
666+
.attr('x', centerX + 5)
667+
.attr('y', centerY - 24)
668+
.transition()
669+
.duration(transitionDuration)
670+
.style('opacity', 1.0);
671+
} else {
672+
let boxWidth = 350;
673+
let centerX = (width - boxWidth) / 2;
674+
let centerY = Math.max(((height - boxHeight) / 2), 50);
675+
676+
notificationText.text('Given SPARQL endpoint not accessible.')
677+
.attr('x', centerX + 5)
678+
.attr('y', centerY - 24)
679+
.transition()
680+
.duration(transitionDuration)
681+
.style('opacity', 1.0);
682+
}
683+
} else {
684+
notificationText.attr('display', 'none');
685+
}
686+
};
687+
626688
/**
627689
* Function which creates the graph.
628690
*
@@ -642,10 +704,18 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
642704
return;
643705
}
644706

707+
// restore view
708+
root.attr('transform', 'translate(' + scope.translate + ')' + 'scale(' + scope.scale + ')');
709+
710+
// set up zoom
645711
var zoom = d3.behavior.zoom()
646-
.duration(150)
647712
.scaleExtent([0.1,2.0])
713+
.duration(150)
648714
.on('zoom', scope.redraw);
715+
716+
zoom.translate(scope.translate)
717+
.scale(scope.scale);
718+
649719
svg.call(zoom);
650720

651721
scope.maxValue = 0;
@@ -738,7 +808,9 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
738808
} // end of if data.properties are defined
739809

740810
// set up dimensions
741-
var width = d3.select(element[0]).node().offsetWidth - margin;
811+
width = d3.select(element[0]).node().offsetWidth - margin;
812+
813+
scope.drawPlaceholder(data, width, height);
742814

743815
// create force layout
744816
scope.force = d3.layout.force()
@@ -782,7 +854,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
782854
});
783855

784856
svg.attr('width', width)
785-
.attr('height', height - 60);
857+
.attr('height', Math.max(height - 60, 0));
786858

787859
scope.nodesToDraw.forEach(function (node) {
788860
node.radius = scope.calcRadius(node);

app/components/settings/settings.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<div class="container">
22

3-
<h2>SPARQL Queries</h2>
3+
<h2>Retrieval Options</h2>
44

55
<form name="extractionForm" class="form-horizontal well" role="form" novalidate>
66
<div class="form-group" ng-class="{ 'has-error' : extractionForm.limit.$invalid && !extractionForm.limit.$pristine }">
7-
<label class="control-label col-sm-3" for="lang">Label Language</label>
7+
<label class="control-label col-sm-3" for="lang">Language of Labels</label>
88
<div class="col-sm-4">
99
<select class="form-control" name="lang" id="lang" ng-model="vm.currentLanguage"
1010
ng-options="language.id as language.name for language in vm.availableLanguages">
1111
</select>
1212
</div>
1313

14-
<label for="limit" class="col-sm-2 control-label">Default Limit</label>
14+
<label for="limit" class="col-sm-2 control-label">Number of Classes</label>
1515
<div class="col-sm-3">
1616
<input class="form-control" name="limit" id="limit" type="number" ng-model="vm.currentLimit" min="1" required/>
1717
<p ng-show="extractionForm.limit.$invalid && !extractionForm.limit.$pristine" class="help-block">
@@ -25,7 +25,7 @@ <h2>SPARQL Queries</h2>
2525
<div class="checkbox">
2626
<label>
2727
<input type="checkbox" name="ordered" ng-model="vm.propsOrdered">
28-
fetch properties in descending order of their usage
28+
retrieve properties in descending order of their usage frequency
2929
</label>
3030
</div>
3131
</div>

app/components/sidebar/groups/endpoint-group/endpoint-group.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<span class="glyphicon glyphicon-link" aria-hidden="true"></span>
55
URL:
66
</strong>
7+
<span ng-show="vm.endpointURL.length === 0">None</span>
78
<a href="{{vm.endpointURL}}" target="_blank">{{vm.endpointURL}}</a>
89
</p>
910

@@ -34,4 +35,17 @@
3435
<span>(Status: {{errorStatus.join(', ')}})</span>
3536
<span ng-show="failedRequests === 0">None</span>
3637
</p>
38+
39+
<div class="text-center" ng-if="vm.endpointURL.length > 0">
40+
<button type="button" class="btn btn-warning" ng-click="vm.restartLoading()" ng-show="pendingRequests === 0">
41+
<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
42+
Reload
43+
</button>
44+
45+
<button type="button" class="btn btn-danger" ng-click="vm.stopLoading()" ng-hide="pendingRequests === 0">
46+
<span class="glyphicon glyphicon-stop" aria-hidden="true"></span>
47+
Stop
48+
</button>
49+
</div>
50+
3751
</div>

app/components/sidebar/slider.drv.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ function slider($rootScope) {
2424
scope.value = parseInt(ui.value);
2525
$rootScope.$broadcast(attrs.model + '-changed', ui.value);
2626
});
27+
},
28+
29+
// this function is needed to set the initial value, otherwise slider will always be at zero in the beginning
30+
create: function() {
31+
$(this).slider('value', scope.value);
2732
}
2833
});
2934
} // end pf link()

app/components/start/start.ctrl.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
*
66
* @param $log
77
* @param $location
8-
* @param Nodes
9-
* @param Properties
8+
* @param Data
9+
* @param View
1010
* @param Requests
1111
* @param RequestConfig
12-
* @param Promises
1312
*/
14-
function startCtrl($log, $location, Nodes, Properties, Requests, RequestConfig, Promises) {
13+
function startCtrl($log, $location, Data, View, Requests, RequestConfig) {
1514

1615
'ngInject';
1716

@@ -136,23 +135,18 @@ function startCtrl($log, $location, Nodes, Properties, Requests, RequestConfig,
136135
*/
137136
start.showGraph = function () {
138137

139-
var lastEndpoint = RequestConfig.getEndpointURL();
138+
const lastEndpoint = RequestConfig.getEndpointURL();
140139

141140
// clear loaded data if endpoint has changed
142141
if (lastEndpoint !== start.endpoint && start.endpoint !== undefined && start.endpoint.length > 0) {
143-
Promises.rejectAll();
142+
Data.clearAll();
144143

145-
Nodes.clearAll();
146-
Properties.clearAll();
147-
Requests.clear();
148-
149-
$log.warn('[Start] Cleared all saved data!');
144+
View.reset();
150145

151146
// change endpoint
152147
RequestConfig.setEndpointURL(start.endpoint);
153148

154-
Nodes.initMap();
155-
Properties.initProperties();
149+
Data.initMaps();
156150
}
157151

158152
RequestConfig.setUseLocalProxy(start.useLocalProxy);
@@ -163,6 +157,9 @@ function startCtrl($log, $location, Nodes, Properties, Requests, RequestConfig,
163157

164158
// move to the graph view
165159
$location.path('graph');
160+
161+
// $location url-encodes parameters automatically
162+
$location.search('endpointURL', start.endpoint);
166163
} else {
167164
$log.error('[Start] Please enter an url for the SPARQL endpoint!');
168165
}

0 commit comments

Comments
 (0)