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

fix: reduce the graph chaos #3548

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions frontend/console/src/features/graph/GraphPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,20 @@ export const GraphPane: React.FC<GraphPaneProps> = ({ onTapped }) => {
})

if (hasNewNodesWithoutPositions) {
const layoutOptions: FcoseLayoutOptions = {
const layoutOptions = {
name: 'fcose',
animate: false,
quality: 'default',
nodeSeparation: 75,
idealEdgeLength: 75,
nodeSeparation: 50,
idealEdgeLength: 50,
nodeRepulsion: 4500,
padding: 30,
padding: 20,
randomize: false,
// Make the layout more deterministic
tile: true,
tilingPaddingVertical: 20,
tilingPaddingHorizontal: 20,
}
} as FcoseLayoutOptions

const layout = cy.layout(layoutOptions)
layout.run()
Expand Down
61 changes: 49 additions & 12 deletions frontend/console/src/features/graph/graph-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const createModuleEdge = (sourceModule: string, targetModule: string) => ({
},
})

const createVerbEdges = (modules: Module[]) => {
const createEdges = (modules: Module[]) => {
const edges: EdgeDefinition[] = []
const moduleConnections = new Set<string>() // Track unique module connections

Expand All @@ -125,33 +125,70 @@ const createVerbEdges = (modules: Module[]) => {
for (const verb of module.verbs || []) {
// For each reference in the verb
for (const ref of verb.references || []) {
// Create verb-to-verb edge
// Only create verb-to-verb child edges
edges.push(createChildEdge(ref.module, ref.name, module.name, verb.verb?.name || ''))

// Track module-to-module connection
// Sort module names to ensure consistent edge IDs
// Track module-to-module connection for all reference types
const [sourceModule, targetModule] = [module.name, ref.module].sort()
moduleConnections.add(`${sourceModule}-${targetModule}`)
}
}

for (const config of module.configs || []) {
// For each reference in the verb
for (const ref of config.references || []) {
// Only create verb-to-verb child edges
edges.push(createChildEdge(ref.module, ref.name, module.name, config.config?.name || ''))

// Track module-to-module connection
// Sort module names to ensure consistent edge IDs
// Track module-to-module connection for all reference types
const [sourceModule, targetModule] = [module.name, ref.module].sort()
moduleConnections.add(`${sourceModule}-${targetModule}`)
}
}

for (const secret of module.secrets || []) {
// For each reference in the verb
for (const ref of secret.references || []) {
// Only create verb-to-verb child edges
edges.push(createChildEdge(ref.module, ref.name, module.name, secret.secret?.name || ''))

// Track module-to-module connection for all reference types
const [sourceModule, targetModule] = [module.name, ref.module].sort()
moduleConnections.add(`${sourceModule}-${targetModule}`)
}
}

for (const data of module.data || []) {
for (const ref of data.references || []) {
edges.push(createChildEdge(ref.module, ref.name, module.name, data.data?.name || ''))
for (const database of module.databases || []) {
// For each reference in the verb
for (const ref of database.references || []) {
// Only create verb-to-verb child edges
edges.push(createChildEdge(ref.module, ref.name, module.name, database.database?.name || ''))

// Track module-to-module connection for all reference types
const [sourceModule, targetModule] = [module.name, ref.module].sort()
moduleConnections.add(`${sourceModule}-${targetModule}`)
}
}

for (const subscription of module.subscriptions || []) {
// For each reference in the verb
for (const ref of subscription.references || []) {
// Only create verb-to-verb child edges
edges.push(createChildEdge(ref.module, ref.name, module.name, subscription.subscription?.name || ''))

// Track module-to-module connection for all reference types
const [sourceModule, targetModule] = [module.name, ref.module].sort()
moduleConnections.add(`${sourceModule}-${targetModule}`)
}
}

for (const topic of module.topics || []) {
// For each reference in the verb
for (const ref of topic.references || []) {
// Only create verb-to-verb child edges
edges.push(createChildEdge(ref.module, ref.name, module.name, topic.topic?.name || ''))

// Track module-to-module connection
// Sort module names to ensure consistent edge IDs
// Track module-to-module connection for all reference types
const [sourceModule, targetModule] = [module.name, ref.module].sort()
moduleConnections.add(`${sourceModule}-${targetModule}`)
}
Expand All @@ -177,7 +214,7 @@ export const getGraphData = (
return [
...modules.modules.map((module) => createParentNode(module, nodePositions)),
...modules.modules.flatMap((module) => createModuleChildren(module, nodePositions, isDarkMode)),
...createVerbEdges(modules.modules),
...createEdges(modules.modules),
]
}

Expand Down
Loading