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: update selected node ui #2595

Merged
merged 1 commit into from
Jan 5, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { Mesh, Vector3 } from 'three'
import { Flex } from '~/components/common/Flex'
import { Icons } from '~/components/Icons'
import CloseIcon from '~/components/Icons/CloseIcon'
import EditIcon from '~/components/Icons/EditIcon'
import NodesIcon from '~/components/Icons/NodesIcon'
import { useGraphStore } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { useSchemaStore } from '~/stores/useSchemaStore'
import { useUserStore } from '~/stores/useUserStore'
import { colors } from '~/utils'
import { truncateText } from '~/utils/truncateText'
import { PathNode } from '..'
import EditIcon from '~/components/Icons/EditIcon'
import { useUserStore } from '~/stores/useUserStore'
import { useModal } from '~/stores/useModalStore'

type TagProps = {
rounded: boolean
Expand Down Expand Up @@ -54,6 +54,8 @@ export const Node = ({ onClick, node, selected, rounded = true, x, y, z, id }: P

const title = node?.properties ? node?.properties[keyProperty] : ''
const titleShortened = title ? truncateText(title, 30) : ''
const description = keyProperty !== 'description' ? node.properties?.description : ''
const descriptionShortened = description ? truncateText(description, 60) : ''

return (
<mesh ref={nodeRef}>
Expand All @@ -70,13 +72,34 @@ export const Node = ({ onClick, node, selected, rounded = true, x, y, z, id }: P
<CloseButton onClick={() => setSelectedNode(null)}>
<CloseIcon />
</CloseButton>
<div>{Icon ? <Icon /> : <NodesIcon />}</div>
<Text>{titleShortened}</Text>
<div>
<Avatar
align="center"
height={!descriptionShortened ? 100 : 48}
justify="center"
radius="6px"
src={node?.properties?.image_url || ''}
width={!descriptionShortened ? 200 : 72}
>
{!node?.properties?.image_url ? <span>{Icon ? <Icon /> : <NodesIcon />}</span> : null}
</Avatar>
</div>
<Flex align="flex-start">
<Text className="selected__title">{titleShortened}</Text>
{descriptionShortened ? <Text>{descriptionShortened}</Text> : null}
</Flex>
</Selected>
) : (
<>
<Tag onClick={() => onClick(id)} rounded={rounded}>
<Avatar align="center" justify="center" src={node?.properties?.image_url || ''}>
<Avatar
align="center"
height={32}
justify="center"
radius="50%"
src={node?.properties?.image_url || ''}
width={32}
>
{!node?.properties?.image_url ? <span>{Icon ? <Icon /> : <NodesIcon />}</span> : null}
</Avatar>
</Tag>
Expand All @@ -97,9 +120,7 @@ const Wrapper = styled(Flex)`
const Text = styled(Flex)`
color: ${colors.white};
margin-left: 16px;
font-weight: 700;
width: 100px;
font-size: 16px;
`

const Tag = styled(Flex)<TagProps>`
Expand All @@ -116,7 +137,7 @@ const Tag = styled(Flex)<TagProps>`
align-items: center;
justify-content: center;
font-family: Barlow;
font-size: 24px;
font-size: 12px;
font-style: normal;
font-weight: 700;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
Expand All @@ -131,8 +152,23 @@ const Selected = styled(Tag)`
height: 100px;
flex-direction: row;
justify-content: center;
align-items: center;
align-items: flex-start;
position: relative;
font-family: Barlow;
font-weight: 700;
text-align: left;
padding: 12px;

.selected__title {
position: absolute;
bottom: -24px;
font-size: 20px;
left: 50%;
top: 100%;
transform: translateX(-50%) translateY(8px);
margin-left: 0;
width: auto;
}
`

const IconButton = styled(Flex)`
Expand Down Expand Up @@ -175,14 +211,18 @@ const CloseButton = styled(IconButton)`

type AvatarProps = {
src: string
radius: string
width: number
height: number
}

const Avatar = styled(Flex)<AvatarProps>`
background-image: ${({ src }) => `url(${src})`};
background-size: cover;
background-position: center;
background-repeat: no-repeat;
width: 32px;
height: 32px;
border-radius: 50%;
width: ${({ width }) => `${width}px`};
height: ${({ height }) => `${height}px`};
border-radius: ${({ radius }) => `${radius}`};
font-size: 20px;
`
28 changes: 8 additions & 20 deletions src/components/Universe/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,6 @@ export const Graph = () => {
})

simulation.on('end', () => {
const nodesVector = simulation.nodes().map((i: NodeExtended) => {
// eslint-disable-next-line no-param-reassign
i.fx = i.x
// eslint-disable-next-line no-param-reassign
i.fy = i.y
// eslint-disable-next-line no-param-reassign
i.fz = i.z

return new Vector3(i.x, i.y, i.z)
})

if (groupRef.current) {
const gr = groupRef.current.getObjectByName('simulation-3d-group__nodes') as Group
const grPoints = groupRef.current.getObjectByName('simulation-3d-group__node-points') as Group
Expand Down Expand Up @@ -253,19 +242,18 @@ export const Graph = () => {
}
})
}
}

const boundingBox = new Box3().setFromPoints(nodesVector)

const boundingSphere = new Sphere()
const box = new Box3().setFromObject(gr)

boundingBox.getBoundingSphere(boundingSphere)
// Compute the center and radius of the bounding sphere
const sphere = new Sphere()

const sphereRadius = Math.min(5000, boundingSphere.radius)
box.getBoundingSphere(sphere)

console.log(sphereRadius)

setGraphRadius(sphereRadius)
if (sphere.radius) {
setGraphRadius(sphere.radius)
}
}
})
}, [dataInitial, simulation, setGraphRadius, normalizedSchemasByType])

Expand Down
Loading