You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2021/06/23 08:57:54 UTC

[GitHub] [brooklyn-ui] algairim commented on a change in pull request #232: Draw relationship path labels with textPath, if supplied

algairim commented on a change in pull request #232:
URL: https://github.com/apache/brooklyn-ui/pull/232#discussion_r656898649



##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -776,11 +776,39 @@ export function D3Blueprint(container, options) {
         let relationData = _relationGroup.selectAll('.relation')
             .data(_d3DataHolder.visible.relationships, (d)=>(d.source._id + '_related_to_' + d.target._id));
 
-        relationData.enter().insert('path')
+        let relationDataEntered = relationData.enter();
+
+        // Draw the relationship path
+        relationDataEntered.insert('path')
             .attr('class', 'relation')
+            .attr('id', (d)=>(d.source._id + '-' + d.target._id))
             .attr('opacity', 0)
             .attr('from', (d)=>(d.source._id))
             .attr('to', (d)=>(d.target._id));
+
+        // Draw the relationship label that follows the path, somewhere in the middle.
+        // NOTE `textPath` DECREASES THE UI PERFORMANCE, USE LABELS WITH CAUTION.
+        relationDataEntered.insert('text') // Add text layer of '&#9608;'s to erase the area on the path.
+            .attr('dominant-baseline', 'middle')
+            .attr('text-anchor', 'middle')
+            .attr('font-family', 'monospace')
+            .attr('fill', '#f5f6fa')
+                .insert('textPath')
+                .attr('hidden', (d) => (d.label ? null : ''))
+                .attr('xlink:href', (d)=>('#' + d.source._id + '-' + d.target._id))
+                .attr('startOffset', '59%')
+                .html((d) => (d.label ? '&#9608;'.repeat(d.label.length + 2) : null));

Review comment:
       This step might look redundant, however, this is how middle part of the path is erased on the label text:
   <img width="721" alt="Screenshot 2021-06-23 at 09 55 22" src="https://user-images.githubusercontent.com/81319331/123068027-6f2dd180-d409-11eb-9996-6103b17ab9ea.png">
   




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org