-
Notifications
You must be signed in to change notification settings - Fork 350
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
Conversation
PF4 preview: https://patternfly-react-pr-4690.surge.sh |
e3f653e
to
92c02ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jeff-phillips-18 i'll have a look at this today or tomorrow |
packages/react-topology/src/types.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
if (!node.element.isPositioned()) { | ||
node.setPosition(cx, cy); | ||
} else { | ||
node.setFixed(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
} |
try { | ||
this.getController().fireEvent(NODE_POSITIONED_EVENT, { node: this }); | ||
// eslint-disable-next-line no-empty | ||
} catch (e) {} |
There was a problem hiding this comment.
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.
try { | ||
this.getController() | ||
.getElements() | ||
.filter(e => isNode(e)) | ||
.forEach(n => { | ||
(n as Node).clearPosition(); | ||
}); | ||
// eslint-disable-next-line no-empty | ||
} catch (e) {} |
There was a problem hiding this comment.
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.
0a634a6
92c02ca
to
0a634a6
Compare
source: this.getSource() ? this.getSource().getId() : '', | ||
target: this.getTarget() ? this.getTarget().getId() : '', |
There was a problem hiding this comment.
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:
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, |
x: this.getPosition().x, | ||
y: this.getPosition().y, |
There was a problem hiding this comment.
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
packages/react-topology/src/types.ts
Outdated
@@ -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; |
There was a problem hiding this comment.
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()
packages/react-topology/src/types.ts
Outdated
@@ -9,6 +9,7 @@ export type PointTuple = [number, number]; | |||
|
|||
export interface Layout { | |||
layout(): void; | |||
stopLayout(): void; |
There was a problem hiding this comment.
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.
// If not merging, clear out the old elements | ||
if (!merge) { | ||
this.elements = {}; | ||
} |
There was a problem hiding this comment.
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.
e2aee28
to
4d8da99
Compare
4d8da99
to
278c546
Compare
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
lgtm |
@redallen @ddonahue007 Please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Your changes have been released in:
Thanks for your contribution! 🎉 |
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