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: added support for node without text #2383

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
32 changes: 18 additions & 14 deletions src/components/Universe/Graph/Cubes/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function splitStringIntoThreeParts(text: string): string {
}

export const TextNode = memo(({ node, hide, isHovered }: Props) => {
const ref = useRef<Mesh | null>(null)
const svgRef = useRef<Mesh | null>(null)
const ringRef = useRef<Mesh | null>(null)
const selectedNode = useSelectedNode()
Expand All @@ -82,7 +81,7 @@ export const TextNode = memo(({ node, hide, isHovered }: Props) => {

useFrame(({ camera }) => {
const checkDistance = () => {
const nodePosition = nodePositionRef.current.setFromMatrixPosition(ref.current!.matrixWorld)
const nodePosition = nodePositionRef.current.setFromMatrixPosition(ringRef.current!.matrixWorld)

if (ringRef.current) {
ringRef.current.visible = nodePosition.distanceTo(camera.position) < 2500
Expand All @@ -97,6 +96,10 @@ export const TextNode = memo(({ node, hide, isHovered }: Props) => {
const nodeTypes = useNodeTypes()

const textScale = useMemo(() => {
if (!node.name) {
return 0
}

let scale = (node.edge_count || 1) * 20

if (showSelectionGraph && isSelected) {
Expand Down Expand Up @@ -153,18 +156,19 @@ export const TextNode = memo(({ node, hide, isHovered }: Props) => {
userData={node}
/>

<Text
ref={ref}
color={color}
fillOpacity={1 || fillOpacity}
name="text"
position={[0, -40, 0]}
scale={textScale}
userData={node}
{...fontProps}
>
{splitStringIntoThreeParts(sanitizedNodeName)}
</Text>
{node.name && (
<Text
color={color}
fillOpacity={1 || fillOpacity}
name="text"
position={[0, -40, 0]}
scale={textScale}
userData={node}
{...fontProps}
>
{splitStringIntoThreeParts(sanitizedNodeName)}
</Text>
)}
</mesh>
</Billboard>
)
Expand Down
Loading