jathanasiou commented on a change in pull request #255:
URL: https://github.com/apache/brooklyn-ui/pull/255#discussion_r674620376
##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -771,50 +774,37 @@ export function D3Blueprint(container, options) {
return node;
}
+ /**
+ * Draws new relationships as arcs and labels. Updates existing ones.
+ */
function drawRelationships() {
+
showRelationships();
- let relationData = _relationGroup.selectAll('.relation')
- .data(_d3DataHolder.visible.relationships, (d)=>(d.source._id +
'_related_to_' + d.target._id));
+ const getPathId = (d) => (d.source._id + '-' + d.target._id);
+ const getRelationId = (d) => (getPathId(d) + '-' + d.pathSelector);
+
+ // ====== RELATIONSHIP ARCS ===========
- let relationDataEntered = relationData.enter();
+ let arcsData =
Object.values(_d3DataHolder.visible.relationships.reduce((accumulator, d) => {
Review comment:
Due to only pulling `Object.values`, in the end `arcsData` will be an
array of all the `{source,target,pathSelector}` objects it seems. If so, it
might be easier to just do
```
const arcsData = _d3DataHolder.visible.relationships;
// or in case it's important to retain specific properties only
const arcsData = _d3DataHolder.visible.relationships
.map(({ source, target, pathSelector }) => ({ source, target, pathSelector
}));
```
##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -771,50 +774,37 @@ export function D3Blueprint(container, options) {
return node;
}
+ /**
+ * Draws new relationships as arcs and labels. Updates existing ones.
+ */
function drawRelationships() {
+
showRelationships();
- let relationData = _relationGroup.selectAll('.relation')
- .data(_d3DataHolder.visible.relationships, (d)=>(d.source._id +
'_related_to_' + d.target._id));
+ const getPathId = (d) => (d.source._id + '-' + d.target._id);
+ const getRelationId = (d) => (getPathId(d) + '-' + d.pathSelector);
+
+ // ====== RELATIONSHIP ARCS ===========
- let relationDataEntered = relationData.enter();
+ let arcsData =
Object.values(_d3DataHolder.visible.relationships.reduce((accumulator, d) => {
+ accumulator[getRelationId(d)] = {
Review comment:
isn't this equivalent to `accumulator[getRelationId(d)] = d;` since they
have the same prop names?
##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -771,50 +774,37 @@ export function D3Blueprint(container, options) {
return node;
}
+ /**
+ * Draws new relationships as arcs and labels. Updates existing ones.
+ */
function drawRelationships() {
+
showRelationships();
- let relationData = _relationGroup.selectAll('.relation')
- .data(_d3DataHolder.visible.relationships, (d)=>(d.source._id +
'_related_to_' + d.target._id));
+ const getPathId = (d) => (d.source._id + '-' + d.target._id);
Review comment:
Both arrow funcs _might_ be more readable like
```
const getPathId = ({ source, target }) => `${source._id}-${target._id}`;
```
##########
File path: ui-modules/blueprint-composer/app/components/util/d3-blueprint.js
##########
@@ -771,50 +774,37 @@ export function D3Blueprint(container, options) {
return node;
}
+ /**
+ * Draws new relationships as arcs and labels. Updates existing ones.
+ */
function drawRelationships() {
+
showRelationships();
- let relationData = _relationGroup.selectAll('.relation')
- .data(_d3DataHolder.visible.relationships, (d)=>(d.source._id +
'_related_to_' + d.target._id));
+ const getPathId = (d) => (d.source._id + '-' + d.target._id);
+ const getRelationId = (d) => (getPathId(d) + '-' + d.pathSelector);
+
+ // ====== RELATIONSHIP ARCS ===========
- let relationDataEntered = relationData.enter();
+ let arcsData =
Object.values(_d3DataHolder.visible.relationships.reduce((accumulator, d) => {
+ accumulator[getRelationId(d)] = {
+ source: d.source,
+ target: d.target,
+ pathSelector: d.pathSelector
+ };
+ return accumulator;
+ }, {}));
- // Draw the relationship path
- relationDataEntered.insert('path')
+ let relationArcs = _relationArcs.selectAll('.relation').data(arcsData,
(d) => getRelationId(d));
+
+ relationArcs.enter().insert('path')
Review comment:
Are we inserting a list of `<path>` elements to the DOM here?
If so, it would probably be more performant (and angular-like) to have the
template html iterate something like `$scope.relationships` to generate them.
A `$watch` statement could keep that scope variable updated whenever any of
the dependant properties for the `drawRelationships` logic changes.
--
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]