Skip to content

Commit

Permalink
feat(layout): allow moving of source point on straight layouting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Matias committed Jun 21, 2016
1 parent 8468695 commit 1a95fcd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/layout/ManhattanLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,30 @@ module.exports.layoutStraight = function(source, target, start, end, hints) {
primaryAxis = 'y';
}

if (hints.moveSource) {

This comment has been minimized.

Copy link
@nikku

nikku Jun 22, 2016

Member

TODO: Document this hint. What does it do? Is this the appropriate name?

This comment has been minimized.

Copy link
@ricardomatias

ricardomatias Jun 22, 2016

Contributor

It moves the source's docking point instead of the target's docking point.


if (!isInRange(primaryAxis, end, source)) {
return null;
}

axis[primaryAxis] = end[primaryAxis];

return [
{
x: axis.x !== undefined ? axis.x : start.x,
y: axis.y !== undefined ? axis.y : start.y,
original: {
x: axis.x !== undefined ? axis.x : start.x,
y: axis.y !== undefined ? axis.y : start.y
}
},
{
x: end.x,
y: end.y
}
];
}

if (!isInRange(primaryAxis, start, target)) {
return null;
}
Expand Down
38 changes: 38 additions & 0 deletions test/spec/layout/ManhattanLayoutSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,25 @@ describe('layout/ManhattanLayout', function() {
});


it('should layout straight line (horizontal) by moving source point', function() {

// given
var start = rect(100, 100, 100, 100),
end = rect(300, 50, 100, 300);

var waypoints = [];

// when
var repaired = repair(start, end, waypoints, { preferredLayouts: [ 'straight' ], moveSource: true });

// then
expect(repaired).to.eql([
{ x: 150, y: 200, original: { x: 150, y: 200 } },
{ x: 350, y: 200 }
]);
});


it('should layout straight line (vertical)', function() {

// given
Expand All @@ -420,6 +439,25 @@ describe('layout/ManhattanLayout', function() {
]);
});


it('should layout straight line (vertical) by moving source point', function() {

// given
var start = rect(100, 100, 100, 100),
end = rect(50, 300, 200, 100);

var waypoints = [];

// when
var repaired = repair(start, end, waypoints, { preferredLayouts: [ 'straight' ], moveSource: true });

// then
expect(repaired).to.eql([
{ x: 150, y: 150, original: { x: 150, y: 150 } },
{ x: 150, y: 350 }
]);
});

});


Expand Down

0 comments on commit 1a95fcd

Please sign in to comment.