Skip to content

Commit e8e5032

Browse files
committed
Extract link calculation and edge lengths into separate service.
- Add JSDoc comments. - Move 'ngInject' annotation into JSDoc comment.
1 parent 3d52811 commit e8e5032

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+535
-282
lines changed

app/app.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import settingsTemplate from './components/settings/settings.html';
33
import graphTemplate from './components/graph/graph.html';
44
import aboutTemplate from './components/about/about.html';
55

6+
/**
7+
* @param $httpProvider
8+
* @param $routeProvider
9+
* @param $logProvider
10+
*
11+
* @ngInject
12+
*/
613
function routing($httpProvider, $routeProvider, $logProvider) {
714

8-
'ngInject';
9-
1015
// set up http interceptor
1116
$httpProvider.interceptors.push('RequestCounter');
1217
$httpProvider.defaults.useXDomain = true;

app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import routing from './app.config';
1111
import runBlock from './app.run';
1212

1313
// create main app module
14-
module.exports = angular.module('ldVOWLApp', ['ngRoute', 'ngAnimate', 'ui.bootstrap', 'ngCookies', components, filters,
14+
export default angular.module('ldVOWLApp', ['ngRoute', 'ngAnimate', 'ui.bootstrap', 'ngCookies', components, filters,
1515
services, utilities])
1616
.config(routing)
1717
.run(runBlock);

app/app.run.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
/**
2+
* @param $rootScope
3+
*
4+
* @ngInject
5+
*/
16
function runBlock($rootScope) {
27

3-
'ngInject';
4-
58
$rootScope.$on('$routeChangeSuccess', function (event, current) {
69
if (current && current.$$route && current.$$route.title) {
710
$rootScope.title = current.$$route.title;

app/components/graph/graph.ctrl.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/**
2-
* @Name GraphCtrl
2+
* @ngdoc type
3+
* @name GraphCtrl
34
*
45
* @param {$location} $location
56
* @param {$log} $log
6-
* @param TBoxExtractor
7+
* @param {TBoxExtractor} TBoxExtractor
78
* @param DetailExtractor
8-
* @param RequestConfig
9-
* @param Data
9+
* @param {RequestConfig} RequestConfig
10+
* @param {Data} Data
1011
* @param View
12+
*
13+
* @ngInject
1114
*/
1215
function graphCtrl($location, $log, TBoxExtractor, DetailExtractor, RequestConfig, Data, View) {
1316

14-
'ngInject';
15-
1617
/* jshint validthis: true */
1718
const vm = this;
1819

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

Lines changed: 27 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ import d3 from 'd3';
66
* @name NodeLinkGraph
77
* @module components.graph
88
*
9-
* @param $window
9+
* @param {$window} $window
1010
* @param $log
11-
* @param Properties
12-
* @param Nodes
11+
* @param {Properties} Properties
12+
* @param {Nodes} Nodes
1313
* @param Prefixes
14-
* @param Filters
15-
* @param {Geometry} Geometry
14+
* @param {Filters} Filters
1615
* @param Utils
17-
* @param Requests
16+
* @param {Requests} Requests
1817
* @param View
18+
* @param {Links} Links
1919
*
2020
* @description
2121
*
2222
* This is the directive which shows the node link graph using D3.
23+
*
24+
* @ngInject
2325
*/
24-
function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geometry, Utils, Requests, View) {
25-
26-
'ngInject';
26+
function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Utils, Requests, View, Links) {
2727

2828
return {
2929
restrict: 'EA',
@@ -68,11 +68,6 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
6868

6969
scope.paused = false;
7070

71-
scope.propDistance = 100;
72-
scope.dtPropDistance = 50;
73-
scope.disjointPropDistance = 100;
74-
scope.loopDistance = 80;
75-
7671
scope.disjointNodeWidth = 40;
7772
scope.disjointNodeHeight = 20;
7873

@@ -182,15 +177,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
182177
scope.render(scope.data);
183178
});
184179

185-
scope.$on('ccEdgeLength-changed', function (event, newPropDistance) {
186-
scope.propDistance = newPropDistance;
187-
if (scope.force !== undefined) {
188-
scope.force.start();
189-
}
190-
});
191-
192-
scope.$on('ctEdgeLength-changed', function (event, newDtPropDistance) {
193-
scope.dtPropDistance = newDtPropDistance;
180+
scope.$on('edge-length-changed', function (){
194181
if (scope.force !== undefined) {
195182
scope.force.start();
196183
}
@@ -331,35 +318,6 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
331318
return (-1) * (scope.calcPropHighlightBoxWidth(d) / 2);
332319
};
333320

334-
scope.linkDistance = function (d) {
335-
var distance;
336-
if ((d.target !== undefined && d.target.isLoopNode) || (d.source !== undefined && d.source.isLoopNode)) {
337-
338-
// loops
339-
distance = scope.loopDistance;
340-
} else {
341-
342-
// non-loops
343-
if (d.type === 'datatypeProperty') {
344-
distance = scope.dtPropDistance;
345-
} else if (d.type === 'disjointProperty') {
346-
distance = scope.disjointPropDistance;
347-
} else {
348-
distance = scope.propDistance;
349-
}
350-
351-
// add radius to source and target
352-
if (d.source !== undefined && d.source.radius !== undefined) {
353-
distance += d.source.radius;
354-
}
355-
if (d.target !== undefined && d.target.radius !== undefined) {
356-
distance += d.target.radius;
357-
}
358-
}
359-
360-
return distance;
361-
};
362-
363321
/**
364322
* Handles the selection of graph items like classes, properties and types.
365323
*
@@ -429,7 +387,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
429387
};
430388

431389
scope.redraw = function () {
432-
root.attr('transform', 'translate(' + d3.event.translate + ')' + 'scale(' + d3.event.scale + ')');
390+
root.attr('transform', `translate(${d3.event.translate})scale(${d3.event.scale})`);
433391

434392
// save current view
435393
View.setTranslate(d3.event.translate);
@@ -448,25 +406,15 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
448406
linkContainer.append('defs').selectAll('marker')
449407
.data(scope.getArrowHeads())
450408
.enter().append('marker')
451-
.attr('id', function (d) {
452-
return d.id;
453-
})
454-
.attr('class', function (d) {
455-
return d.class;
456-
})
409+
.attr('id', function (d) { return d.id; })
410+
.attr('class', function (d) { return d.class; })
457411
.attr('viewBox', function (d) {
458412
return '-1 ' + ((d.size + 1) * (-1)) + ' ' + ((d.size + 1) * 2) + ' ' + ((d.size + 1) * 2);
459413
})
460-
.attr('refX', function (d) {
461-
return d.size * 2;
462-
})
414+
.attr('refX', function (d) { return d.size * 2;})
463415
.attr('refY', 0)
464-
.attr('markerWidth', function (d) {
465-
return d.size;
466-
})
467-
.attr('markerHeight', function (d) {
468-
return d.size;
469-
})
416+
.attr('markerWidth', function (d) { return d.size; })
417+
.attr('markerHeight', function (d) { return d.size; })
470418
.attr('orient', 'auto')
471419
.style('stroke', function (d) {
472420
return (d.class === 'hovered') ? 'red' : scope.arrowColor(d.size);
@@ -482,7 +430,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
482430
})
483431
.append('path')
484432
.attr('d', function (d) {
485-
return 'M0,' + (d.size * -1) + 'L' + (d.size * 2) + ',0L0,' + d.size + 'Z';
433+
return `M0,${d.size * -1}L${d.size * 2},0L0,${d.size}Z`;
486434
});
487435
};
488436

@@ -695,45 +643,17 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
695643
.style('stroke-dasharray', '5, 5');
696644
};
697645

646+
/**
647+
* @param {{source, intermediate, target}} d
648+
*/
698649
scope.recalculateLines = function(d) {
699-
var line = {};
700-
701650
// check whether current line is a loop
702651
if (d.source.id === d.target.id) {
703-
704-
var loopData = [];
705-
706-
// for the loops
707-
loopData.push(Geometry.getAnotherCircleOutlinePoint(d, -1));
708-
loopData.push({x: d.intermediate.x, y: d.intermediate.y});
709-
710-
// loops are always towards classes
711-
loopData.push(Geometry.getAnotherCircleOutlinePoint(d, 1));
712-
713-
line = scope.loopSpline(loopData);
652+
return scope.loopSpline(Links.getLoopData(d));
714653
} else {
715-
716-
// non-loop
717-
718-
var lineData = [];
719-
720-
// TODO should also start from circumference
721-
lineData.push({x: d.source.x, y: d.source.y});
722-
lineData.push({x: d.intermediate.x, y: d.intermediate.y});
723-
724-
// position depends on node type
725-
if (d.target.type === 'class') {
726-
lineData.push(Geometry.getCircleOutlinePoint(d));
727-
} else {
728-
lineData.push(Geometry.getRectOutlinePoint(d));
729-
}
730-
731-
line = scope.cardinalSpline(lineData);
654+
return scope.cardinalSpline(Links.getLineData(d));
732655
}
733-
734-
return line;
735-
}; // end of recalculateLines()
736-
656+
};
737657

738658
scope.recalculateDirectLines = function (d) {
739659
var lineData = [];
@@ -785,7 +705,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
785705
if (resultCodes.length > 0) {
786706
switch (resultCodes[0]) {
787707
case -1:
788-
message = 'Given SPARQL endpoint is not accessable.';
708+
message = 'Given SPARQL endpoint is not accessible.';
789709
break;
790710

791711
case 400:
@@ -844,7 +764,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
844764
}
845765

846766
// restore view
847-
root.attr('transform', 'translate(' + scope.translate + ')' + 'scale(' + scope.scale + ')');
767+
root.attr('transform', `translate(${scope.translate})scale(${scope.scale})`);
848768

849769
// set up zoom
850770
var zoom = d3.behavior.zoom()
@@ -929,7 +849,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
929849
scope.force = d3.layout.force()
930850
.charge(-500)
931851
.linkStrength(1.0)
932-
.linkDistance(scope.linkDistance)
852+
.linkDistance(Links.getDistance)
933853
.gravity(0.03)
934854
.size([width, height]);
935855

@@ -957,7 +877,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
957877
scope.tick = function () {
958878
scope.link.attr('d', scope.recalculateLines);
959879
scope.directLink.attr('d', scope.recalculateDirectLines);
960-
scope.node.attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')'; });
880+
scope.node.attr('transform', function(d) { return `translate(${d.x},${d.y})`; });
961881
};
962882
} // end of link()
963883
}; // end of returned directive

app/components/header/header.ctrl.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
'use strict';
2-
31
/**
2+
* @ngdoc type
43
* @name HeaderCtrl
4+
*
55
* @param $scope
66
* @param $location
7+
*
8+
* @ngInject
79
*/
810
function HeaderCtrl($scope, $location) {
911

10-
'ngInject';
11-
12-
let header = this;
12+
const header = this;
1313

1414
header.loading = false;
1515

app/components/settings/settings.ctrl.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
'use strict';
2-
1+
/**
2+
* @ngdoc type
3+
* @name SettingsCtrl
4+
*
5+
* @param $log
6+
* @param $cookies
7+
* @param PREFIX
8+
* @param PROPERTY_BLACKLIST
9+
* @param CLASS_BLACKLIST
10+
* @param {RequestConfig} RequestConfig
11+
* @param Data
12+
* @param ClassExtractor
13+
* @param RelationExtractor
14+
*
15+
* @ngInject
16+
*/
317
function settingsCtrl($log, $cookies, PREFIX, PROPERTY_BLACKLIST, CLASS_BLACKLIST, RequestConfig, Data, ClassExtractor,
418
RelationExtractor) {
519

6-
'ngInject';
7-
820
/* jshint validthis: true */
921
const vm = this;
1022

app/components/sidebar/groups/endpoint-group/endpoint-group.ctrl.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
/**
2+
* @ngdoc type
3+
* @name EndpointGroupCtrl
4+
*
5+
* @param $scope
6+
* @param $location
7+
* @param Requests
8+
* @param RequestConfig
9+
*
10+
* @ngInject
11+
*/
112
function endpointGroupCtrl($scope, $location, Requests, RequestConfig) {
213

3-
'ngInject';
4-
514
const vm = this;
615

716
vm.showEndpointUrl = true;

app/components/sidebar/groups/filter-group/filter-group.ctrl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* @Name FilterGroupCtrl
33
*
4-
* @param Filters
5-
* @param TBoxExtractor
4+
* @param {Filters} Filters
5+
* @param {TBoxExtractor} TBoxExtractor
6+
*
7+
* @ngInject
68
*/
79
function filterGroupCtrl(Filters, TBoxExtractor) {
810

9-
'ngInject';
10-
1111
const vm = this;
1212

1313
vm.filterTypes = !Filters.getIncludeLiterals();

0 commit comments

Comments
 (0)