This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from avivtur/fix-topology
Fix topology issues
- Loading branch information
Showing
9 changed files
with
158 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/views/states/topology/components/CustomGroup/CustomGroup.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.custom-group { | ||
.pf-topology__group__label > text { | ||
fill: var(--pf-topology__node__label__text--Fill); | ||
} | ||
|
||
.pf-topology__node__label__background { | ||
fill: var(--pf-topology__node__label__background--Fill); | ||
stroke: var(--pf-topology__node__background--Stroke); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/views/states/topology/components/CustomNode/CustomNode.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.custom-node { | ||
.pf-topology__node__background { | ||
stroke-width: 4px; | ||
} | ||
|
||
.pf-topology__node__label__background { | ||
stroke-width: 2px; | ||
} | ||
} | ||
|
||
.custom-node.pf-topology__node.pf-m-selected .pf-topology__node__background { | ||
stroke-width: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
export const NODE_DIAMETER = 35; | ||
export const NODE_DIAMETER = 70; | ||
export const ICON_SIZE = 30; | ||
|
||
export const CONNECTOR_TARGET_DROP = 'connector-target-drop'; | ||
export const GROUP = 'group'; | ||
export const ICON_SIZE = 15; | ||
|
||
export const TOPOLOGY_LOCAL_STORAGE_KEY = 'topologyNodePositions'; | ||
export const NODE_POSITIONING_EVENT = 'node-positioned'; | ||
export const GRAPH_POSITIONING_EVENT = 'graph-position-change'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Point, Visualization } from '@patternfly/react-topology'; | ||
|
||
import { TOPOLOGY_LOCAL_STORAGE_KEY } from './constants'; | ||
|
||
export const saveNodePositions = (visualization: Visualization) => { | ||
const graph = visualization.getGraph(); | ||
const nodePositions = {}; | ||
|
||
// Traverse all nodes and their children | ||
graph.getNodes().forEach((node) => { | ||
if (node.isGroup()) { | ||
// Save the group node position | ||
nodePositions[node.getId()] = node.getPosition(); | ||
|
||
// Save all child node positions | ||
node.getAllNodeChildren().forEach((childNode) => { | ||
nodePositions[childNode.getId()] = childNode.getPosition(); | ||
}); | ||
} else { | ||
nodePositions[node.getId()] = node.getPosition(); | ||
} | ||
}); | ||
|
||
localStorage.setItem(TOPOLOGY_LOCAL_STORAGE_KEY, JSON.stringify(nodePositions)); | ||
}; | ||
|
||
export const restoreNodePositions = (visualization: Visualization) => { | ||
const savedPositions = localStorage.getItem(TOPOLOGY_LOCAL_STORAGE_KEY); | ||
if (savedPositions) { | ||
const nodePositions = JSON.parse(savedPositions); | ||
const graph = visualization.getGraph(); | ||
|
||
// Traverse all nodes and their children | ||
graph.getNodes().forEach((node) => { | ||
if (nodePositions[node.getId()]) { | ||
node.setPosition(new Point(nodePositions[node.getId()].x, nodePositions[node.getId()].y)); | ||
} | ||
|
||
if (node.isGroup()) { | ||
node.getAllNodeChildren().forEach((childNode) => { | ||
if (nodePositions[childNode.getId()]) { | ||
childNode.setPosition( | ||
new Point(nodePositions[childNode.getId()].x, nodePositions[childNode.getId()].y), | ||
); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}; |
Oops, something went wrong.