@@ -32,7 +32,7 @@ export default class Graph extends React.Component {
3232
3333 let yCenter = 100
3434 let totalYAllowed = yCenter * 2
35- let vertexGap = 150
35+ let vertexGap = this . props . orientation === 'horizontal' ? 100 : 70
3636
3737 console . log ( this . state . list )
3838
@@ -52,9 +52,13 @@ export default class Graph extends React.Component {
5252 if ( mainVertexCoordinates ) {
5353 // if mainVertex is already set, take partitionLength from it (to keep it at same Y coordinate)
5454 // also take x coordinate from the same and add the standard center gap
55-
56- partitionLength = mainVertexCoordinates . y * 2 / ( edgesTo . length + 1 )
57- childX = mainVertexCoordinates . x + vertexGap
55+ if ( this . props . orientation === 'horizontal' ) {
56+ partitionLength = mainVertexCoordinates . y * 2 / ( edgesTo . length + 1 )
57+ childX = mainVertexCoordinates . x + vertexGap
58+ } else {
59+ partitionLength = mainVertexCoordinates . x * 2 / ( edgesTo . length + 1 )
60+ childX = mainVertexCoordinates . y + vertexGap
61+ }
5862 }
5963
6064 for ( let i = 0 ; i < edgesTo . length ; i ++ ) {
@@ -96,9 +100,16 @@ export default class Graph extends React.Component {
96100 if ( flag ) throw new Error ( "Initializing the graph with multiple vertices? Only 1 vertex is supported for now" )
97101 // this is the first vertex which was not registered in the for-loop above
98102 flag = true
99- this . state . vertexCoordinates [ vertex ] = {
100- x : 100 ,
101- y : yCenter
103+ if ( this . props . orientation === 'horizontal' ) {
104+ this . state . vertexCoordinates [ vertex ] = {
105+ x : 100 ,
106+ y : yCenter
107+ }
108+ } else {
109+ this . state . vertexCoordinates [ vertex ] = {
110+ x : yCenter ,
111+ y : 100
112+ }
102113 }
103114 }
104115 } )
@@ -129,12 +140,12 @@ export default class Graph extends React.Component {
129140
130141 render ( ) {
131142
132- const vertices = this . props . vertices
143+ const { vertices, width , height } = this . props
133144
134145 const vertexCoordinates = this . state . vertexCoordinates
135146
136147 return (
137- < Stage width = { window . innerWidth } height = { window . innerHeight } >
148+ < Stage width = { width } height = { height } >
138149 < Layer >
139150 {
140151 this . getEdges ( )
@@ -159,7 +170,9 @@ export default class Graph extends React.Component {
159170}
160171
161172Graph . propTypes = {
162- orientation : PropTypes . oneOf ( [ 'horizontal' , 'vertical' ] ) . isRequired
173+ orientation : PropTypes . oneOf ( [ 'horizontal' , 'vertical' ] ) . isRequired ,
174+ width : PropTypes . number . isRequired ,
175+ height : PropTypes . number . isRequired
163176}
164177
165178Graph . defaultProps = {
0 commit comments