-
Notifications
You must be signed in to change notification settings - Fork 3
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 #675 from XYOracleNetwork/feature/popper-work
module graph hover labels
- Loading branch information
Showing
26 changed files
with
220 additions
and
172 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
4 changes: 2 additions & 2 deletions
4
packages/sdk/packages/node-renderer/src/Cytoscape/lib/layout/ConcentricLayout.ts
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
56 changes: 0 additions & 56 deletions
56
packages/sdk/packages/node-renderer/src/components/ModuleGraphFlexBox.tsx
This file was deleted.
Oops, something went wrong.
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
13 changes: 0 additions & 13 deletions
13
packages/sdk/packages/node-renderer/src/components/WithCola.tsx
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
packages/sdk/packages/node-renderer/src/components/cytoscape-extensions/WithExtensions.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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './lib' | ||
export * from './ModuleCardParser' | ||
export * from './module' | ||
export * from './ProvidedNodeRenderer' | ||
export * from './RelationalGraph' |
4 changes: 2 additions & 2 deletions
4
packages/sdk/packages/node-renderer/src/components/lib/RelationalGraphProps.ts
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { FlexBoxProps } from '@xylabs/react-flexbox' | ||
import { CytoscapeOptions } from 'cytoscape' | ||
import { ReactNode } from 'react' | ||
import { PropsWithChildren, ReactNode } from 'react' | ||
|
||
export interface NodeRelationalGraphProps extends FlexBoxProps { | ||
export interface NodeRelationalGraphProps extends PropsWithChildren<FlexBoxProps> { | ||
actions?: ReactNode | ||
options?: CytoscapeOptions | ||
} |
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
36 changes: 36 additions & 0 deletions
36
packages/sdk/packages/node-renderer/src/components/module/graph/GraphFlexBox.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,36 @@ | ||
import { Button } from '@mui/material' | ||
import { FlexBoxProps } from '@xylabs/react-flexbox' | ||
import { ModuleInstance } from '@xyo-network/module' | ||
|
||
import { useHoveredNode, useNewElements, useRelationalGraphOptions, useRenderNewElements, useSelectedElement } from '../../../hooks' | ||
import { WithExtensions } from '../../cytoscape-extensions' | ||
import { NodeRelationalGraphFlexBox } from '../../RelationalGraph' | ||
import { ModuleGraphNodeHover } from './NodeHover' | ||
|
||
export interface ModuleGraphFlexBoxProps extends FlexBoxProps { | ||
rootModule?: ModuleInstance | null | ||
} | ||
|
||
export const ModuleGraphFlexBox: React.FC<ModuleGraphFlexBoxProps> = ({ rootModule, ...props }) => { | ||
const { handleToggleLabels, hideLabels, options } = useRelationalGraphOptions(rootModule ?? undefined) | ||
const selectedElement = useSelectedElement() | ||
const newElements = useNewElements(selectedElement) | ||
const renderedElements = useRenderNewElements(newElements, hideLabels) | ||
const hoveredNode = useHoveredNode(renderedElements) | ||
|
||
return ( | ||
<WithExtensions> | ||
<NodeRelationalGraphFlexBox | ||
actions={ | ||
<Button size={'small'} onClick={handleToggleLabels} variant="contained"> | ||
Toggle Labels | ||
</Button> | ||
} | ||
options={options} | ||
{...props} | ||
> | ||
<ModuleGraphNodeHover node={hoveredNode} /> | ||
</NodeRelationalGraphFlexBox> | ||
</WithExtensions> | ||
) | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/sdk/packages/node-renderer/src/components/module/graph/NodeHover.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,56 @@ | ||
import { NodeSingular } from 'cytoscape' | ||
import { useLayoutEffect, useRef, useState } from 'react' | ||
|
||
import { ModuleHoverPopper } from './Popper' | ||
|
||
export interface ModuleHoverProps { | ||
node?: NodeSingular | ||
} | ||
|
||
export const ModuleGraphNodeHover: React.FC<ModuleHoverProps> = ({ node }) => { | ||
const { address, name } = node?.data() ?? {} | ||
const [boundingBox, setBoundingBox] = useState(node?.renderedBoundingBox()) | ||
const ref = useRef<HTMLDivElement>(null) | ||
const [currentEl, setCurrentEl] = useState<HTMLDivElement | null>(null) | ||
|
||
useLayoutEffect(() => { | ||
if (node && ref.current) { | ||
setBoundingBox(node.renderedBoundingBox()) | ||
setCurrentEl(ref.current) | ||
} | ||
|
||
const listener = () => { | ||
setBoundingBox(node?.renderedBoundingBox()) | ||
} | ||
|
||
node?.on('position', listener) | ||
|
||
return () => { | ||
node?.off('position', undefined, listener) | ||
} | ||
}, [node]) | ||
|
||
return ( | ||
<> | ||
{node ? ( | ||
<> | ||
<div | ||
ref={ref} | ||
style={{ | ||
// backgroundColor: '#fff', | ||
// opacity: 0.25, | ||
cursor: 'pointer', | ||
height: boundingBox?.h, | ||
left: boundingBox?.x1, | ||
pointerEvents: 'none', | ||
position: 'absolute', | ||
top: boundingBox?.y1, | ||
width: boundingBox?.w, | ||
}} | ||
></div> | ||
<ModuleHoverPopper address={address} element={currentEl} name={name} placement={'top'} open /> | ||
</> | ||
) : null} | ||
</> | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/sdk/packages/node-renderer/src/components/module/graph/Popper.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,23 @@ | ||
import { alpha, Chip, Popper, PopperProps, Theme, Typography } from '@mui/material' | ||
import { FlexCol, FlexRow } from '@xylabs/react-flexbox' | ||
import { Identicon } from '@xylabs/react-identicon' | ||
|
||
export interface ModuleHoverPopperProps extends PopperProps { | ||
address?: string | ||
element?: HTMLElement | null | ||
name?: string | ||
} | ||
|
||
export const ModuleHoverPopper: React.FC<ModuleHoverPopperProps> = ({ address, element, name, ...props }) => { | ||
return ( | ||
<Popper anchorEl={element} {...props}> | ||
<FlexCol gap={2} p={2} paper sx={{ backgroundColor: (theme: Theme) => alpha(theme.palette.background.paper, 0.95) }}> | ||
<FlexRow gap={2}> | ||
<Identicon value={address} size={24} /> | ||
<Typography>{name}</Typography> | ||
</FlexRow> | ||
<Chip label={address} color={'primary'} /> | ||
</FlexCol> | ||
</Popper> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
packages/sdk/packages/node-renderer/src/components/module/graph/index.ts
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 @@ | ||
export * from './GraphFlexBox' |
2 changes: 2 additions & 0 deletions
2
packages/sdk/packages/node-renderer/src/components/module/index.ts
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,2 @@ | ||
export * from './CardParser' | ||
export * from './graph' |
5 changes: 3 additions & 2 deletions
5
packages/sdk/packages/node-renderer/src/hooks/cytoscape/index.ts
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './useAddNewElements' | ||
export * from './useCytoscapeElements' | ||
export * from './useCytoscapeOptions' | ||
export * from './useHoveredNode' | ||
export * from './useNewElements' | ||
export * from './usePopperListener' | ||
export * from './useRelationalGraphOptions' | ||
export * from './useRenderNewElements' | ||
export * from './useSelectedElement' |
19 changes: 0 additions & 19 deletions
19
packages/sdk/packages/node-renderer/src/hooks/cytoscape/useAddNewElements.tsx
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
packages/sdk/packages/node-renderer/src/hooks/cytoscape/useHoveredNode.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,32 @@ | ||
import { NodeCollection, NodeSingular } from 'cytoscape' | ||
import { useCallback, useEffect, useState } from 'react' | ||
|
||
import { useCytoscapeInstance } from '../../contexts' | ||
|
||
export const useHoveredNode = (renderedElements?: NodeCollection) => { | ||
const { cy } = useCytoscapeInstance(true) | ||
const [hoveredNode, setHoveredNode] = useState<NodeSingular>() | ||
|
||
const nodeListener = useCallback((node: NodeSingular) => { | ||
node.on('mouseover tap', () => { | ||
setHoveredNode(node) | ||
}) | ||
node.on('mouseout', () => { | ||
setHoveredNode(undefined) | ||
}) | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (renderedElements) { | ||
renderedElements.nodes().forEach(nodeListener) | ||
} | ||
}, [nodeListener, renderedElements]) | ||
|
||
useEffect(() => { | ||
cy?.ready(() => { | ||
cy.nodes().forEach(nodeListener) | ||
}) | ||
}, [cy, nodeListener]) | ||
|
||
return hoveredNode | ||
} |
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
Oops, something went wrong.