Skip to content

Commit

Permalink
Merge pull request #252 from ditrit/bugfix/reverse_link
Browse files Browse the repository at this point in the history
Bugfix: reverse link display
  • Loading branch information
Zorin95670 authored Jun 18, 2024
2 parents e64d1a3 + e2d8ff9 commit bf17c29
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [Unreleased]

### Fixed

- Reverse link display management.

## [0.24.0] - 2024/06/12

### Added
Expand Down
2 changes: 1 addition & 1 deletion demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/draw/render/LinkRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class LinkRenderer {
y: link.endY,
};
} else {
sourceAnchor = this.getClosestAnchor(link.source, link.target);
targetAnchor = this.getClosestAnchor(link.target, link.source);
const source = link.isReverse ? link.target : link.source;
const target = link.isReverse ? link.source : link.target;

sourceAnchor = this.getClosestAnchor(source, target);
targetAnchor = this.getClosestAnchor(target, source);
}

return renderString(
Expand Down
10 changes: 10 additions & 0 deletions src/models/ComponentLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ class ComponentLink extends FileInformation {
* @param {string} [props.target] - Id of component can be the target of the link.
* @param {string} [props.name] - Name of the link anchor, link to store where the link begin.
* @param {ComponentLinkDefinition} [props.definition] - The definition of the link.
* @param {boolean} [props.isReverse] - Indicate if this link is a reverse link.
* The purpose of reversing a Link is to switch the start and the end of the link.
*/
constructor(props = {
source: null,
target: null,
name: null,
definition: null,
isReverse: false,
}) {
super();
const {
source,
target,
name,
definition,
isReverse,
} = props;

/**
Expand Down Expand Up @@ -53,6 +57,12 @@ class ComponentLink extends FileInformation {
* @type {ComponentLinkDefinition}
*/
this.definition = definition || null;
/**
* Indicate if this link is a reverse link.
* The purpose of reversing a Link is to switch the start and the end of the link.
* @type {boolean}
*/
this.isReverse = !!isReverse;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/models/DefaultData.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class DefaultData {
definition,
source: component.id,
target: value,
isReverse: attribute.definition.linkType === 'Reverse',
})));
});
});
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/models/ComponentLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Test class: ComponentLink', () => {
expect(link.target).toBeNull();
expect(link.name).toBeNull();
expect(link.definition).toBeNull();
expect(link.isReverse).toEqual(false);
});

it('Check passing undefined variables to constructor', () => {
Expand All @@ -20,6 +21,7 @@ describe('Test class: ComponentLink', () => {
expect(link.target).toBeNull();
expect(link.name).toBeNull();
expect(link.definition).toBeNull();
expect(link.isReverse).toEqual(false);
});

it('Check passing variable to constructor', () => {
Expand All @@ -28,13 +30,15 @@ describe('Test class: ComponentLink', () => {
target: 'target',
name: 'name',
definition: {},
isReverse: true,
});

expect(link.__class).toEqual('Link');
expect(link.source).toEqual('source');
expect(link.target).toEqual('target');
expect(link.name).toEqual('name');
expect(link.definition).toBeDefined();
expect(link.isReverse).toEqual(true);
});
});
});
1 change: 1 addition & 0 deletions tests/unit/models/DefaultData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ describe('Test class: DefaultData', () => {
definition: pluginData.definitions.links[1],
source: 'server2',
target: 'server1',
isReverse: true,
}),
new ComponentLink({
definition: pluginData.definitions.links[2],
Expand Down

0 comments on commit bf17c29

Please sign in to comment.