-
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.
- Loading branch information
Showing
20 changed files
with
1,499 additions
and
574 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 |
---|---|---|
@@ -1,40 +1,76 @@ | ||
import { Box } from "@chakra-ui/react"; | ||
import { Graph, GraphProps, useNgraph } from "@diagrams/graph"; | ||
import { ExpandableGraph, GraphOptions, SimpleGraph } from "@diagrams/graph"; | ||
import { useDefaultOptions } from "@diagrams/graph/lib/use-ngraph-simple"; | ||
import * as React from "react"; | ||
import { FC, useState } from "react"; | ||
import { edges, nodesL3, nodesL2, nodesLeaf } from "./data"; | ||
import { FC, useCallback, useMemo, useState } from "react"; | ||
import { edges, nodesL2, nodesLeaf } from "./data"; | ||
|
||
export const DemoGraphSimple: FC<{ options: GraphProps["options"] }> = ({ options }) => { | ||
const graph = useNgraph(nodesLeaf, edges, null, { iterations: 500 }); | ||
export const DemoGraphSimple: FC<{ | ||
options: GraphOptions; | ||
}> = ({ options: _options }) => { | ||
const [selected, setSelected] = useState<string>(); | ||
const options = useDefaultOptions(_options); | ||
const expand = useCallback(({ name }: { name: string }) => { | ||
console.log("Name", name); | ||
setSelected(name); | ||
}, []); | ||
const largeNodes = useMemo( | ||
() => | ||
nodesLeaf.map((node) => ({ | ||
...node, | ||
size: | ||
node.name === selected | ||
? { | ||
width: (node.size ?? options.defaultSize).width * 2, | ||
height: (node.size ?? options.defaultSize).height * 2, | ||
} | ||
: node.size, | ||
border: node.name === selected ? "red" : "black", | ||
})), | ||
[options.defaultSize, selected] | ||
); | ||
return ( | ||
<Box width="100%" height="100%"> | ||
<Graph key="graph" graph={graph} options={options} />; | ||
<SimpleGraph nodes={largeNodes} edges={edges} options={options} onSelectNode={expand} />; | ||
</Box> | ||
); | ||
}; | ||
|
||
export const DemoGraphLevel2: FC<{ options: GraphProps["options"] }> = ({ options }) => { | ||
export const DemoGraphLevel2: FC<{ | ||
options: GraphOptions; | ||
}> = ({ options: _options }) => { | ||
const [expanded, setExpanded] = useState<string[]>([]); | ||
const graph = useNgraph(nodesL2, edges, expanded, { iterations: 500 }); | ||
const onSelectNode = React.useCallback((args: { name: string }) => { | ||
const options = useDefaultOptions(_options); | ||
|
||
const onSelectNode = useCallback((args: { name: string }) => { | ||
setExpanded((exp) => (exp.includes(args.name) ? exp.filter((e) => e !== args.name) : [...exp, args.name])); | ||
}, []); | ||
return ( | ||
<Box width="100%" height="100%"> | ||
<Graph graph={graph} onSelectNode={onSelectNode} options={options} />; | ||
<ExpandableGraph | ||
key="expandable" | ||
nodes={nodesL2} | ||
edges={edges} | ||
onSelectNode={onSelectNode} | ||
expanded={expanded} | ||
options={options} | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
export const DemoGraphLevel3: FC<{ options: GraphProps["options"] }> = ({ options }) => { | ||
export const DemoGraphLevel3: FC<{ | ||
options: GraphOptions; | ||
}> = ({ options }) => { | ||
const [expanded, setExpanded] = useState<string[]>([]); | ||
const graph = useNgraph(nodesL3, edges, expanded, { iterations: 500 }); | ||
const onSelectNode = React.useCallback((args: { name: string }) => { | ||
setExpanded((exp) => (exp.includes(args.name) ? exp.filter((e) => e !== args.name) : [...exp, args.name])); | ||
}, []); | ||
return ( | ||
<Box width="100%" height="100%"> | ||
<Graph graph={graph} onSelectNode={onSelectNode} options={options} />; | ||
</Box> | ||
); | ||
return <Box />; | ||
// const graph = useNgraph(nodesL3, edges, expanded, { ...options, physics }); | ||
// const onSelectNode = React.useCallback((args: { name: string }) => { | ||
// setExpanded((exp) => (exp.includes(args.name) ? exp.filter((e) => e !== args.name) : [...exp, args.name])); | ||
// }, []); | ||
// return ( | ||
// <Box width="100%" height="100%"> | ||
// <Graph graph={graph} onSelectNode={onSelectNode} options={options} />; | ||
// </Box> | ||
// ); | ||
}; |
Oops, something went wrong.