Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(topology): Enable saving current topology graph model #4690

Merged
merged 1 commit into from
Aug 27, 2020

Conversation

jeff-phillips-18
Copy link
Member

What:
This PR is aimed at allowing adopters to track the current layout of nodes so that it can be saved and restored.

Provides API for toModel for the current Controller/GraphElements.
Keeps track of nodes that have had their position set, do not reset positions on layout.
Adds events on individual node moves, and overall event for all node moves (debouncing individual node moves)

/cc @christianvogt

@patternfly-build
Copy link
Contributor

patternfly-build commented Aug 13, 2020

redallen
redallen previously approved these changes Aug 18, 2020
ddonahue007
ddonahue007 previously approved these changes Aug 18, 2020
Copy link
Member

@ddonahue007 ddonahue007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@christianvogt
Copy link
Contributor

@jeff-phillips-18 i'll have a look at this today or tomorrow

@@ -126,6 +127,7 @@ export interface Node<E extends NodeModel = NodeModel, D = any> extends GraphEle
setBounds(bounds: Rect): void;
getPosition(): Point;
setPosition(location: Point): void;
clearPosition(): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove clearPosition.
All other comments are related to trying to remove this function.

@@ -439,7 +439,7 @@ class BaseLayout implements Layout {
this.edges = this.getLinks(this.graph.getEdges());

// initialize new node positions
this.initializeNodePositions(newNodes, this.graph, initialRun);
this.initializeNodePositions(this.nodes, this.graph);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep initialRun as a param to force layout on the nodes.

Comment on lines 373 to 378
if (!node.element.isPositioned()) {
node.setPosition(cx, cy);
} else {
node.setFixed(true);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!node.element.isPositioned()) {
node.setPosition(cx, cy);
} else {
node.setFixed(true);
}
if (force || !node.element.isPositioned()) {
node.setPosition(cx, cy);
} else if (!force) {
node.setFixed(true);
}

Comment on lines +149 to +152
try {
this.getController().fireEvent(NODE_POSITIONED_EVENT, { node: this });
// eslint-disable-next-line no-empty
} catch (e) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit concerned that this can result in a lot of event notifications during the layout which may impact performance.

I wonder if we should consider a single event notification that's debounced that can announce model changed. This isn't really ideal either.

Comment on lines 148 to 156
try {
this.getController()
.getElements()
.filter(e => isNode(e))
.forEach(n => {
(n as Node).clearPosition();
});
// eslint-disable-next-line no-empty
} catch (e) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this if we can remove clearPosition altogether.

Comment on lines 167 to 168
source: this.getSource() ? this.getSource().getId() : '',
target: this.getTarget() ? this.getTarget().getId() : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have these as undefined:

Suggested change
source: this.getSource() ? this.getSource().getId() : '',
target: this.getTarget() ? this.getTarget().getId() : '',
source: this.getSource() ? this.getSource().getId() : undefined,
target: this.getTarget() ? this.getTarget().getId() : undefined,

Comment on lines 305 to 306
x: this.getPosition().x,
y: this.getPosition().y,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only include the position if this.positioned === true

@@ -171,6 +173,7 @@ export interface Graph<E extends GraphModel = GraphModel, D = any> extends Graph
getLayout(): string | undefined;
setLayout(type: string | undefined): void;
layout(): void;
stopLayout(): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to not add this function to the graph api.
They can always do graph.getLayout()?.stopLayout()

@@ -9,6 +9,7 @@ export type PointTuple = [number, number];

export interface Layout {
layout(): void;
stopLayout(): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call it stop(): void ? Since this is a function of the layout itself.

Comment on lines 51 to 54
// If not merging, clear out the old elements
if (!merge) {
this.elements = {};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to go through the routine of destroying the element for the sake of consistency.

@jeff-phillips-18 jeff-phillips-18 force-pushed the serialize-layout branch 4 times, most recently from e2aee28 to 4d8da99 Compare August 21, 2020 14:32
@codecov-commenter
Copy link

Codecov Report

Merging #4690 into master will decrease coverage by 0.08%.
The diff coverage is 28.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4690      +/-   ##
==========================================
- Coverage   52.52%   52.44%   -0.09%     
==========================================
  Files         514      514              
  Lines        8974     9006      +32     
  Branches     3266     3277      +11     
==========================================
+ Hits         4714     4723       +9     
- Misses       3673     3693      +20     
- Partials      587      590       +3     
Flag Coverage Δ
#patternfly4 52.44% <28.20%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/react-topology/src/elements/BaseEdge.ts 1.51% <0.00%> (-0.10%) ⬇️
...ackages/react-topology/src/elements/BaseElement.ts 26.41% <0.00%> (+1.41%) ⬆️
packages/react-topology/src/elements/BaseGraph.ts 86.44% <0.00%> (-2.26%) ⬇️
packages/react-topology/src/Visualization.ts 34.37% <27.77%> (-2.70%) ⬇️
packages/react-topology/src/elements/BaseNode.ts 32.53% <45.45%> (+1.50%) ⬆️
packages/react-topology/src/types.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1697af5...278c546. Read the comment docs.

@christianvogt
Copy link
Contributor

lgtm

@jeff-phillips-18
Copy link
Member Author

@redallen @ddonahue007 Please take another look.

Copy link
Contributor

@redallen redallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM!

Copy link
Member

@ddonahue007 ddonahue007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@redallen redallen merged commit 2c4b25c into patternfly:master Aug 27, 2020
@patternfly-build
Copy link
Contributor

Your changes have been released in:

  • @patternfly/react-docs@5.8.23
  • demo-app-ts@4.36.0
  • @patternfly/react-integration@4.36.0
  • @patternfly/react-topology@4.5.0

Thanks for your contribution! 🎉

@jeff-phillips-18 jeff-phillips-18 deleted the serialize-layout branch November 11, 2021 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants