Skip to content

Commit

Permalink
chore(context-pad): scale margin with canvas zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed May 3, 2024
1 parent 698426f commit 665980a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
11 changes: 4 additions & 7 deletions lib/features/context-pad/ContextPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { isConnection } from '../../util/ModelUtil';
var entrySelector = '.entry';

var DEFAULT_PRIORITY = 1000;
var CONTEXT_PAD_MARGIN = 12;
var CONTEXT_PAD_MARGIN = 8;
var HOVER_DELAY = 300;

/**
Expand Down Expand Up @@ -554,7 +554,7 @@ ContextPad.prototype._getPosition = function(target) {
y = lastWaypoint.y * viewbox.scale - viewbox.y * viewbox.scale;

return {
left: x + CONTEXT_PAD_MARGIN,
left: x + CONTEXT_PAD_MARGIN * this._canvas.zoom(),
top: y
};
}
Expand All @@ -565,12 +565,9 @@ ContextPad.prototype._getPosition = function(target) {

var targetBounds = this._getTargetBounds(target);

var left = targetBounds.right - containerBounds.left + CONTEXT_PAD_MARGIN;
var top = targetBounds.top - containerBounds.top;

return {
left,
top
left: targetBounds.right - containerBounds.left + CONTEXT_PAD_MARGIN * this._canvas.zoom(),
top: targetBounds.top - containerBounds.top
};
};

Expand Down
27 changes: 24 additions & 3 deletions test/spec/features/context-pad/ContextPadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,27 @@ describe('features/context-pad', function() {
var containerBounds = canvas.getContainer().getBoundingClientRect();
var targetBounds = canvas.getGraphics(shape).getBoundingClientRect();

expect(position.left).be.closeTo(targetBounds.left + targetBounds.width + 8 - containerBounds.left, 1);
expect(position.top).be.closeTo(targetBounds.top - containerBounds.top, 1);
}));


it('shape (scaled)', inject(function(canvas, contextPad) {

// given
var shape = { id: 's1', width: 100, height: 100, x: 10, y: 10 };

canvas.addShape(shape);

canvas.zoom(1.5);

// when
var position = contextPad._getPosition(shape);

// then
var containerBounds = canvas.getContainer().getBoundingClientRect();
var targetBounds = canvas.getGraphics(shape).getBoundingClientRect();

expect(position.left).be.closeTo(targetBounds.left + targetBounds.width + 12 - containerBounds.left, 1);
expect(position.top).be.closeTo(targetBounds.top - containerBounds.top, 1);
}));
Expand All @@ -1325,7 +1346,7 @@ describe('features/context-pad', function() {
var containerBounds = canvas.getContainer().getBoundingClientRect();
var targetBounds = canvas.getGraphics(connection).getBoundingClientRect();

expect(position.left).be.closeTo(targetBounds.left + targetBounds.width + 12 - containerBounds.left, 1);
expect(position.left).be.closeTo(targetBounds.left + targetBounds.width + 8 - containerBounds.left, 1);
expect(position.top).be.closeTo(targetBounds.bottom - containerBounds.top, 1);
}));

Expand All @@ -1349,7 +1370,7 @@ describe('features/context-pad', function() {
var target1Bounds = canvas.getGraphics(shape1).getBoundingClientRect();
var target2Bounds = canvas.getGraphics(shape2).getBoundingClientRect();

expect(position.left).be.closeTo(target2Bounds.left + target2Bounds.width + 12 - containerBounds.left, 1);
expect(position.left).be.closeTo(target2Bounds.left + target2Bounds.width + 8 - containerBounds.left, 1);
expect(position.top).be.closeTo(target1Bounds.top - containerBounds.top, 1);
}));

Expand All @@ -1370,7 +1391,7 @@ describe('features/context-pad', function() {
var containerBounds = canvas.getContainer().getBoundingClientRect();
var targetBounds = canvas.getGraphics(shape).getBoundingClientRect();

expect(position.left).be.closeTo(targetBounds.left + targetBounds.width + 12 - containerBounds.left, 1);
expect(position.left).be.closeTo(targetBounds.left + targetBounds.width + 8 - containerBounds.left, 1);
expect(position.top).be.closeTo(targetBounds.top - containerBounds.top, 1);
}));

Expand Down

0 comments on commit 665980a

Please sign in to comment.