@@ -64,6 +64,67 @@ QUnit.module('linkTools', function(hooks) {
6464 assert . deepEqual ( link . prop ( [ 'target' , 'anchor' ] ) , testCase . resultAnchor ) ;
6565 } ) ;
6666 } ) ;
67+
68+ QUnit . test ( 'No area' , function ( assert ) {
69+ const CustomAnchor = joint . linkTools . TargetAnchor . extend ( {
70+ children : [ {
71+ tagName : 'circle' ,
72+ selector : 'anchor' ,
73+ attributes : {
74+ 'cursor' : 'pointer'
75+ }
76+ } ]
77+ } ) ;
78+ const anchor = new CustomAnchor ( ) ;
79+ linkView . addTools ( new joint . dia . ToolsView ( { tools : [ anchor ] } ) ) ;
80+ assert . ok ( true , 'The anchor tool does not require an area node.' ) ;
81+ } ) ;
82+
83+ QUnit . test ( 'No anchor' , function ( assert ) {
84+ const CustomAnchor = joint . linkTools . TargetAnchor . extend ( {
85+ children : [ {
86+ tagName : 'rect' ,
87+ selector : 'area' ,
88+ attributes : {
89+ 'pointer-events' : 'none' ,
90+ 'fill' : 'none' ,
91+ 'stroke' : '#33334F' ,
92+ 'stroke-dasharray' : '2,4' ,
93+ 'rx' : 5 ,
94+ 'ry' : 5
95+ }
96+ } ]
97+ } ) ;
98+ const anchor = new CustomAnchor ( ) ;
99+ linkView . addTools ( new joint . dia . ToolsView ( { tools : [ anchor ] } ) ) ;
100+ assert . ok ( true , 'The anchor tool does not require an anchor node.' ) ;
101+ } ) ;
102+
103+ QUnit . test ( 'Element area bounding box' , function ( assert ) {
104+ paper . translate ( 11 , 13 ) ;
105+ const areaPadding = 7 ;
106+ const anchor = new joint . linkTools . TargetAnchor ( { areaPadding } ) ;
107+ linkView . addTools ( new joint . dia . ToolsView ( { tools : [ anchor ] } ) ) ;
108+ anchor . toggleArea ( true ) ;
109+ const areaBBox = V ( anchor . childNodes . area ) . getBBox ( { target : paper . viewport } ) ;
110+ assert . checkBboxApproximately ( 1e-6 , areaBBox , link . getTargetCell ( ) . getBBox ( ) . inflate ( areaPadding ) ) ;
111+ } ) ;
112+
113+ QUnit . test ( 'Link area bounding box' , function ( assert ) {
114+ const link2 = new joint . shapes . standard . Link ( {
115+ source : { x : 100 , y : 100 } ,
116+ target : { x : 200 , y : 200 }
117+ } ) ;
118+ graph . addCell ( link2 ) ;
119+ link . target ( link2 ) ;
120+ paper . translate ( 11 , 13 ) ;
121+ const areaPadding = 7 ;
122+ const anchor = new joint . linkTools . TargetAnchor ( { areaPadding } ) ;
123+ linkView . addTools ( new joint . dia . ToolsView ( { tools : [ anchor ] } ) ) ;
124+ anchor . toggleArea ( true ) ;
125+ const areaBBox = V ( anchor . childNodes . area ) . getBBox ( { target : paper . viewport } ) ;
126+ assert . checkBboxApproximately ( 1e-6 , areaBBox , link . getTargetCell ( ) . getBBox ( ) . inflate ( areaPadding ) ) ;
127+ } ) ;
67128 } ) ;
68129
69130 QUnit . module ( 'SourceAnchor' , function ( ) {
@@ -85,6 +146,32 @@ QUnit.module('linkTools', function(hooks) {
85146 assert . deepEqual ( link . prop ( [ 'source' , 'anchor' ] ) , testCase . resultAnchor ) ;
86147 } ) ;
87148 } ) ;
149+
150+ QUnit . test ( 'Element area bounding box' , function ( assert ) {
151+ paper . translate ( 11 , 13 ) ;
152+ const areaPadding = 7 ;
153+ const anchor = new joint . linkTools . SourceAnchor ( { areaPadding } ) ;
154+ linkView . addTools ( new joint . dia . ToolsView ( { tools : [ anchor ] } ) ) ;
155+ anchor . toggleArea ( true ) ;
156+ const areaBBox = V ( anchor . childNodes . area ) . getBBox ( { target : paper . viewport } ) ;
157+ assert . checkBboxApproximately ( 1e-6 , areaBBox , link . getSourceCell ( ) . getBBox ( ) . inflate ( areaPadding ) ) ;
158+ } ) ;
159+
160+ QUnit . test ( 'Link area bounding box' , function ( assert ) {
161+ const link2 = new joint . shapes . standard . Link ( {
162+ source : { x : 100 , y : 100 } ,
163+ target : { x : 200 , y : 200 }
164+ } ) ;
165+ graph . addCell ( link2 ) ;
166+ link . source ( link2 ) ;
167+ paper . translate ( 11 , 13 ) ;
168+ const areaPadding = 7 ;
169+ const anchor = new joint . linkTools . SourceAnchor ( { areaPadding } ) ;
170+ linkView . addTools ( new joint . dia . ToolsView ( { tools : [ anchor ] } ) ) ;
171+ anchor . toggleArea ( true ) ;
172+ const areaBBox = V ( anchor . childNodes . area ) . getBBox ( { target : paper . viewport } ) ;
173+ assert . checkBboxApproximately ( 1e-6 , areaBBox , link . getSourceCell ( ) . getBBox ( ) . inflate ( areaPadding ) ) ;
174+ } ) ;
88175 } ) ;
89176
90177 QUnit . module ( 'Connect' , function ( ) {
0 commit comments