1+ import { useEffect } from 'react' ;
12import { SafeAreaView , View } from 'react-native' ;
23import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
34
4- import DirectedGraphComponent from '@/components/graphs/DirectedGraphComponent' ;
55import DefaultEdgeLabelRenderer from '@/components/graphs/labels/renderers/DefaultEdgeLabelRenderer' ;
6- import { DirectedGraph } from '@/models/graphs' ;
6+ import { UndirectedGraph } from '@/models/graphs' ;
77import PannableScalableView from '@/views/PannableScalableView' ;
88
9+ import UndirectedGraphComponent from './components/graphs/UndirectedGraphComponent' ;
10+
911const GRAPH1 = {
1012 vertices : [
1113 { key : 'A' , data : 'A' } ,
@@ -15,10 +17,10 @@ const GRAPH1 = {
1517 { key : 'E' , data : 'E' }
1618 ] ,
1719 edges : [
18- { key : 'AB' , from : 'A' , to : 'B' , data : 'AB' } ,
19- { key : 'AC' , from : 'A' , to : 'C' , data : 'AC' } ,
20- { key : 'AD' , from : 'A' , to : 'D' , data : 'AD' } ,
21- { key : 'AE' , from : 'A' , to : 'E' , data : 'AE' }
20+ { key : 'AB' , vertices : [ 'A' , 'B' ] , data : 'AB' } ,
21+ { key : 'AC' , vertices : [ 'A' , 'C' ] , data : 'AC' } ,
22+ { key : 'AD' , vertices : [ 'A' , 'D' ] , data : 'AD' } ,
23+ { key : 'AE' , vertices : [ 'A' , 'E' ] , data : 'AE' }
2224 ]
2325} ;
2426
@@ -36,15 +38,15 @@ const GRAPH2 = {
3638 { key : 'O' , data : 'O' }
3739 ] ,
3840 edges : [
39- { key : 'FG' , from : 'F' , to : 'G' , data : 'FG' } ,
40- { key : 'FH' , from : 'F' , to : 'H' , data : 'FH' } ,
41- { key : 'FI' , from : 'F' , to : 'I' , data : 'FI' } ,
42- { key : 'GJ' , from : 'G' , to : 'J' , data : 'GJ' } ,
43- { key : 'GK' , from : 'G' , to : 'K' , data : 'GK' } ,
44- { key : 'GL' , from : 'G' , to : 'L' , data : 'GL' } ,
45- { key : 'GM' , from : 'G' , to : 'M' , data : 'GM' } ,
46- { key : 'GN' , from : 'G' , to : 'N' , data : 'GN' } ,
47- { key : 'GO' , from : 'G' , to : 'O' , data : 'GO' }
41+ { key : 'FG' , vertices : [ 'F' , 'G' ] , data : 'FG' } ,
42+ { key : 'FH' , vertices : [ 'F' , 'H' ] , data : 'FH' } ,
43+ { key : 'FI' , vertices : [ 'F' , 'I' ] , data : 'FI' } ,
44+ { key : 'GJ' , vertices : [ 'G' , 'J' ] , data : 'GJ' } ,
45+ { key : 'GK' , vertices : [ 'G' , 'K' ] , data : 'GK' } ,
46+ { key : 'GL' , vertices : [ 'G' , 'L' ] , data : 'GL' } ,
47+ { key : 'GM' , vertices : [ 'G' , 'M' ] , data : 'GM' } ,
48+ { key : 'GN' , vertices : [ 'G' , 'N' ] , data : 'GN' } ,
49+ { key : 'GO' , vertices : [ 'G' , 'O' ] , data : 'GO' }
4850 ]
4951} ;
5052
@@ -54,8 +56,8 @@ const GRAPH3 = {
5456 { key : 'Q' , data : 'Q' }
5557 ] ,
5658 edges : [
57- { key : 'PQ1' , from : 'P' , to : 'Q' , data : 'PQ1' } ,
58- { key : 'PQ2' , from : 'P' , to : 'Q' , data : 'PQ2' }
59+ { key : 'PQ1' , vertices : [ 'P' , 'Q' ] , data : 'PQ1' } ,
60+ { key : 'PQ2' , vertices : [ 'P' , 'Q' ] , data : 'PQ2' }
5961 ]
6062} ;
6163
@@ -64,23 +66,41 @@ const DISCONNECTED_GRAPH = {
6466 edges : [ ...GRAPH1 . edges , ...GRAPH2 . edges , ...GRAPH3 . edges ]
6567} ;
6668
69+ let phase = 0 ;
70+
6771export default function App ( ) {
68- const graph = DirectedGraph . fromData (
72+ const graph = UndirectedGraph . fromData (
6973 DISCONNECTED_GRAPH . vertices ,
7074 DISCONNECTED_GRAPH . edges
7175 ) ;
7276
77+ useEffect ( ( ) => {
78+ setInterval ( ( ) => {
79+ if ( phase === 0 ) {
80+ graph . insertEdge ( 'PC' , '' , 'P' , 'C' ) ;
81+ } else if ( phase === 1 ) {
82+ graph . insertEdge ( 'CI' , '' , 'C' , 'I' ) ;
83+ } else if ( phase === 2 ) {
84+ graph . removeEdge ( 'PC' ) ;
85+ } else if ( phase === 3 ) {
86+ graph . removeEdge ( 'CI' ) ;
87+ }
88+ phase = ( phase + 1 ) % 4 ;
89+ } , 1000 ) ;
90+ } , [ graph ] ) ;
91+
7392 return (
7493 < SafeAreaView className = 'grow' >
7594 < GestureHandlerRootView className = 'grow' >
7695 < View className = 'grow bg-black' >
7796 < PannableScalableView objectFit = 'contain' controls >
78- < DirectedGraphComponent
97+ < UndirectedGraphComponent
7998 graph = { graph }
8099 settings = { {
81100 // TODO - fix orbits strategy padding
82101 placement : {
83- strategy : 'circles' ,
102+ strategy : 'orbits' ,
103+ layerSizing : 'equal' ,
84104 minVertexSpacing : 100
85105 } ,
86106 components : {
0 commit comments