Login   Register  
PHP Classes
elePHPant
Icontem

File: bin/example_directory_tree_dynamic.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Stefan Lwe  >  Reingold Tilford  >  bin/example_directory_tree_dynamic.php  >  Download  
File: bin/example_directory_tree_dynamic.php
Role: Example script
Content type: text/plain
Description: example with some dynamic CSS goodies
Class: Reingold Tilford
Render tree structures in several image formats
Author: By
Last change: made inclusion of bootstrap script more robust
Date: 3 years ago
Size: 3,366 bytes
 

Contents

Class file image Download
<?php

/**
 * This example exports the directory structure of the installation folder of this package to HTML, with some interactive components.
 *
 * Just direct your browser to this file.
 */

use Utils\Autoload\Autoloader;
use 
ReingoldTilford\Algorithms\ReingoldTilfordAlgorithm;
use 
ReingoldTilford\Models\FSTreeModel;
use 
ReingoldTilford\Plotters\Plotter;
use 
ReingoldTilford\Styles\TreeStyle;
use 
Utils\Graphics2D\DrawingPanes\HtmlDrawingPane;
use 
Utils\Graphics2D\Shapes\Styles\TextStyle;
use 
Utils\Geom\Dimension;
use 
Utils\File\Directory;
use 
Utils\Font\FontManager;
use 
Utils\Font\FontMetricServices\FontMetricServiceFactory;
use 
Utils\URL\Url;

require_once 
__DIR__.'/../app/bootstrap.inc';

// get the directory information
$rootDirectory = new Directory(new SplFileInfo(INSTALLATION_FOLDER));
$rootDirectory->expand();

// get the default style for a tree
$style = new TreeStyle();
$style->shapeStyle->setWidth(8);
$style->shapeStyle->setHeight(5);
$style->shapeStyle->setColor(new \Utils\Color\RgbColor(251247180));
$style->shapeStyle->border->setColor(new \Utils\Color\RgbColor(228212128));
$style->edgeStyle->setColor(new \Utils\Color\RgbColor(200200200));

// get a new instance of the algorithm
$algorithm  = new ReingoldTilfordAlgorithm();

// get the model for the root directory, so that the algorithm can traverse it
$model      = new FSTreeModel($rootDirectory);

// get the layout of the tree
$layout     $algorithm->getLayout($model$style->orientation)->normalize();

// pass it to the plotter
$plotter    = new Plotter($model$layoutnullnullnull);

// create a new document
$document = new HtmlDrawingPane($layout->getDimension($style));

// plot it onto the document
$plotter->plot($style$document);

// print the html head
printHtmlHead($style);

// print the document
echo $document->save();

/**
 * This helper method prints the html head, e.g. the CSS styles in use.
 */
function printHtmlHead(TreeStyle $treeStyle)
{
    echo 
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'.PHP_EOL.
       
'"http://www.w3.org/TR/html4/loose.dtd">'.PHP_EOL.
        
'<style>'.PHP_EOL.
            
'.rt_node'.PHP_EOL.
            
'{'.PHP_EOL.
                
'position:          absolute;'.PHP_EOL.
            
'}'.PHP_EOL.

            
'.sty0:hover'.PHP_EOL.
            
'{'.PHP_EOL.
                
'width:             240px;'.PHP_EOL.
                
'height:            100px;'.PHP_EOL.
                
'opacity:           0.5;'.PHP_EOL.
                
'z-index:           10;'.PHP_EOL.
                
'border:            solid 2px black;'.PHP_EOL.
            
'}'.PHP_EOL.

            
'.rt_edge'.PHP_EOL.
            
'{'.
                
'position:          absolute;'.PHP_EOL.
            
'}'.PHP_EOL.

            
'.text'.PHP_EOL.
            
'{'.
                
'width:             0px;'.PHP_EOL.
                
'overflow:          hidden;'.PHP_EOL.
            
'}'.PHP_EOL.

            
'.sty0:hover + .text'.PHP_EOL.
            
'{'.
                
'width:             240px;'.PHP_EOL.
                
'overflow:          visible;'.PHP_EOL.
                
'z-index:           1;'.PHP_EOL.
                
'text-align:        center;'.PHP_EOL.
            
'}'.PHP_EOL.

        
'</style>';
}