Skip to content

Commit

Permalink
Merge pull request stakwork#2383 from stakwork/feature/node-without-text
Browse files Browse the repository at this point in the history
feat: added support for node without text
  • Loading branch information
Rassl authored Oct 25, 2024
2 parents 7f87e56 + 7a7ae80 commit 9a2c852
Showing 1 changed file with 18 additions and 14 deletions.
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

0 comments on commit 9a2c852

Please sign in to comment.