@@ -71,15 +71,21 @@ export default class Sandbox extends React.Component {
7171 if ( this . state . data . nodes && this . state . data . nodes . length ) {
7272 const maxIndex = this . state . data . nodes . length - 1 ;
7373 const minIndex = 0 ;
74- const i = Math . floor ( Math . random ( ) * ( maxIndex - minIndex + 1 ) + minIndex ) ;
75- const id = this . state . data . nodes [ i ] . id ;
74+ let i = Math . floor ( Math . random ( ) * ( maxIndex - minIndex + 1 ) + minIndex ) ;
75+ let nLinks = Math . floor ( Math . random ( ) * ( 5 - minIndex + 1 ) + minIndex ) ;
7676 const newNode = `Node ${ this . state . data . nodes . length } ` ;
7777
7878 this . state . data . nodes . push ( { id : newNode } ) ;
79- this . state . data . links . push ( {
80- source : newNode ,
81- target : id
82- } ) ;
79+
80+ while ( this . state . data . nodes [ i ] && this . state . data . nodes [ i ] . id && nLinks ) {
81+ this . state . data . links . push ( {
82+ source : newNode ,
83+ target : this . state . data . nodes [ i ] . id
84+ } ) ;
85+
86+ i ++ ;
87+ nLinks -- ;
88+ }
8389
8490 this . setState ( {
8591 data : this . state . data
@@ -136,6 +142,8 @@ export default class Sandbox extends React.Component {
136142 return { config, schemaPropsValues} ;
137143 }
138144
145+ refresh = ( ) => location . reload ( ) ;
146+
139147 refreshGraph = ( data ) => {
140148 const { config, schemaPropsValues} = this . _buildGraphConfig ( data ) ;
141149
@@ -195,16 +203,27 @@ export default class Sandbox extends React.Component {
195203 return (
196204 < div className = 'container' >
197205 < div className = 'container__graph' >
198- < button onClick = { this . restartGraphSimulation } className = 'btn btn-default' style = { btnStyle } disabled = { this . state . config . staticGraph } > ▶️</ button >
199- < button onClick = { this . pauseGraphSimulation } className = 'btn btn-default' style = { btnStyle } disabled = { this . state . config . staticGraph } > ⏸️</ button >
200- < button onClick = { this . resetNodesPositions } className = 'btn btn-default' style = { btnStyle } disabled = { this . state . config . staticGraph } > Unstick nodes</ button >
201- < button onClick = { this . onClickAddNode } className = 'btn btn-default' style = { btnStyle } > +</ button >
202- < button onClick = { this . onClickRemoveNode } className = 'btn btn-default' style = { btnStyle } > -</ button >
203- < br /> < b > Nodes: </ b > { this . state . data . nodes . length } , < b > Links: </ b > { this . state . data . links . length }
204- < Graph ref = 'graph' { ...graphProps } />
206+ < button onClick = { this . restartGraphSimulation } className = 'btn btn-default btn-margin-left' style = { btnStyle } disabled = { this . state . config . staticGraph } > ▶️</ button >
207+ < button onClick = { this . pauseGraphSimulation } className = 'btn btn-default btn-margin-left' style = { btnStyle } disabled = { this . state . config . staticGraph } > ⏸️</ button >
208+ < button onClick = { this . refresh } className = 'btn btn-default btn-margin-left' style = { btnStyle } > 🔄</ button >
209+ < button onClick = { this . resetNodesPositions } className = 'btn btn-default btn-margin-left' style = { btnStyle } disabled = { this . state . config . staticGraph } > Unstick nodes</ button >
210+ < button onClick = { this . onClickAddNode } className = 'btn btn-default btn-margin-left' style = { btnStyle } > +</ button >
211+ < button onClick = { this . onClickRemoveNode } className = 'btn btn-default btn-margin-left' style = { btnStyle } > -</ button >
212+ < span className = 'container__graph-info' >
213+ < b > Nodes: </ b > { this . state . data . nodes . length } | < b > Links: </ b > { this . state . data . links . length }
214+ </ span >
215+ < div className = 'container__graph-area' >
216+ < Graph ref = 'graph' { ...graphProps } />
217+ </ div >
205218 </ div >
206219 < div className = 'container__form' >
207- < h4 > < a href = "https://github.com/danielcaldas/react-d3-graph" target = "_blank" > < img width = "40" height = "40" src = "https://a248.e.akamai.net/assets.github.com/images/icons/emoji/octocat.png" > </ img > react-d3-graph</ a > configurations </ h4 >
220+ < h4 >
221+ < a href = "https://github.com/danielcaldas/react-d3-graph" target = "_blank" > react-d3-graph</ a >
222+ </ h4 >
223+ < h4 >
224+ < a href = "https://danielcaldas.github.io/react-d3-graph/docs/index.html" target = "_blank" > docs</ a >
225+ </ h4 >
226+ < h3 > Configurations</ h3 >
208227 < Form className = 'form-wrapper'
209228 schema = { this . state . schema }
210229 uiSchema = { this . uiSchema }
@@ -220,7 +239,7 @@ export default class Sandbox extends React.Component {
220239 < JSONContainer data = { this . state . generatedConfig } staticData = { false } />
221240 </ div >
222241 < div className = 'container__graph-data' >
223- < h4 > Initial Graph data </ h4 >
242+ < h4 > Initial Graph Data </ h4 >
224243 < JSONContainer data = { this . state . data } staticData = { true } />
225244 </ div >
226245 </ div >
0 commit comments