jathanasiou commented on a change in pull request #255:
URL: https://github.com/apache/brooklyn-ui/pull/255#discussion_r673893476



##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -774,18 +774,38 @@ export function D3Blueprint(container, options) {
     function drawRelationships() {
         showRelationships();
 
+        // Generates unique relation ID string.
+        const getRelationId = (relationDataItem) => 
(relationDataItem.source._id + '_related_to_' + relationDataItem.target._id);
+
+        // Group relationships per direction, as a key.
+        let relationshipsPerDirection = new Map();

Review comment:
       Do we need strict order iteration for `relationshipsPerDirection`? If 
not, it might be simpler to use a POJO `{}` instead.

##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -774,18 +774,38 @@ export function D3Blueprint(container, options) {
     function drawRelationships() {
         showRelationships();
 
+        // Generates unique relation ID string.
+        const getRelationId = (relationDataItem) => 
(relationDataItem.source._id + '_related_to_' + relationDataItem.target._id);
+
+        // Group relationships per direction, as a key.
+        let relationshipsPerDirection = new Map();
+        _d3DataHolder.visible.relationships.forEach(relation => {
+            const directionKey = getRelationId(relation);
+            if (!relationshipsPerDirection.has(directionKey)) {
+                relationshipsPerDirection.set(directionKey, []);
+            }
+            relationshipsPerDirection.get(directionKey).push(relation.label);
+        });
+
+        // Calculates offset for label, based on number of labels in the same 
direction.
+        const getLabelOffset = (relationDataItem) => {
+            const directionKey = getRelationId(relationDataItem);
+            let labelIndex = 
relationshipsPerDirection.get(directionKey).findIndex(label => label === 
relationDataItem.label);

Review comment:
       Since the arrays have string elements we can simply used `.indexOf` here 
like
   `let labelIndex = 
relationshipsPerDirection.get(directionKey).indexOf(relationDataItem.label);`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to