Skip to content

Commit

Permalink
Merge pull request stakwork#2409 from stakwork/feature/normalize-scale
Browse files Browse the repository at this point in the history
feat: normalized node scales
  • Loading branch information
Rassl authored Oct 30, 2024
2 parents 7850207 + 0260b6a commit 383fc86
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Universe/Graph/Cubes/NodePoints/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const _NodePoints = () => {
const primaryColor = normalizedSchemasByType[node.node_type]?.primary_color
const color = primaryColor ?? (COLORS_MAP[nodeTypes.indexOf(node.node_type)] || colors.white)

return <Point key={node.ref_id} color={color} scale={node.edge_count || 1} />
return <Point key={node.ref_id} color={color} scale={node.scale || 1} />
})}
</Instances>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Universe/Graph/Cubes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const Cubes = memo(() => {
const hide = !!selectedNode && (relativeIds.includes(node.ref_id) || selectedNode.ref_id === node.ref_id)

return (
<mesh key={node.ref_id} name="wr2" scale={node.edge_count || 1} userData={node}>
<mesh key={node.ref_id} name="wr2" scale={node.scale || 1} userData={node}>
<boxGeometry args={[40, 40, 40]} />
<meshStandardMaterial opacity={0} transparent />
<TextNode
Expand Down
22 changes: 21 additions & 1 deletion src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,28 @@ export const useDataStore = create<DataStore>()(
count: currentNodes.filter((node) => filter === 'all' || node.node_type?.toLowerCase() === filter).length,
}))

const minScale = 1
const maxScale = 4

// Find min and max edgeCount values
const minEdgeCount = Math.min(...currentNodes.map((node) => node.edge_count))
const maxEdgeCount = Math.max(...currentNodes.map((node) => node.edge_count))

// Normalize and calculate scale for each node
const normalizedNodes = currentNodes.map((node) => {
const { edge_count: edgeCount } = node
const count = edgeCount || 1

const scale = Math.round(
((count - minEdgeCount) / (maxEdgeCount - minEdgeCount)) * (maxScale - minScale) + minScale,
)

// Return new object with calculated scale
return { ...node, scale }
})

set({
dataInitial: { nodes: currentNodes, links: currentLinks },
dataInitial: { nodes: normalizedNodes, links: currentLinks },
dataNew: { nodes: newNodes, links: newLinks },
isFetching: false,
isLoadingNew: false,
Expand Down

0 comments on commit 383fc86

Please sign in to comment.