Login Register Wishes Forum About
Language Reference » Spring charts functions » drawSpring
Help topics
Latest updates
2233d  replaceImageMapTitle
2233d  replaceImageMapValues
2233d  createFunctionSerie
2233d  setAbsicssaPosition
2233d  negateValues
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
drawSpring - Draw a Spring graph

This function allows will draw a spring graph. Parameters are given trough a $Settings array. To learn more about this please read the Format array guide.

Based on the number of nodes, the amount of connection and the graph area size, it may be not possible to create a graph without links overlap. As the spring algorithm is an almost linear one, the initial placement formula (defined with the "Algorithm" parameter) will do the difference in the final layout.

Calling this function
Where :

Object is the reference to a pImage object.

Settings array - Tune up your link!

It is possible to customize the rendering with this array.
You can specify the initial placement algorithm with Algorithm. (default is ALGORITHM_WEIGHTED)
The number of pass can be adjusted with Pass. (default is 50)
The number of retries can be set with Retries. (default is 10)
You can specify the text padding with TextPadding. (default is 4)
You can specify the attraction force with MagneticForceA. (default is 1.5)
You can specify the repulsion force with MagneticForceR. (default is 2)
You can draw the force vectors setting DrawVectors to TRUE.
You can draw the quiet zonesDrawQuietZone to TRUE.

Following algorithms are allowed :

ALGORITHM_RANDOM, nodes will be placed randomly.
ALGORITHM_WEIGHTED, node will be placed depending of their number of connections.
ALGORITHM_CIRCULAR, based on the weighted algorithm, this will limit the number of crossing links.

Sample script

 /* pChart library inclusions */

 /* Create the pChart object */
 $myPicture = new pImage(300,300);

 /* Background customization */
 $myPicture->drawText(10,13,"pSpring - Draw spring charts",array("R"=>255,"G"=>255,"B"=>255));

 /* Prepare the graph area */

 /* Create the pSpring object */
 $SpringChart = new pSpring();

 /* Set the nodes default settings */

 /* Build random nodes & connections */
   $Connections = "";
    { $Connections[] = rand(0,10); }
   $SpringChart->addNode($i,array("Name"=>"Node ".$i,"Connections"=>$Connections));

 /* Compute and draw the Spring Graph */
 $Result = $SpringChart->drawSpring($myPicture,array("DrawQuietZone"=>TRUE));

 /* Display the statistics */

 /* Render the picture */
Last updated on 07/28/2010 
by Jean-Damien 
Linked resources
Community comments
  No comments have been posted yet.
© Copyrights
Components used on this web site : Famfamfam icons has been made by Mark James, Rounded corners lite has been coded by Cameron Cooke and Tim Hutchison, SyntaxHighlighter has been written by Alex Gorbatchev. pChart and this web site have been created by Jean-Damien POGOLOTTI. This documentation contains 185 pages and 56 comments. 410 users have registered. This page has been rendered in 0,02 seconds. Wiki revision 1.37.