PDF Schema File: Relation_Stats class structured

This commit is contained in:
Adnan
2010-07-10 15:44:17 +05:00
parent 459eeb1230
commit 9fb8619f2a

View File

@@ -19,7 +19,7 @@ require_once './libraries/tcpdf/tcpdf.php';
/** /**
* Extends the "TCPDF" class and helps * Extends the "TCPDF" class and helps
* in developing the structure of PDF Schema Export * in developing the structure of PDF Schema Export
* * *
* @name PMA_PDF * @name PMA_PDF
* @author Muhammad Adnan <hiddenpearls@gmail.com> * @author Muhammad Adnan <hiddenpearls@gmail.com>
* @copyright * @copyright
@@ -685,19 +685,73 @@ class Table_Stats {
/** /**
* Draws relation links * Draws relation links
* *
* @access private * @access public
* @see * @see PMA_PDF
* @package phpMyAdmin
*/ */
class Relation_Stats { class Relation_Stats
{
/** /**
* Defines private properties * Defines properties
*/ */
var $x_src, $y_src; public $xSrc, $ySrc;
var $src_dir ; public $srcDir;
var $dest_dir; public $destDir;
var $x_dest, $y_dest; public $xDest, $yDest;
var $w_tick = 5; public $wTick = 5;
/**
* The "Relation_Stats" constructor
*
* @param string master_table The master table name
* @param string master_field The relation field in the master table
* @param string foreign_table The foreign table name
* @param string foreigh_field The relation field in the foreign table
* @see Relation_Stats::_getXy
*/
function __construct($master_table, $master_field, $foreign_table, $foreign_field)
{
$src_pos = $this->_getXy($master_table, $master_field);
$dest_pos = $this->_getXy($foreign_table, $foreign_field);
/*
* [0] is x-left
* [1] is x-right
* [2] is y
*/
$src_left = $src_pos[0] - $this->wTick;
$src_right = $src_pos[1] + $this->wTick;
$dest_left = $dest_pos[0] - $this->wTick;
$dest_right = $dest_pos[1] + $this->wTick;
$d1 = abs($src_left - $dest_left);
$d2 = abs($src_right - $dest_left);
$d3 = abs($src_left - $dest_right);
$d4 = abs($src_right - $dest_right);
$d = min($d1, $d2, $d3, $d4);
if ($d == $d1) {
$this->xSrc = $src_pos[0];
$this->srcDir = -1;
$this->xDest = $dest_pos[0];
$this->destDir = -1;
} elseif ($d == $d2) {
$this->xSrc = $src_pos[1];
$this->srcDir = 1;
$this->xDest = $dest_pos[0];
$this->destDir = -1;
} elseif ($d == $d3) {
$this->xSrc = $src_pos[0];
$this->srcDir = -1;
$this->xDest = $dest_pos[1];
$this->destDir = 1;
} else {
$this->xSrc = $src_pos[1];
$this->srcDir = 1;
$this->xDest = $dest_pos[1];
$this->destDir = 1;
}
$this->ySrc = $src_pos[2];
$this->yDest = $dest_pos[2];
}
/** /**
* Gets arrows coordinates * Gets arrows coordinates
@@ -715,7 +769,8 @@ class Relation_Stats {
} }
/** /**
* Do draws relation links * draws relation links and arrows
* shows foreign key relations
* *
* @param boolean changeColor Whether to use one color per relation or not * @param boolean changeColor Whether to use one color per relation or not
* @param integer i The id of the link to draw * @param integer i The id of the link to draw
@@ -745,69 +800,22 @@ class Relation_Stats {
$pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
} else { } else {
$pdf->SetDrawColor(0); $pdf->SetDrawColor(0);
} // end if... else... }
$pdf->PMA_PDF_setLineWidthScale(0.2); $pdf->PMA_PDF_setLineWidthScale(0.2);
$pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src); $pdf->PMA_PDF_lineScale($this->xSrc, $this->ySrc, $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc);
$pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest); $pdf->PMA_PDF_lineScale($this->xDest + $this->destDir * $this->wTick, $this->yDest, $this->xDest, $this->yDest);
$pdf->PMA_PDF_setLineWidthScale(0.1); $pdf->PMA_PDF_setLineWidthScale(0.1);
$pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick, $this->y_src, $this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest); $pdf->PMA_PDF_lineScale($this->xSrc + $this->srcDir * $this->wTick, $this->ySrc, $this->xDest + $this->destDir * $this->wTick, $this->yDest);
// arrow /*
$root2 = 2 * sqrt(2); * Draws arrows ->
$pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src + $this->w_tick / $root2);
$pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src - $this->w_tick / $root2);
$pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest + $this->w_tick / $root2);
$pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest - $this->w_tick / $root2);
$pdf->SetDrawColor(0);
}
/**
* The "Relation_Stats" constructor
*
* @param string masterTable The master table name
* @param string masterField The relation field in the master table
* @param string foreignTable The foreign table name
* @param string foreignField The relation field in the foreign table
* @see _Relation::_getXy
*/ */
function __construct($masterTable, $masterField, $foreignTable, $foreignField) $root2 = 2 * sqrt(2);
{ $pdf->PMA_PDF_lineScale($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc + $this->wTick / $root2);
$src_pos = $this->_getXy($masterTable, $masterField); $pdf->PMA_PDF_lineScale($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc - $this->wTick / $root2);
$dest_pos = $this->_getXy($foreignTable, $foreignField);
$src_left = $src_pos[0] - $this->w_tick;
$src_right = $src_pos[1] + $this->w_tick;
$dest_left = $dest_pos[0] - $this->w_tick;
$dest_right = $dest_pos[1] + $this->w_tick;
$d1 = abs($src_left - $dest_left); $pdf->PMA_PDF_lineScale($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest + $this->wTick / $root2);
$d2 = abs($src_right - $dest_left); $pdf->PMA_PDF_lineScale($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest - $this->wTick / $root2);
$d3 = abs($src_left - $dest_right); $pdf->SetDrawColor(0);
$d4 = abs($src_right - $dest_right);
$d = min($d1, $d2, $d3, $d4);
if ($d == $d1) {
$this->x_src = $src_pos[0];
$this->src_dir = -1;
$this->x_dest = $dest_pos[0];
$this->dest_dir = -1;
} elseif ($d == $d2) {
$this->x_src = $src_pos[1];
$this->src_dir = 1;
$this->x_dest = $dest_pos[0];
$this->dest_dir = -1;
} elseif ($d == $d3) {
$this->x_src = $src_pos[0];
$this->src_dir = -1;
$this->x_dest = $dest_pos[1];
$this->dest_dir = 1;
} else {
$this->x_src = $src_pos[1];
$this->src_dir = 1;
$this->x_dest = $dest_pos[1];
$this->dest_dir = 1;
}
$this->y_src = $src_pos[2];
$this->y_dest = $dest_pos[2];
} }
} }