From 654a65ebd54ea2c8d7b7b912c76fa79f1dc88886 Mon Sep 17 00:00:00 2001 From: Roman Bruckner Date: Wed, 14 Aug 2024 13:18:04 +0200 Subject: [PATCH] unset transform attributes --- .../src/dia/attributes/connection.mjs | 4 +++ .../joint-core/test/jointjs/dia/attributes.js | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/joint-core/src/dia/attributes/connection.mjs b/packages/joint-core/src/dia/attributes/connection.mjs index 95975243f..2e8b063e8 100644 --- a/packages/joint-core/src/dia/attributes/connection.mjs +++ b/packages/joint-core/src/dia/attributes/connection.mjs @@ -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 }) } diff --git a/packages/joint-core/test/jointjs/dia/attributes.js b/packages/joint-core/test/jointjs/dia/attributes.js index e86cbfc3c..f5fcfce79 100644 --- a/packages/joint-core/test/jointjs/dia/attributes.js +++ b/packages/joint-core/test/jointjs/dia/attributes.js @@ -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']; + }); });