Skip to content

Commit

Permalink
Merge pull request #2509 from stakwork/feat/graph-links
Browse files Browse the repository at this point in the history
feat: added link
  • Loading branch information
Rassl authored Dec 6, 2024
2 parents 2bf9bd5 + 21085c8 commit ab7c123
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 79 deletions.
4 changes: 2 additions & 2 deletions src/components/App/ActionsToolbar/GraphViewControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export const GraphViewControl = () => {
setGraphStyle(val)
}

return (
return false ? (
<Wrapper direction="column">
{graphStyles.map((i) => (
<Flex key={i} className={clsx('icon', { active: graphStyle === i })} onClick={() => changeGraphType(i)}>
{IconsMapper[i]}
</Flex>
))}
</Wrapper>
)
) : null
}

const Wrapper = styled(Flex).attrs({
Expand Down
28 changes: 20 additions & 8 deletions src/components/Universe/Graph/Connections/LineComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Line } from '@react-three/drei'
import { Billboard, Line, Text } from '@react-three/drei'
import gsap from 'gsap'
import { memo, useEffect, useRef } from 'react'
import { Vector3 } from 'three'
Expand All @@ -9,10 +9,11 @@ import { LINE_WIDTH } from '../../constants'
type LineComponentProps = {
isSelected: boolean
position: LinkPosition
label: string
}

// eslint-disable-next-line no-underscore-dangle
const _LineComponent = ({ isSelected, position }: LineComponentProps) => {
const _LineComponent = ({ isSelected, position, label }: LineComponentProps) => {
const lineRef = useRef<Line2 | null>(null)

useEffect(() => {
Expand All @@ -31,12 +32,23 @@ const _LineComponent = ({ isSelected, position }: LineComponentProps) => {
}, [isSelected, lineRef])

return (
<Line
ref={lineRef}
isLine2
opacity={0.5}
points={[new Vector3(position.sx, position.sy, position.sz), new Vector3(position.tx, position.ty, position.tz)]}
/>
<group>
<Line
ref={lineRef}
isLine2
name="line"
opacity={0.5}
points={[
new Vector3(position.sx, position.sy, position.sz),
new Vector3(position.tx, position.ty, position.tz),
]}
/>
<Billboard>
<Text anchorX="center" anchorY="middle" color="white" fontSize={10}>
{label}
</Text>
</Billboard>
</group>
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Universe/Graph/Connections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Connections = memo(({ linksPosition }: Props) => {
tz: 0,
}

return <LineComponent key={l.ref_id} isSelected={isSelected} position={position} />
return <LineComponent key={l.ref_id} isSelected={isSelected} label={l.edge_type} position={position} />
})}
</group>
)
Expand Down
4 changes: 3 additions & 1 deletion src/components/Universe/Graph/Cubes/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ export const TextNode = memo(({ node, hide, ignoreDistance }: Props) => {
<meshBasicMaterial color={color} opacity={0.5} transparent />
</mesh>

{node.properties?.image_url && ['Person', 'Episode', 'Guest', 'Host'].includes(node.node_type) && texture ? (
{node.properties?.image_url &&
['Person', 'Episode', 'Guest', 'Host', 'Show'].includes(node.node_type) &&
texture ? (
<Plane args={[10 * 2, 10 * 2]} scale={2}>
<shaderMaterial
fragmentShader={`
Expand Down
66 changes: 43 additions & 23 deletions src/components/Universe/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,55 @@ export const Graph = () => {
if (grConnections) {
linksPositionRef.current.clear()

grConnections.children.forEach((r, i) => {
const link = dataInitial?.links[i]
const Line = r as Line2
grConnections.children.forEach((g, i) => {
const r = g.children[0] // Assuming Line is the first child
const text = g.children[1] // Assuming Text is the second child

if (link) {
const sourceNode = simulation.nodes().find((n: NodeExtended) => n.ref_id === link.source)
const targetNode = simulation.nodes().find((n: NodeExtended) => n.ref_id === link.target)
if (r instanceof Line2) {
// Ensure you have both Line and Text
const Line = r as Line2
const link = dataInitial?.links[i]

const { x: sx, y: sy, z: sz } = sourceNode
const { x: tx, y: ty, z: tz } = targetNode
if (link) {
const sourceNode = simulation.nodes().find((n: NodeExtended) => n.ref_id === link.source)
const targetNode = simulation.nodes().find((n: NodeExtended) => n.ref_id === link.target)

linksPositionRef.current.set(link.ref_id, {
sx,
sy,
sz,
tx,
ty,
tz,
})
if (!sourceNode || !targetNode) {
console.warn(`Missing source or target node for link: ${link?.ref_id}`)

const lineColor = normalizedSchemasByType[sourceNode.node_type]?.primary_color || 'white'
return
}

Line.geometry.setPositions([sx, sy, sz, tx, ty, tz])
const { x: sx, y: sy, z: sz } = sourceNode
const { x: tx, y: ty, z: tz } = targetNode

const { material } = Line
// Set positions for the link
linksPositionRef.current.set(link.ref_id, {
sx,
sy,
sz,
tx,
ty,
tz,
})

material.color = new Color(lineColor)
material.transparent = true
material.opacity = 0.3
// Calculate midpoint for the text position
const midPoint = new Vector3((sx + tx) / 2, (sy + ty) / 2, (sz + tz) / 2)

// Set text position and rotation
text.position.set(midPoint.x, midPoint.y, midPoint.z)

// Set line color and properties
const lineColor = normalizedSchemasByType[sourceNode.node_type]?.primary_color || 'white'

Line.geometry.setPositions([sx, sy, sz, tx, ty, tz])

const { material } = Line

material.color = new Color(lineColor)
material.transparent = true
material.opacity = 0.3
}
}
})
}
Expand All @@ -166,7 +186,7 @@ export const Graph = () => {

const sphereRadius = boundingSphere.radius

setGraphRadius(sphereRadius)
setGraphRadius(sphereRadius * 1.5)

cameraSettled.current = false
})
Expand Down
1 change: 1 addition & 0 deletions src/components/Universe/Overlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const OverlayWrap = styled('div')(({ theme }) => ({
height: '100%',
width: '100%',
padding: '16px',
paddingRight: '0',
overflow: 'hidden',
[theme.breakpoints.down('sm')]: {
top: 50,
Expand Down
6 changes: 4 additions & 2 deletions src/components/common/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import styled from 'styled-components'

type Props = {
size?: number
height?: number
width?: number
src: string
type: string
rounded?: boolean
Expand Down Expand Up @@ -30,7 +32,7 @@ export const Avatar = styled.div<Props>`
background-size: cover;
background-position: center;
background-repeat: no-repeat;
width: ${({ size = 45 }) => size}px;
height: ${({ size = 45 }) => size}px;
width: ${({ size = 45, width }) => width || size}px;
height: ${({ size = 45, height }) => height || size}px;
border-radius: ${({ rounded }) => (rounded ? '50%' : '2px')};
`
4 changes: 2 additions & 2 deletions src/components/common/GraphViewControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export const GraphViewControl = () => {
setGraphStyle(val)
}

return (
return false ? (
<Wrapper direction="column">
{graphStyles.map((i) => (
<Flex key={i} className={clsx('icon', { active: graphStyle === i })} onClick={() => changeGraphType(i)}>
{IconsMapper[i]}
</Flex>
))}
</Wrapper>
)
) : null
}

const Wrapper = styled(Flex).attrs({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { NodeExtended } from '~/types'
import { colors } from '~/utils'
import { Viewer } from './Viewer'

export const Transcript = () => {
type Props = {
name: string
}

export const Transcript = ({ name }: Props) => {
const { selectedEpisodeId } = useMindsetStore((s) => s)
const { playerRef } = usePlayerStore((s) => s)
const [currentTime, setCurrentTime] = useState(0)
Expand Down Expand Up @@ -47,7 +51,7 @@ export const Transcript = () => {

return (
<Wrapper>
<Flex className="heading">Transcript</Flex>
<Flex className="heading">{name}</Flex>
{clips.map((clip) => {
const timestamp: string | undefined = clip?.properties?.timestamp

Expand Down
29 changes: 3 additions & 26 deletions src/components/mindset/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import styled from 'styled-components'
import { MENU_WIDTH } from '~/components/App/SideBar'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { MediaPlayer } from '~/components/mindset/components/MediaPlayer'
import { useMindsetStore } from '~/stores/useMindsetStore'
import { Transcript } from './Transcript'
Expand All @@ -11,20 +10,16 @@ export const SideBar = () => {

return (
<Wrapper align="stretch" basis="100%" grow={1} shrink={1}>
<MediaWrapper>
{selectedEpisode?.name && <EpisodeTitle>{selectedEpisode?.name}</EpisodeTitle>}
{selectedEpisode?.properties?.text && <Summary>{selectedEpisode?.properties?.text}</Summary>}
{selectedEpisodeLink && <MediaPlayer mediaUrl={selectedEpisodeLink} />}
</MediaWrapper>
<Transcript />
<MediaWrapper>{selectedEpisodeLink && <MediaPlayer mediaUrl={selectedEpisodeLink} />}</MediaWrapper>
<Transcript name={selectedEpisode?.name || ''} />
</Wrapper>
)
}

const Wrapper = styled(Flex)(({ theme }) => ({
position: 'relative',
display: 'flex',
padding: '33px 20px 20px 20px',
padding: '0 20px 20px 20px',
background: 'transparent',
width: '100%',

Expand All @@ -33,24 +28,6 @@ const Wrapper = styled(Flex)(({ theme }) => ({
},
}))

const Summary = styled(Text)`
font-size: 20px;
font-weight: Bold;
line-height: 24.2px;
overflow-wrap: break-word;
white-space: normal;
word-break: break-word;
margin-right: 10px;
font-weight: 500;
`

const EpisodeTitle = styled(Text)`
font-size: 14px;
font-weight: 700;
line-height: 16.94px;
margin-bottom: 12px;
`

const MediaWrapper = styled(Flex)(({ theme }) => ({
width: '100%',
margin: '0 auto 16px',
Expand Down
9 changes: 2 additions & 7 deletions src/components/mindset/components/VideoCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components'
import { Avatar } from '~/components/common/Avatar'
import { Flex } from '~/components/common/Flex'
import { colors } from '~/utils/colors'

Expand All @@ -16,7 +17,7 @@ export const VideoCard = ({ imageUrl, title, subtitle, onClick }: VideoCardProps
return (
<CardWrapper onClick={onClick}>
<ImageWrapper>
<CardImage alt={title} src={imageUrl} />
<Avatar height={140} src={imageUrl} type="Episode" width={170} />
</ImageWrapper>
<TextWrapper>
<CardTitle>{truncatedTitle}</CardTitle>
Expand Down Expand Up @@ -56,12 +57,6 @@ const ImageWrapper = styled.div`
align-items: center;
`

const CardImage = styled.img`
width: 100%;
height: 100%;
object-fit: cover;
`

const TextWrapper = styled(Flex)`
flex-direction: column;
justify-content: flex-start;
Expand Down
2 changes: 0 additions & 2 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const deduplicateByRefId = (items: Array<NodeExtended | Link>) => {

export type GraphStyle = 'sphere' | 'force' | 'split' | 'earth'

export const graphStyles: GraphStyle[] = ['sphere', 'force', 'split', 'earth']

export type FetchNodeParams = {
word?: string
skip_cache?: string
Expand Down
4 changes: 2 additions & 2 deletions src/stores/useGraphStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const defaultData: Omit<
disableCameraRotation: false,
scrollEventsDisabled: false,
graphRadius: 1500, // calculated from initial load
graphStyle: (localStorage.getItem('graphStyle') as GraphStyle) || 'sphere',
graphStyle: 'sphere',
hoveredNode: null,
selectedNode: null,
activeEdge: null,
Expand All @@ -144,7 +144,7 @@ export const useGraphStore = create<GraphStore>()((set, get) => ({
setDisableCameraRotation: (rotation) => set({ disableCameraRotation: rotation }),
setIsHovering: (isHovering) => set({ isHovering }),
setGraphRadius: (graphRadius) => set({ graphRadius }),
setGraphStyle: (graphStyle) => set({ graphStyle }),
setGraphStyle: (graphStyle) => set({ graphStyle: 'sphere' || graphStyle }),
setHoveredNode: (hoveredNode) => {
set({ hoveredNode })
},
Expand Down
2 changes: 1 addition & 1 deletion src/stores/useSchemaStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const useSchemaStore = create<SchemasStore>()(
getNodeKeysByType: (type: string) => {
const schema = get().normalizedSchemasByType[type]

return schema ? schema.node_key : undefined
return schema ? schema.index || schema.node_key : undefined
},
getSchemaByType: (type: string) => get().normalizedSchemasByType[type],
})),
Expand Down

0 comments on commit ab7c123

Please sign in to comment.