TableStatsSvg.class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains Table_Stats_Svg class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. require_once 'libraries/plugins/schema/TableStats.class.php';
  12. /**
  13. * Table preferences/statistics
  14. *
  15. * This class preserves the table co-ordinates,fields
  16. * and helps in drawing/generating the Tables in SVG XML document.
  17. *
  18. * @package PhpMyAdmin
  19. * @name Table_Stats_Svg
  20. * @see PMA_SVG
  21. */
  22. class Table_Stats_Svg extends TableStats
  23. {
  24. /**
  25. * Defines properties
  26. */
  27. public $height;
  28. public $currentCell = 0;
  29. /**
  30. * The "Table_Stats_Svg" constructor
  31. *
  32. * @param object $diagram The current SVG image document
  33. * @param string $db The database name
  34. * @param string $tableName The table name
  35. * @param string $font Font face
  36. * @param integer $fontSize The font size
  37. * @param integer $pageNumber Page number
  38. * @param integer &$same_wide_width The max. with among tables
  39. * @param boolean $showKeys Whether to display keys or not
  40. * @param boolean $tableDimension Whether to display table position or not
  41. * @param boolean $offline Whether the coordinates are sent
  42. *
  43. *
  44. * @see PMA_SVG, Table_Stats_Svg::Table_Stats_setWidth,
  45. * Table_Stats_Svg::Table_Stats_setHeight
  46. */
  47. public function __construct(
  48. $diagram, $db, $tableName, $font, $fontSize, $pageNumber, &$same_wide_width,
  49. $showKeys = false, $tableDimension = false, $offline = false
  50. ) {
  51. parent::__construct(
  52. $diagram, $db, $pageNumber, $tableName,
  53. $showKeys, $tableDimension, $offline
  54. );
  55. // height and width
  56. $this->_setHeightTable($fontSize);
  57. // setWidth must me after setHeight, because title
  58. // can include table height which changes table width
  59. $this->_setWidthTable($font, $fontSize);
  60. if ($same_wide_width < $this->width) {
  61. $same_wide_width = $this->width;
  62. }
  63. }
  64. /**
  65. * Displays an error when the table cannot be found.
  66. *
  67. * @return void
  68. */
  69. protected function showMissingTableError()
  70. {
  71. PMA_Export_Relation_Schema::dieSchema(
  72. $this->pageNumber,
  73. "SVG",
  74. sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
  75. );
  76. }
  77. /**
  78. * Sets the width of the table
  79. *
  80. * @param string $font The font size
  81. * @param integer $fontSize The font size
  82. *
  83. * @return void
  84. * @access private
  85. *
  86. * @see PMA_SVG
  87. */
  88. private function _setWidthTable($font,$fontSize)
  89. {
  90. foreach ($this->fields as $field) {
  91. $this->width = max(
  92. $this->width,
  93. PMA_Font::getStringWidth($field, $font, $fontSize)
  94. );
  95. }
  96. $this->width += PMA_Font::getStringWidth(' ', $font, $fontSize);
  97. /*
  98. * it is unknown what value must be added, because
  99. * table title is affected by the table width value
  100. */
  101. while ($this->width
  102. < PMA_Font::getStringWidth($this->getTitle(), $font, $fontSize)
  103. ) {
  104. $this->width += 7;
  105. }
  106. }
  107. /**
  108. * Sets the height of the table
  109. *
  110. * @param integer $fontSize font size
  111. *
  112. * @return void
  113. */
  114. private function _setHeightTable($fontSize)
  115. {
  116. $this->heightCell = $fontSize + 4;
  117. $this->height = (count($this->fields) + 1) * $this->heightCell;
  118. }
  119. /**
  120. * draw the table
  121. *
  122. * @param boolean $showColor Whether to display color
  123. *
  124. * @access public
  125. * @return void
  126. *
  127. * @see PMA_SVG,PMA_SVG::printElement
  128. */
  129. public function tableDraw($showColor)
  130. {
  131. $this->diagram->printElement(
  132. 'rect', $this->x, $this->y, $this->width,
  133. $this->heightCell, null, 'fill:#007;stroke:black;'
  134. );
  135. $this->diagram->printElement(
  136. 'text', $this->x + 5, $this->y+ 14, $this->width, $this->heightCell,
  137. $this->getTitle(), 'fill:#fff;'
  138. );
  139. foreach ($this->fields as $field) {
  140. $this->currentCell += $this->heightCell;
  141. $fillColor = 'none';
  142. if ($showColor) {
  143. if (in_array($field, $this->primary)) {
  144. $fillColor = '#aea';
  145. }
  146. if ($field == $this->displayfield) {
  147. $fillColor = 'none';
  148. }
  149. }
  150. $this->diagram->printElement(
  151. 'rect', $this->x, $this->y + $this->currentCell, $this->width,
  152. $this->heightCell, null, 'fill:' . $fillColor . ';stroke:black;'
  153. );
  154. $this->diagram->printElement(
  155. 'text', $this->x + 5, $this->y + 14 + $this->currentCell,
  156. $this->width, $this->heightCell, $field, 'fill:black;'
  157. );
  158. }
  159. }
  160. }