@@ -6,24 +6,24 @@ import d3 from 'd3';
6
6
* @name NodeLinkGraph
7
7
* @module components.graph
8
8
*
9
- * @param $window
9
+ * @param { $window } $window
10
10
* @param $log
11
- * @param Properties
12
- * @param Nodes
11
+ * @param { Properties } Properties
12
+ * @param { Nodes } Nodes
13
13
* @param Prefixes
14
- * @param Filters
15
- * @param {Geometry } Geometry
14
+ * @param {Filters } Filters
16
15
* @param Utils
17
- * @param Requests
16
+ * @param { Requests } Requests
18
17
* @param View
18
+ * @param {Links } Links
19
19
*
20
20
* @description
21
21
*
22
22
* This is the directive which shows the node link graph using D3.
23
+ *
24
+ * @ngInject
23
25
*/
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 ) {
27
27
28
28
return {
29
29
restrict : 'EA' ,
@@ -68,11 +68,6 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
68
68
69
69
scope . paused = false ;
70
70
71
- scope . propDistance = 100 ;
72
- scope . dtPropDistance = 50 ;
73
- scope . disjointPropDistance = 100 ;
74
- scope . loopDistance = 80 ;
75
-
76
71
scope . disjointNodeWidth = 40 ;
77
72
scope . disjointNodeHeight = 20 ;
78
73
@@ -182,15 +177,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
182
177
scope . render ( scope . data ) ;
183
178
} ) ;
184
179
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 ( ) {
194
181
if ( scope . force !== undefined ) {
195
182
scope . force . start ( ) ;
196
183
}
@@ -331,35 +318,6 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
331
318
return ( - 1 ) * ( scope . calcPropHighlightBoxWidth ( d ) / 2 ) ;
332
319
} ;
333
320
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
-
363
321
/**
364
322
* Handles the selection of graph items like classes, properties and types.
365
323
*
@@ -429,7 +387,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
429
387
} ;
430
388
431
389
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 } )` ) ;
433
391
434
392
// save current view
435
393
View . setTranslate ( d3 . event . translate ) ;
@@ -448,25 +406,15 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
448
406
linkContainer . append ( 'defs' ) . selectAll ( 'marker' )
449
407
. data ( scope . getArrowHeads ( ) )
450
408
. 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 ; } )
457
411
. attr ( 'viewBox' , function ( d ) {
458
412
return '-1 ' + ( ( d . size + 1 ) * ( - 1 ) ) + ' ' + ( ( d . size + 1 ) * 2 ) + ' ' + ( ( d . size + 1 ) * 2 ) ;
459
413
} )
460
- . attr ( 'refX' , function ( d ) {
461
- return d . size * 2 ;
462
- } )
414
+ . attr ( 'refX' , function ( d ) { return d . size * 2 ; } )
463
415
. 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 ; } )
470
418
. attr ( 'orient' , 'auto' )
471
419
. style ( 'stroke' , function ( d ) {
472
420
return ( d . class === 'hovered' ) ? 'red' : scope . arrowColor ( d . size ) ;
@@ -482,7 +430,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
482
430
} )
483
431
. append ( 'path' )
484
432
. 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` ;
486
434
} ) ;
487
435
} ;
488
436
@@ -695,45 +643,17 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
695
643
. style ( 'stroke-dasharray' , '5, 5' ) ;
696
644
} ;
697
645
646
+ /**
647
+ * @param {{source, intermediate, target} } d
648
+ */
698
649
scope . recalculateLines = function ( d ) {
699
- var line = { } ;
700
-
701
650
// check whether current line is a loop
702
651
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 ) ) ;
714
653
} 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 ) ) ;
732
655
}
733
-
734
- return line ;
735
- } ; // end of recalculateLines()
736
-
656
+ } ;
737
657
738
658
scope . recalculateDirectLines = function ( d ) {
739
659
var lineData = [ ] ;
@@ -785,7 +705,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
785
705
if ( resultCodes . length > 0 ) {
786
706
switch ( resultCodes [ 0 ] ) {
787
707
case - 1 :
788
- message = 'Given SPARQL endpoint is not accessable .' ;
708
+ message = 'Given SPARQL endpoint is not accessible .' ;
789
709
break ;
790
710
791
711
case 400 :
@@ -844,7 +764,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
844
764
}
845
765
846
766
// restore view
847
- root . attr ( 'transform' , ' translate(' + scope . translate + ')' + ' scale(' + scope . scale + ')' ) ;
767
+ root . attr ( 'transform' , ` translate(${ scope . translate } ) scale(${ scope . scale } )` ) ;
848
768
849
769
// set up zoom
850
770
var zoom = d3 . behavior . zoom ( )
@@ -929,7 +849,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
929
849
scope . force = d3 . layout . force ( )
930
850
. charge ( - 500 )
931
851
. linkStrength ( 1.0 )
932
- . linkDistance ( scope . linkDistance )
852
+ . linkDistance ( Links . getDistance )
933
853
. gravity ( 0.03 )
934
854
. size ( [ width , height ] ) ;
935
855
@@ -957,7 +877,7 @@ function NodeLinkGraph($window, $log, Properties, Nodes, Prefixes, Filters, Geom
957
877
scope . tick = function ( ) {
958
878
scope . link . attr ( 'd' , scope . recalculateLines ) ;
959
879
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 } )` ; } ) ;
961
881
} ;
962
882
} // end of link()
963
883
} ; // end of returned directive
0 commit comments