Skip to content

Commit

Permalink
unset transform attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus committed Aug 14, 2024
1 parent 9805974 commit 654a65e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/joint-core/src/dia/attributes/connection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,25 @@ const connectionAttributesNS = {

'at-connection-length-keep-gradient': {
qualify: isLinkView,
unset: 'transform',
set: atConnectionWrapper('getTangentAtLength', { rotate: true })
},

'at-connection-length-ignore-gradient': {
qualify: isLinkView,
unset: 'transform',
set: atConnectionWrapper('getTangentAtLength', { rotate: false })
},

'at-connection-ratio-keep-gradient': {
qualify: isLinkView,
unset: 'transform',
set: atConnectionWrapper('getTangentAtRatio', { rotate: true })
},

'at-connection-ratio-ignore-gradient': {
qualify: isLinkView,
unset: 'transform',
set: atConnectionWrapper('getTangentAtRatio', { rotate: false })
}

Expand Down
33 changes: 33 additions & 0 deletions packages/joint-core/test/jointjs/dia/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,39 @@ QUnit.module('Attributes', function() {
cell.attr('div/html', null);
assert.notOk(divNode.firstChild);
});

QUnit.test('unset transform & position callback', function(assert) {
joint.dia.attributes['test-transform-attribute'] = {
unset: 'transform',
set: function(value) {
return { transform: `translate(${value},${value})` };
}
};
joint.dia.attributes['test-position-attribute'] = {
position(value) {
return new g.Point(value, value);
}
};

// set transform attribute
cell.attr('body/testTransformAttribute', 7);
const bodyNode = cellView.findNode('body');
assert.ok(bodyNode.getAttribute('transform'));
assert.deepEqual(V(bodyNode).translate(), { tx: 7, ty: 7 });
// unset transform attribute
cell.attr('body/testTransformAttribute', null);
assert.notOk(bodyNode.getAttribute('transform'));
assert.deepEqual(V(bodyNode).translate(), { tx: 0, ty: 0 });
// position attribute and deleted transform
cell.attr('body/testPositionAttribute', 11);
assert.deepEqual(V(bodyNode).translate(), { tx: 11, ty: 11 });
// position and set transform attribute
cell.attr('body/testTransformAttribute', 13);
assert.deepEqual(V(bodyNode).translate(), { tx: 13 + 11, ty: 13 + 11 });

delete joint.dia.attributes['test-transform-attribute'];
delete joint.dia.attributes['test-position-attribute'];
});
});


Expand Down

0 comments on commit 654a65e

Please sign in to comment.