-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2565 from stakwork/feature/selection-graph
feat: update selection view
- Loading branch information
Showing
14 changed files
with
483 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/components/Universe/Graph/Cubes/SelectionDataNodes/Connections/Connection/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Line, Text } from '@react-three/drei' | ||
import { memo, useRef } from 'react' | ||
import { Line2 } from 'three-stdlib' | ||
|
||
type LineComponentProps = { | ||
label: string | ||
sourceX: number | ||
sourceY: number | ||
sourceZ: number | ||
targetX: number | ||
targetY: number | ||
targetZ: number | ||
} | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
const _Connection = (props: LineComponentProps) => { | ||
const lineRef = useRef<Line2 | null>(null) | ||
|
||
const { label, sourceX, sourceY, sourceZ, targetX, targetY, targetZ } = props | ||
|
||
return ( | ||
<group> | ||
<Line | ||
ref={lineRef} | ||
color="blue" | ||
isLine2 | ||
lineWidth={2} | ||
name="line" | ||
points={[sourceX, sourceY, sourceZ, targetX, targetY, targetZ]} | ||
/> | ||
<mesh> | ||
<Text anchorX="center" anchorY="middle" color="white" fontSize={10}> | ||
{label} | ||
</Text> | ||
</mesh> | ||
</group> | ||
) | ||
} | ||
|
||
_Connection.displayName = 'Connection' | ||
|
||
export const Connection = memo(_Connection) |
43 changes: 43 additions & 0 deletions
43
src/components/Universe/Graph/Cubes/SelectionDataNodes/Connections/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { memo } from 'react' | ||
import { useGraphStore } from '~/stores/useGraphStore' | ||
import { Link } from '~/types' | ||
import { LinkPosition } from '../../..' | ||
import { Connection } from './Connection' | ||
|
||
type Props = { | ||
linksPosition: Map<string, LinkPosition> | ||
} | ||
|
||
export const Connections = memo(({ linksPosition }: Props) => { | ||
const { selectionGraphData } = useGraphStore((s) => s) | ||
|
||
return ( | ||
<group name="simulation-3d-group__connections"> | ||
{selectionGraphData?.links.map((l: Link) => { | ||
const position = linksPosition.get(l.ref_id) || { | ||
sx: 0, | ||
sy: 0, | ||
sz: 0, | ||
tx: 0, | ||
ty: 0, | ||
tz: 0, | ||
} | ||
|
||
return ( | ||
<Connection | ||
key={l.ref_id} | ||
label={l.edge_type} | ||
sourceX={position.sx} | ||
sourceY={position.sy} | ||
sourceZ={position.sz} | ||
targetX={position.tx} | ||
targetY={position.ty} | ||
targetZ={position.tz} | ||
/> | ||
) | ||
})} | ||
</group> | ||
) | ||
}) | ||
|
||
Connections.displayName = 'Connections' |
115 changes: 115 additions & 0 deletions
115
src/components/Universe/Graph/Cubes/SelectionDataNodes/Node/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import styled from 'styled-components' | ||
import { Flex } from '~/components/common/Flex' | ||
import { Icons } from '~/components/Icons' | ||
import CloseIcon from '~/components/Icons/CloseIcon' | ||
import NodesIcon from '~/components/Icons/NodesIcon' | ||
import { useGraphStore } from '~/stores/useGraphStore' | ||
import { useSchemaStore } from '~/stores/useSchemaStore' | ||
import { NodeExtended } from '~/types' | ||
import { colors } from '~/utils' | ||
import { truncateText } from '~/utils/truncateText' | ||
|
||
type TagProps = { | ||
rounded: boolean | ||
} | ||
|
||
type Props = { | ||
node: NodeExtended | ||
rounded?: boolean | ||
selected: boolean | ||
onClick: () => void | ||
} | ||
|
||
export const Node = ({ onClick, node, selected, rounded = true }: Props) => { | ||
const { normalizedSchemasByType, getNodeKeysByType } = useSchemaStore((s) => s) | ||
const setSelectedNode = useGraphStore((s) => s.setSelectedNode) | ||
|
||
const primaryIcon = normalizedSchemasByType[node.node_type]?.icon | ||
|
||
const Icon = primaryIcon ? Icons[primaryIcon] : null | ||
// const iconName = Icon ? primaryIcon : 'NodesIcon' | ||
const keyProperty = getNodeKeysByType(node.node_type) || '' | ||
|
||
const title = node?.properties ? node?.properties[keyProperty] : '' | ||
const titleShortened = title ? truncateText(title, 30) : '' | ||
|
||
return ( | ||
<Wrapper align="center" direction="row" justify="flex-start"> | ||
<> | ||
{selected ? ( | ||
<Selected rounded={false}> | ||
<IconButton onClick={() => setSelectedNode(null)}> | ||
<CloseIcon /> | ||
</IconButton> | ||
<div>{Icon ? <Icon /> : <NodesIcon />}</div> | ||
<Text>{titleShortened}</Text> | ||
</Selected> | ||
) : ( | ||
<> | ||
<Tag onClick={onClick} rounded={rounded}> | ||
<div>{Icon ? <Icon /> : <NodesIcon />}</div> | ||
</Tag> | ||
<Text>{titleShortened}</Text> | ||
</> | ||
)} | ||
</> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
const Wrapper = styled(Flex)`` | ||
|
||
const Text = styled(Flex)` | ||
color: ${colors.white}; | ||
margin-left: 16px; | ||
font-weight: 700; | ||
` | ||
|
||
const Tag = styled(Flex)<TagProps>` | ||
text-align: center; | ||
width: 48px; | ||
height: 48px; | ||
outline: 1px solid ${colors.white}; | ||
outline-offset: 0px; | ||
background: ${colors.BG1}; | ||
color: ${colors.white}; | ||
border-radius: ${(p: TagProps) => `${p.rounded ? '50%' : '6px'}`}; | ||
cursor: pointer; | ||
transition: font-size 0.4s, outline 0.4s; | ||
align-items: center; | ||
justify-content: center; | ||
font-family: Barlow; | ||
font-size: 24px; | ||
font-style: normal; | ||
font-weight: 700; | ||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); | ||
&:hover { | ||
outline-offset: 4px; | ||
} | ||
` | ||
|
||
const Selected = styled(Tag)` | ||
width: 300px; | ||
height: 150px; | ||
` | ||
|
||
const IconButton = styled(Flex)` | ||
position: absolute; | ||
top: -10px; | ||
right: -10px; | ||
width: 24px; | ||
height: 24px; | ||
border-radius: 40px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background: black; | ||
color: #ffffff; | ||
border-radius: 100%; | ||
font-size: 16px; | ||
cursor: pointer; | ||
transition: opacity 0.4s; | ||
box-shadow: 0px 2px 12px rgba(0, 0, 0, 0.5); | ||
` |
Oops, something went wrong.