forked from lonestone/rolebase.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new graph renderer with HTML (beta)
- Loading branch information
Showing
27 changed files
with
732 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Box } from '@chakra-ui/react' | ||
import React, { forwardRef, useImperativeHandle, useRef } from 'react' | ||
import { CirclesGraph } from './graphs/CirclesGraph' | ||
import useCirclesGraph, { CirclesGraphProps } from './hooks/useCirclesGraph' | ||
import CirclesTitles from './renderers/html/CirclesTitles' | ||
import Nodes from './renderers/html/Nodes' | ||
import { Panzoom } from './renderers/html/Panzoom' | ||
|
||
// Force reset with fast refresh | ||
// @refresh reset | ||
|
||
export default forwardRef<CirclesGraph | undefined, CirclesGraphProps>( | ||
function CirclesHTMLGraph(props, ref) { | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
|
||
// Instanciate graph | ||
const graph = useCirclesGraph(containerRef, props) | ||
|
||
// Expose ref | ||
useImperativeHandle(ref, () => graph) | ||
|
||
const focusWidth = | ||
props.width - (props.focusCrop?.left || 0) - (props.focusCrop?.right || 0) | ||
|
||
const focusHeight = | ||
props.height - | ||
(props.focusCrop?.top || 0) - | ||
(props.focusCrop?.bottom || 0) | ||
|
||
const graphMinSize = Math.min(focusWidth, focusHeight) | ||
|
||
// Click outside => unselect circle | ||
const handleClickOutside = (event: React.MouseEvent<HTMLDivElement>) => { | ||
if (event.target === containerRef.current) { | ||
props.events?.onClickOutside?.() | ||
} | ||
} | ||
|
||
return ( | ||
<Box | ||
ref={containerRef} | ||
width={props.width} | ||
height={props.height} | ||
style={ | ||
{ | ||
'--graph-min-size': graphMinSize, | ||
} as React.CSSProperties | ||
} | ||
onClick={handleClickOutside} | ||
> | ||
{graph && ( | ||
<Panzoom graph={graph}> | ||
<Nodes graph={graph} /> | ||
<CirclesTitles graph={graph} /> | ||
</Panzoom> | ||
)} | ||
</Box> | ||
) | ||
} | ||
) |
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
Oops, something went wrong.