PHP Classes

Diagram 2: Draw an hierarchic diagram from a XML definition

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum (9)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 72%Total: 3,187 All time: 1,119 This week: 524Up
Version License Categories
diagram2 1.0.0GNU General Publi...XML, Graphics


This package can draw diagrams of hierarchy trees defined in XML files.

The diagram class is a follow-up of another class released here before. Instead of arrays, now it uses XML to define the diagram.

It also implements more features supporting: borders, text colors, fonts, text alignments, backgrounds, paddings, margins, text over the node connections and the thickness of the connections.

The tree XML files define the structure of nodes of the tree as well the graphical attributes that define details of how the diagram should be rendered.

Picture of Diogo Resende
Name: Diogo Resende <contact>
Classes: 10 packages by
Country: Portugal Portugal
Age: 41
All time rank: 292 in Portugal Portugal
Week rank: 262 Down7 in Portugal Portugal Down
Innovation award
Innovation award
Nominee: 4x

Winner: 2x


Hi, This class is so simple I don't think you'll need documentation. The class draws a diagram with only one root node. You can define properties for every node on the diagram. After instanciating the class you can pass the diagram structure in 2 diferent ways: xml file or xml data. If you pass the xml file it will then call the xml data function so if you're just opening the xml file and passing it to the function.. don't bother, just use the xml file feature. The function names are very simple: - loadXmlFile() With this function you can pass a file path as an argument. It will open the file and send the data to loadXmlData() to be parsed. - loadXmlData() With this function you can pass xml directly to the xml parser of the function. - Draw() After using one of the above function you should call this one to draw the diagram. The optional argument can be a path to where the image should be saved. If no argument is set, the image will be sent to stdout with the apropriate header. Now that you know all you need to build a diagram, you might be wondering how the xml file is. Well, it's simple. The basic structure is like this: <?xml version="1.0" encoding="UTF-8"?> <diagram> <node name="this is the name"> this is the data inside the node </node> </diagram> To load this file you would do: <?php include 'class.diagram.php'; $diagram = new Diagram(realpath('myfirstdiagram.xml')); $diagram->Draw(); ?> This would work if you save the previous xml in myfirstdiagram.xml and both the file and the class are in the same directory as this php file. Confused? Hope not. You have 2 examples. One simple and another a bit more complex with two-color backgrounds and text over lines. Hope you like it. To view them simply view test1.html and test2.html (on your server, not offline because it calls test.php). Any doubt, e-mail me at: me (at) diogoresende (dot) net Diogo Resende

  • test.png
  Files folder image Files  
File Role Description
Plain text file class.diagram-ext.php Class Class extension
Accessible without login Plain text file class.diagram.php Class Main class
Plain text file class.xmlparser.php Class Small auxiliary class to parse xml
Plain text file readme.txt Doc. Read it first if you're not sure what you're doing
Plain text file test.php Example This will load one of the two examples
HTML file test1.html Data Example 1
Plain text file test1.xml Data Test1 diagram in xml format
HTML file test2.html Data Example 2
Plain text file test2.php Example This will load the class with an array
Plain text file test2.xml Data Test2 diagram in xml format
Plain text file test4.php Example Test class extension

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:1,119
This week:524Up
User Ratings User Comments (2)
 All time
14 years ago (kishore kumar)
good exam.
16 years ago (Nguyen Duy Hai)