@@ -4,50 +4,59 @@ import { Select, SelectOption, ThemeProvider } from "@gravity-ui/uikit";
44import type { Meta , StoryFn } from "@storybook/react" ;
55
66import { Graph , GraphCanvas , GraphState , TBlock , TConnection , useGraph , useGraphEvent } from "../../../index" ;
7- import { MultipointConnection } from "../../../plugins/elk/components/MultipointConnection" ;
8- import { useElk } from "../../../plugins/elk/hooks/useElk" ;
7+ import { MultipointConnection , useElk } from "../../../plugins" ;
98import { TMultipointConnection } from "../../../plugins/elk/types" ;
109import { useFn } from "../../../utils/hooks/useFn" ;
11- import { generatePrettyBlocks } from "../../configurations/generatePretty" ;
1210import { BlockStory } from "../../main/Block" ;
1311
14- import { getElkConfig } from "./getElkConfig" ;
12+ import { getExampleConfig } from "./getExampleConfig" ;
13+
14+ export enum Algorithm {
15+ Box = "box" ,
16+ Layered = "layered" ,
17+ Disco = "disco" ,
18+ Radial = "radial" ,
19+ MrTree = "mrtree" ,
20+ Force = "force" ,
21+ Stress = "stress" ,
22+ Random = "random" ,
23+ SporeOverlap = "sporeOverlap" ,
24+ SporeCompaction = "sporeCompaction" ,
25+ }
1526
1627import "@gravity-ui/uikit/styles/styles.css" ;
1728
18- const config = generatePrettyBlocks ( 10 , 30 , true ) ;
19-
2029const GraphApp = ( ) => {
21- const [ algorithm , setAlgorithm ] = useState ( "layered" ) ;
30+ const [ algorithm , setAlgorithm ] = useState ( Algorithm . Layered ) ;
31+ const [ algorithms , setAlgorithms ] = useState < SelectOption [ ] > ( [ ] ) ;
2232 const { graph, setEntities, start } = useGraph ( {
2333 settings : {
2434 connection : MultipointConnection ,
2535 } ,
2636 } ) ;
2737
28- const elkConfig = useMemo ( ( ) => {
29- return getElkConfig ( config , algorithm ) ;
38+ const { elkConfig, graphConfig } = useMemo ( ( ) => {
39+ return getExampleConfig ( algorithm ) ;
3040 } , [ algorithm ] ) ;
3141
3242 const { isLoading, elk, result } = useElk ( elkConfig ) ;
3343
3444 useEffect ( ( ) => {
3545 if ( isLoading || ! result ) return ;
3646
37- const connections = config . connections . reduce < ( TConnection & Pick < TMultipointConnection , "points" | "labels" > ) [ ] > (
38- ( acc , connection ) => {
39- if ( connection . id in result . edges ) {
40- acc . push ( {
41- ...connection ,
42- ...result . edges [ connection . id ] ,
43- } ) ;
44- }
45- return acc ;
46- } ,
47- [ ]
48- ) ;
49-
50- const blocks = config . blocks . map ( ( block ) => {
47+ const connections = graphConfig . connections . reduce <
48+ ( TConnection & Pick < TMultipointConnection , "points" | "labels" > ) [ ]
49+ > ( ( acc , connection ) => {
50+ if ( connection . id in result . edges ) {
51+ acc . push ( {
52+ ...connection ,
53+ ...result . edges [ connection . id ] ,
54+ } ) ;
55+ }
56+ return acc ;
57+ } , [ ] ) ;
58+
59+ const blocks = graphConfig . blocks . map ( ( block ) => {
5160 return {
5261 ...block ,
5362 ...result . blocks [ block . id ] ,
@@ -62,8 +71,6 @@ const GraphApp = () => {
6271 graph . zoomTo ( "center" , { padding : 300 } ) ;
6372 } , [ isLoading , result ] ) ;
6473
65- const [ algorithms , setAlgorithms ] = useState < SelectOption [ ] > ( [ ] ) ;
66-
6774 useEffect ( ( ) => {
6875 elk . knownLayoutAlgorithms ( ) . then ( ( knownLayoutAlgorithms ) => {
6976 setAlgorithms (
@@ -88,7 +95,7 @@ const GraphApp = () => {
8895
8996 return (
9097 < ThemeProvider theme = { "light" } >
91- < Select value = { [ algorithm ] } options = { algorithms } onUpdate = { ( v ) => setAlgorithm ( v [ 0 ] ) } > </ Select >
98+ < Select value = { [ algorithm ] } options = { algorithms } onUpdate = { ( v ) => setAlgorithm ( v [ 0 ] as Algorithm ) } > </ Select >
9299 < GraphCanvas className = "graph" graph = { graph } renderBlock = { renderBlockFn } /> ;
93100 </ ThemeProvider >
94101 ) ;
0 commit comments