Translation update done using Pootle.
[phpmyadmin/tyronm.git] / libraries / schema / Svg_Relation_Schema.class.php
blob292a78c092a77ce809669cb2bf5daf9a3e03c2e3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 require_once 'Export_Relation_Schema.class.php';
10 /**
11 * This Class inherits the XMLwriter class and
12 * helps in developing structure of SVG Schema Export
14 * @access public
15 * @see http://php.net/manual/en/book.xmlwriter.php
17 class PMA_SVG extends XMLWriter
19 public $title;
20 public $author;
21 public $font;
22 public $fontSize;
24 /**
25 * The "PMA_SVG" constructor
27 * Upon instantiation This starts writing the Svg XML document
29 * @return void
30 * @see XMLWriter::openMemory(),XMLWriter::setIndent(),XMLWriter::startDocument()
32 function __construct()
34 $this->openMemory();
36 * Set indenting using three spaces,
37 * so output is formatted
40 $this->setIndent(true);
41 $this->setIndentString(' ');
43 * Create the XML document
46 $this->startDocument('1.0', 'UTF-8');
47 $this->startDtd(
48 'svg', '-//W3C//DTD SVG 1.1//EN',
49 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'
51 $this->endDtd();
54 /**
55 * Set document title
57 * @param string $value sets the title text
59 * @return void
60 * @access public
62 function setTitle($value)
64 $this->title = $value;
67 /**
68 * Set document author
70 * @param string $value sets the author
72 * @return void
73 * @access public
75 function setAuthor($value)
77 $this->author = $value;
80 /**
81 * Set document font
83 * @param string $value sets the font e.g Arial, Sans-serif etc
85 * @return void
86 * @access public
88 function setFont($value)
90 $this->font = $value;
93 /**
94 * Get document font
96 * @return string returns the font name
97 * @access public
99 function getFont()
101 return $this->font;
105 * Set document font size
107 * @param string $value sets the font size in pixels
109 * @return void
110 * @access public
112 function setFontSize($value)
114 $this->fontSize = $value;
118 * Get document font size
120 * @return string returns the font size
121 * @access public
123 function getFontSize()
125 return $this->fontSize;
129 * Starts Svg Document
131 * svg document starts by first initializing svg tag
132 * which contains all the attributes and namespace that needed
133 * to define the svg document
135 * @param integer $width total width of the Svg document
136 * @param integer $height total height of the Svg document
138 * @return void
139 * @access public
141 * @see XMLWriter::startElement(),XMLWriter::writeAttribute()
143 function startSvgDoc($width,$height)
145 $this->startElement('svg');
146 $this->writeAttribute('width', $width);
147 $this->writeAttribute('height', $height);
148 $this->writeAttribute('xmlns', 'http://www.w3.org/2000/svg');
149 $this->writeAttribute('version', '1.1');
153 * Ends Svg Document
155 * @return void
156 * @access public
157 * @see XMLWriter::endElement(),XMLWriter::endDocument()
159 function endSvgDoc()
161 $this->endElement();
162 $this->endDocument();
166 * output Svg Document
168 * svg document prompted to the user for download
169 * Svg document saved in .svg extension and can be
170 * easily changeable by using any svg IDE
172 * @param string $fileName file name
174 * @return void
175 * @access public
176 * @see XMLWriter::startElement(),XMLWriter::writeAttribute()
178 function showOutput($fileName)
180 //ob_get_clean();
181 $output = $this->flush();
182 PMA_download_header($fileName . '.svg', 'image/svg+xml', strlen($output));
183 print $output;
187 * Draws Svg elements
189 * SVG has some predefined shape elements like rectangle & text
190 * and other elements who have x,y co-ordinates are drawn.
191 * specify their width and height and can give styles too.
193 * @param string $name Svg element name
194 * @param integer $x The x attr defines the left position of the element
195 * (e.g. x="0" places the element 0 pixels from the left of the browser window)
196 * @param integer $y The y attribute defines the top position of the element
197 * (e.g. y="0" places the element 0 pixels from the top of the browser window)
198 * @param integer $width The width attribute defines the width the element
199 * @param integer $height The height attribute defines the height the element
200 * @param string $text The text attribute defines the text the element
201 * @param string $styles The style attribute defines the style the element
202 * styles can be defined like CSS styles
204 * @return void
205 * @access public
207 * @see XMLWriter::startElement(), XMLWriter::writeAttribute(),
208 * XMLWriter::text(), XMLWriter::endElement()
210 function printElement($name, $x, $y, $width = '', $height = '', $text = '', $styles = '')
212 $this->startElement($name);
213 $this->writeAttribute('width', $width);
214 $this->writeAttribute('height', $height);
215 $this->writeAttribute('x', $x);
216 $this->writeAttribute('y', $y);
217 $this->writeAttribute('style', $styles);
218 if (isset($text)) {
219 $this->writeAttribute('font-family', $this->font);
220 $this->writeAttribute('font-size', $this->fontSize);
221 $this->text($text);
223 $this->endElement();
227 * Draws Svg Line element
229 * Svg line element is drawn for connecting the tables.
230 * arrows are also drawn by specify its start and ending
231 * co-ordinates
233 * @param string $name Svg element name i.e line
234 * @param integer $x1 Defines the start of the line on the x-axis
235 * @param integer $y1 Defines the start of the line on the y-axis
236 * @param integer $x2 Defines the end of the line on the x-axis
237 * @param integer $y2 Defines the end of the line on the y-axis
238 * @param string $styles The style attribute defines the style the element
239 * styles can be defined like CSS styles
241 * @return void
242 * @access public
244 * @see XMLWriter::startElement(), XMLWriter::writeAttribute(),
245 * XMLWriter::endElement()
247 function printElementLine($name,$x1,$y1,$x2,$y2,$styles)
249 $this->startElement($name);
250 $this->writeAttribute('x1', $x1);
251 $this->writeAttribute('y1', $y1);
252 $this->writeAttribute('x2', $x2);
253 $this->writeAttribute('y2', $y2);
254 $this->writeAttribute('style', $styles);
255 $this->endElement();
259 * get width of string/text
261 * Svg text element width is calcualted depending on font name
262 * and font size. It is very important to know the width of text
263 * because rectangle is drawn around it.
265 * This is a bit hardcore method. I didn't found any other than this.
267 * @param string $text string that width will be calculated
268 * @param integer $font name of the font like Arial,sans-serif etc
269 * @param integer $fontSize size of font
271 * @return integer width of the text
272 * @access public
274 function getStringWidth($text,$font,$fontSize)
277 * Start by counting the width, giving each character a modifying value
279 $count = 0;
280 $count = $count + ((strlen($text) - strlen(str_replace(array("i", "j", "l"), "", $text))) * 0.23);//ijl
281 $count = $count + ((strlen($text) - strlen(str_replace(array("f"), "", $text))) * 0.27);//f
282 $count = $count + ((strlen($text) - strlen(str_replace(array("t", "I"), "", $text))) * 0.28);//tI
283 $count = $count + ((strlen($text) - strlen(str_replace(array("r"), "", $text))) * 0.34);//r
284 $count = $count + ((strlen($text) - strlen(str_replace(array("1"), "", $text))) * 0.49);//1
285 $count = $count + ((strlen($text) - strlen(str_replace(array("c", "k", "s", "v", "x", "y", "z", "J"), "", $text))) * 0.5);//cksvxyzJ
286 $count = $count + ((strlen($text) - strlen(str_replace(array("a", "b", "d", "e", "g", "h", "n", "o", "p", "q", "u", "L", "0", "2", "3", "4", "5", "6", "7", "8", "9"), "", $text))) * 0.56);//abdeghnopquL023456789
287 $count = $count + ((strlen($text) - strlen(str_replace(array("F", "T", "Z"), "", $text))) * 0.61);//FTZ
288 $count = $count + ((strlen($text) - strlen(str_replace(array("A", "B", "E", "K", "P", "S", "V", "X", "Y"), "", $text))) * 0.67);//ABEKPSVXY
289 $count = $count + ((strlen($text) - strlen(str_replace(array("w", "C", "D", "H", "N", "R", "U"), "", $text))) * 0.73);//wCDHNRU
290 $count = $count + ((strlen($text) - strlen(str_replace(array("G", "O", "Q"), "", $text))) * 0.78);//GOQ
291 $count = $count + ((strlen($text) - strlen(str_replace(array("m", "M"), "", $text))) * 0.84);//mM
292 $count = $count + ((strlen($text) - strlen(str_replace("W", "", $text))) * .95);//W
293 $count = $count + ((strlen($text) - strlen(str_replace(" ", "", $text))) * .28);//" "
294 $text = str_replace(" ", "", $text);//remove the " "'s
295 $count = $count + (strlen(preg_replace("/[a-z0-9]/i", "", $text)) * 0.3); //all other chrs
297 $modifier = 1;
298 $font = strtolower($font);
299 switch($font){
301 * no modifier for arial and sans-serif
303 case 'arial':
304 case 'sans-serif':
305 break;
307 * .92 modifer for time, serif, brushscriptstd, and californian fb
309 case 'times':
310 case 'serif':
311 case 'brushscriptstd':
312 case 'californian fb':
313 $modifier = .92;
314 break;
316 * 1.23 modifier for broadway
318 case 'broadway':
319 $modifier = 1.23;
320 break;
322 $textWidth = $count*$fontSize;
323 return ceil($textWidth*$modifier);
328 * Table preferences/statistics
330 * This class preserves the table co-ordinates,fields
331 * and helps in drawing/generating the Tables in SVG XML document.
333 * @name Table_Stats
334 * @see PMA_SVG
336 class Table_Stats
339 * Defines properties
342 private $_tableName;
343 private $_showInfo = false;
345 public $width = 0;
346 public $height;
347 public $fields = array();
348 public $heightCell = 0;
349 public $currentCell = 0;
350 public $x, $y;
351 public $primary = array();
354 * The "Table_Stats" constructor
356 * @param string $tableName The table name
357 * @param string $font Font face
358 * @param integer $fontSize The font size
359 * @param integer $pageNumber Page number
360 * @param integer &$same_wide_width The max. with among tables
361 * @param boolean $showKeys Whether to display keys or not
362 * @param boolean $showInfo Whether to display table position or not
364 * @global object The current SVG image document
365 * @global integer The current page number (from the
366 * $cfg['Servers'][$i]['table_coords'] table)
367 * @global array The relations settings
368 * @global string The current db name
370 * @access private
372 * @see PMA_SVG, Table_Stats::Table_Stats_setWidth,
373 * Table_Stats::Table_Stats_setHeight
375 function __construct($tableName, $font, $fontSize, $pageNumber,
376 &$same_wide_width, $showKeys = false, $showInfo = false)
378 global $svg, $cfgRelation, $db;
380 $this->_tableName = $tableName;
381 $sql = 'DESCRIBE ' . PMA_backquote($tableName);
382 $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE);
383 if (! $result || ! PMA_DBI_num_rows($result)) {
384 $svg->dieSchema(
385 $pageNumber,
386 "SVG",
387 sprintf(__('The %s table doesn\'t exist!'), $tableName)
392 * load fields
393 * check to see if it will load all fields or only the foreign keys
396 if ($showKeys) {
397 $indexes = PMA_Index::getFromTable($this->_tableName, $db);
398 $all_columns = array();
399 foreach ($indexes as $index) {
400 $all_columns = array_merge(
401 $all_columns,
402 array_flip(array_keys($index->getColumns()))
405 $this->fields = array_keys($all_columns);
406 } else {
407 while ($row = PMA_DBI_fetch_row($result)) {
408 $this->fields[] = $row[0];
412 $this->_showInfo = $showInfo;
414 // height and width
415 $this->_setHeightTable($fontSize);
417 // setWidth must me after setHeight, because title
418 // can include table height which changes table width
419 $this->_setWidthTable($font, $fontSize);
420 if ($same_wide_width < $this->width) {
421 $same_wide_width = $this->width;
424 // x and y
425 $sql = 'SELECT x, y FROM '
426 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
427 . PMA_backquote($cfgRelation['table_coords'])
428 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
429 . ' AND table_name = \'' . PMA_sqlAddSlashes($tableName) . '\''
430 . ' AND pdf_page_number = ' . $pageNumber;
431 $result = PMA_query_as_controluser($sql, false, PMA_DBI_QUERY_STORE);
433 if (!$result || !PMA_DBI_num_rows($result)) {
434 $svg->dieSchema(
435 $pageNumber,
436 "SVG",
437 sprintf(
438 __('Please configure the coordinates for table %s'),
439 $tableName
443 list($this->x, $this->y) = PMA_DBI_fetch_row($result);
444 $this->x = (double) $this->x;
445 $this->y = (double) $this->y;
446 // displayfield
447 $this->displayfield = PMA_getDisplayField($db, $tableName);
448 // index
449 $result = PMA_DBI_query(
450 'SHOW INDEX FROM ' . PMA_backquote($tableName) . ';',
451 null,
452 PMA_DBI_QUERY_STORE
454 if (PMA_DBI_num_rows($result) > 0) {
455 while ($row = PMA_DBI_fetch_assoc($result)) {
456 if ($row['Key_name'] == 'PRIMARY') {
457 $this->primary[] = $row['Column_name'];
464 * Returns title of the current table,
465 * title can have the dimensions/co-ordinates of the table
467 * @access private
469 private function _getTitle()
471 return ($this->_showInfo
472 ? sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->heightCell)
473 : ''
474 ) . ' ' . $this->_tableName;
478 * Sets the width of the table
480 * @param string $font The font size
481 * @param integer $fontSize The font size
483 * @global object The current SVG image document
485 * @return nothing
486 * @access private
488 * @see PMA_SVG
490 private function _setWidthTable($font,$fontSize)
492 global $svg;
494 foreach ($this->fields as $field) {
495 $this->width = max(
496 $this->width,
497 $svg->getStringWidth($field, $font, $fontSize)
500 $this->width += $svg->getStringWidth(' ', $font, $fontSize);
503 * it is unknown what value must be added, because
504 * table title is affected by the tabe width value
506 while ($this->width < $svg->getStringWidth($this->_getTitle(), $font, $fontSize)) {
507 $this->width += 7;
512 * Sets the height of the table
514 * @param integer $fontSize font size
516 * @return nothing
517 * @access private
519 function _setHeightTable($fontSize)
521 $this->heightCell = $fontSize + 4;
522 $this->height = (count($this->fields) + 1) * $this->heightCell;
526 * draw the table
528 * @param boolean $showColor Whether to display color
530 * @global object The current SVG image document
532 * @access public
533 * @return nothing
535 * @see PMA_SVG,PMA_SVG::printElement
537 public function tableDraw($showColor)
539 global $svg;
540 //echo $this->_tableName.'<br />';
541 $svg->printElement(
542 'rect', $this->x, $this->y, $this->width,
543 $this->heightCell, null, 'fill:red;stroke:black;'
545 $svg->printElement(
546 'text', $this->x + 5, $this->y+ 14, $this->width, $this->heightCell,
547 $this->_getTitle(), 'fill:none;stroke:black;'
549 foreach ($this->fields as $field) {
550 $this->currentCell += $this->heightCell;
551 $showColor = 'none';
552 if ($showColor) {
553 if (in_array($field, $this->primary)) {
554 $showColor = '#0c0';
556 if ($field == $this->displayfield) {
557 $showColor = 'none';
560 $svg->printElement(
561 'rect', $this->x, $this->y + $this->currentCell, $this->width,
562 $this->heightCell, null, 'fill:'.$showColor.';stroke:black;'
564 $svg->printElement(
565 'text', $this->x + 5, $this->y + 14 + $this->currentCell,
566 $this->width, $this->heightCell, $field, 'fill:none;stroke:black;'
574 * Relation preferences/statistics
576 * This class fetches the table master and foreign fields positions
577 * and helps in generating the Table references and then connects
578 * master table's master field to foreign table's foreign key
579 * in SVG XML document.
581 * @name Relation_Stats
582 * @see PMA_SVG::printElementLine
584 class Relation_Stats
587 * Defines properties
589 public $xSrc, $ySrc;
590 public $srcDir ;
591 public $destDir;
592 public $xDest, $yDest;
593 public $wTick = 10;
596 * The "Relation_Stats" constructor
598 * @param string $master_table The master table name
599 * @param string $master_field The relation field in the master table
600 * @param string $foreign_table The foreign table name
601 * @param string $foreign_field The relation field in the foreign table
603 * @return nothing
605 * @see Relation_Stats::_getXy
607 function __construct($master_table, $master_field, $foreign_table, $foreign_field)
609 $src_pos = $this->_getXy($master_table, $master_field);
610 $dest_pos = $this->_getXy($foreign_table, $foreign_field);
612 * [0] is x-left
613 * [1] is x-right
614 * [2] is y
616 $src_left = $src_pos[0] - $this->wTick;
617 $src_right = $src_pos[1] + $this->wTick;
618 $dest_left = $dest_pos[0] - $this->wTick;
619 $dest_right = $dest_pos[1] + $this->wTick;
621 $d1 = abs($src_left - $dest_left);
622 $d2 = abs($src_right - $dest_left);
623 $d3 = abs($src_left - $dest_right);
624 $d4 = abs($src_right - $dest_right);
625 $d = min($d1, $d2, $d3, $d4);
627 if ($d == $d1) {
628 $this->xSrc = $src_pos[0];
629 $this->srcDir = -1;
630 $this->xDest = $dest_pos[0];
631 $this->destDir = -1;
632 } elseif ($d == $d2) {
633 $this->xSrc = $src_pos[1];
634 $this->srcDir = 1;
635 $this->xDest = $dest_pos[0];
636 $this->destDir = -1;
637 } elseif ($d == $d3) {
638 $this->xSrc = $src_pos[0];
639 $this->srcDir = -1;
640 $this->xDest = $dest_pos[1];
641 $this->destDir = 1;
642 } else {
643 $this->xSrc = $src_pos[1];
644 $this->srcDir = 1;
645 $this->xDest = $dest_pos[1];
646 $this->destDir = 1;
648 $this->ySrc = $src_pos[2];
649 $this->yDest = $dest_pos[2];
653 * Gets arrows coordinates
655 * @param string $table The current table name
656 * @param string $column The relation column name
658 * @return array Arrows coordinates
659 * @access private
661 function _getXy($table, $column)
663 $pos = array_search($column, $table->fields);
664 // x_left, x_right, y
665 return array(
666 $table->x,
667 $table->x + $table->width,
668 $table->y + ($pos + 1.5) * $table->heightCell
673 * draws relation links and arrows shows foreign key relations
675 * @param boolean $changeColor Whether to use one color per relation or not
677 * @global object The current SVG image document
679 * @return nothing
680 * @access public
682 * @see PMA_SVG
684 public function relationDraw($changeColor)
686 global $svg;
688 if ($changeColor) {
689 $listOfColors = array(
690 'red',
691 'grey',
692 'black',
693 'yellow',
694 'green',
695 'cyan',
696 ' orange'
698 shuffle($listOfColors);
699 $color = $listOfColors[0];
700 } else {
701 $color = 'black';
704 $svg->printElementLine(
705 'line', $this->xSrc, $this->ySrc,
706 $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
707 'fill:' . $color . ';stroke:black;stroke-width:2;'
709 $svg->printElementLine(
710 'line', $this->xDest + $this->destDir * $this->wTick,
711 $this->yDest, $this->xDest, $this->yDest,
712 'fill:' . $color . ';stroke:black;stroke-width:2;'
714 $svg->printElementLine(
715 'line', $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc,
716 $this->xDest + $this->destDir * $this->wTick, $this->yDest,
717 'fill:' . $color . ';stroke:' . $color . ';stroke-width:1;'
719 $root2 = 2 * sqrt(2);
720 $svg->printElementLine(
721 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
722 $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
723 $this->ySrc + $this->wTick / $root2,
724 'fill:' . $color . ';stroke:black;stroke-width:2;'
726 $svg->printElementLine(
727 'line', $this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc,
728 $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
729 $this->ySrc - $this->wTick / $root2,
730 'fill:' . $color . ';stroke:black;stroke-width:2;'
732 $svg->printElementLine(
733 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
734 $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
735 $this->yDest + $this->wTick / $root2,
736 'fill:' . $color . ';stroke:black;stroke-width:2;'
738 $svg->printElementLine(
739 'line', $this->xDest + $this->destDir * $this->wTick / 2, $this->yDest,
740 $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
741 $this->yDest - $this->wTick / $root2,
742 'fill:' . $color . ';stroke:black;stroke-width:2;'
747 * end of the "Relation_Stats" class
751 * Svg Relation Schema Class
753 * Purpose of this class is to generate the SVG XML Document because
754 * SVG defines the graphics in XML format which is used for representing
755 * the database diagrams as vector image. This class actually helps
756 * in preparing SVG XML format.
758 * SVG XML is generated by using XMLWriter php extension and this class
759 * inherits Export_Relation_Schema class has common functionality added
760 * to this class
762 * @name Svg_Relation_Schema
764 class PMA_Svg_Relation_Schema extends PMA_Export_Relation_Schema
767 private $tables = array();
768 private $_relations = array();
769 private $_xMax = 0;
770 private $_yMax = 0;
771 private $scale;
772 private $_xMin = 100000;
773 private $_yMin = 100000;
774 private $t_marg = 10;
775 private $b_marg = 10;
776 private $l_marg = 10;
777 private $r_marg = 10;
778 private $_tablewidth;
781 * The "PMA_Svg_Relation_Schema" constructor
783 * Upon instantiation This starts writing the SVG XML document
784 * user will be prompted for download as .svg extension
786 * @return void
787 * @see PMA_SVG
789 function __construct()
791 global $svg,$db;
793 $this->setPageNumber($_POST['pdf_page_number']);
794 $this->setShowColor(isset($_POST['show_color']));
795 $this->setShowKeys(isset($_POST['show_keys']));
796 $this->setTableDimension(isset($_POST['show_table_dimension']));
797 $this->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
798 $this->setExportType($_POST['export_type']);
800 $svg = new PMA_SVG();
801 $svg->setTitle(
802 sprintf(
803 __('Schema of the %s database - Page %s'),
804 $db,
805 $this->pageNumber
808 $svg->SetAuthor('phpMyAdmin ' . PMA_VERSION);
809 $svg->setFont('Arial');
810 $svg->setFontSize('16px');
811 $svg->startSvgDoc('1000px', '1000px');
812 $alltables = $this->getAllTables($db, $this->pageNumber);
814 foreach ($alltables AS $table) {
815 if (! isset($this->tables[$table])) {
816 $this->tables[$table] = new Table_Stats(
817 $table, $svg->getFont(), $svg->getFontSize(), $this->pageNumber,
818 $this->_tablewidth, $this->showKeys, $this->tableDimension
822 if ($this->sameWide) {
823 $this->tables[$table]->width = $this->_tablewidth;
825 $this->_setMinMax($this->tables[$table]);
827 $seen_a_relation = false;
828 foreach ($alltables as $one_table) {
829 $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
830 if ($exist_rel) {
831 $seen_a_relation = true;
832 foreach ($exist_rel as $master_field => $rel) {
833 /* put the foreign table on the schema only if selected
834 * by the user
835 * (do not use array_search() because we would have to
836 * to do a === false and this is not PHP3 compatible)
838 if (in_array($rel['foreign_table'], $alltables)) {
839 $this->_addRelation(
840 $one_table, $svg->getFont(), $svg->getFontSize(),
841 $master_field, $rel['foreign_table'],
842 $rel['foreign_field'], $this->tableDimension
848 if ($seen_a_relation) {
849 $this->_drawRelations($this->showColor);
852 $this->_drawTables($this->showColor);
853 $svg->endSvgDoc();
854 $svg->showOutput($db.'-'.$this->pageNumber);
855 exit();
859 * Sets X and Y minimum and maximum for a table cell
861 * @param string $table The table name
863 * @return nothing
864 * @access private
866 private function _setMinMax($table)
868 $this->_xMax = max($this->_xMax, $table->x + $table->width);
869 $this->_yMax = max($this->_yMax, $table->y + $table->height);
870 $this->_xMin = min($this->_xMin, $table->x);
871 $this->_yMin = min($this->_yMin, $table->y);
875 * Defines relation objects
877 * @param string $masterTable The master table name
878 * @param string $font The font face
879 * @param int $fontSize Font size
880 * @param string $masterField The relation field in the master table
881 * @param string $foreignTable The foreign table name
882 * @param string $foreignField The relation field in the foreign table
883 * @param boolean $showInfo Whether to display table position or not
885 * @access private
886 * @return nothing
888 * @see _setMinMax,Table_Stats::__construct(),Relation_Stats::__construct()
890 private function _addRelation($masterTable,$font,$fontSize, $masterField,
891 $foreignTable, $foreignField, $showInfo)
893 if (! isset($this->tables[$masterTable])) {
894 $this->tables[$masterTable] = new Table_Stats(
895 $masterTable, $font, $fontSize, $this->pageNumber,
896 $this->_tablewidth, false, $showInfo
898 $this->_setMinMax($this->tables[$masterTable]);
900 if (! isset($this->tables[$foreignTable])) {
901 $this->tables[$foreignTable] = new Table_Stats(
902 $foreignTable, $font, $fontSize, $this->pageNumber,
903 $this->_tablewidth, false, $showInfo
905 $this->_setMinMax($this->tables[$foreignTable]);
907 $this->_relations[] = new Relation_Stats(
908 $this->tables[$masterTable], $masterField,
909 $this->tables[$foreignTable], $foreignField
914 * Draws relation arrows and lines
915 * connects master table's master field to
916 * foreign table's forein field
918 * @param boolean $changeColor Whether to use one color per relation or not
920 * @return nothing
921 * @access private
923 * @see Relation_Stats::relationDraw()
925 private function _drawRelations($changeColor)
927 foreach ($this->_relations as $relation) {
928 $relation->relationDraw($changeColor);
933 * Draws tables
935 * @param boolean $changeColor Whether to show color for primary fields or not
937 * @return nothing
938 * @access private
940 * @see Table_Stats::Table_Stats_tableDraw()
942 private function _drawTables($changeColor)
944 foreach ($this->tables as $table) {
945 $table->tableDraw($changeColor);