Skip to content

Commit

Permalink
conenctionPoints.Boundary: disabling automatic magnet lookup via sele…
Browse files Browse the repository at this point in the history
…ctor option (#2053)
  • Loading branch information
kumilingus authored Mar 18, 2023
1 parent ce79e4e commit ec372eb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/joint/api/connectionPoints/boundary.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<tr>
<th>selector</th>
<td><i>string</i></td>
<td>A selector to identify subelement/magnet of the end element at whose boundary we want the connection point to be found. Default is <code>undefined</code>, meaning that the first non-group descendant of the end element's node will be considered. (An example of another setting that may be useful is <code>'root'</code>, which forces the usage of the root group bbox instead.)</td>
<td>A selector to identify subelement/magnet of the end element at whose boundary we want the connection point to be found. Default is <code>undefined</code>, meaning that the first non-group descendant of the end element's node will be considered. (An example of another setting that may be useful is <code>'root'</code>, which forces the usage of the root group bbox instead.). If set to <code>false</code>, the magnet is used as is, even if it is an SVGGroup (it's the most suitable for use in conjunction with <a href="#dia.attributes.magnetSelector">magnetSelector</a>).</td>
</tr>
<tr>
<th>stroke</th>
Expand Down
2 changes: 2 additions & 0 deletions src/connectionPoints/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function boundaryIntersection(line, view, magnet, opt) {

if (typeof selector === 'string') {
node = view.findBySelector(selector)[0];
} else if (selector === false) {
node = magnet;
} else if (Array.isArray(selector)) {
node = util.getByPath(magnet, selector);
} else {
Expand Down
22 changes: 22 additions & 0 deletions test/jointjs/connectionPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ QUnit.module('connectionPoints', function(hooks) {
line = new g.Line(tp.clone(), sp.clone());
cp = connectionPointFn.call(lv1, line, rv1, rv1.el, { selector: null });
assert.ok(cp.round().equals(r1.getBBox().rightMiddle()));

// Disabling the magnet lookup should use the magnet
// passed to the connector even if it is a group node.
r1.set('markup', [{
tagName: 'g',
selector: 'wrapper',
children: [{
tagName: 'rect',
selector: 'quarter'
}, {
tagName: 'rect',
selector: 'full',
}]
}]);
// lookup off
line = new g.Line(tp.clone(), sp.clone());
cp = connectionPointFn.call(lv1, line, rv1, rv1.findBySelector('wrapper')[0], { selector: false });
assert.ok(cp.round().equals(r1.getBBox().rightMiddle()));
// lookup on
line = new g.Line(tp.clone(), sp.clone());
cp = connectionPointFn.call(lv1, line, rv1, rv1.findBySelector('wrapper')[0], { selector: undefined });
assert.ok(cp.round().equals(r1.getBBox().center().offset(25, 0)));
});


Expand Down
2 changes: 1 addition & 1 deletion types/joint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3694,7 +3694,7 @@ export namespace connectionPoints {
}

interface BoundaryConnectionPointArguments extends StrokeConnectionPointArguments {
selector?: Array<string | number> | string;
selector?: Array<string | number> | string | false;
precision?: number;
extrapolate?: boolean;
sticky?: boolean;
Expand Down

0 comments on commit ec372eb

Please sign in to comment.