RelationStatsSvg.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\Svg\RelationStatsSvg class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Plugins\Schema\Svg;
  9. use PhpMyAdmin\Plugins\Schema\RelationStats;
  10. /**
  11. * Relation preferences/statistics
  12. *
  13. * This class fetches the table master and foreign fields positions
  14. * and helps in generating the Table references and then connects
  15. * master table's master field to foreign table's foreign key
  16. * in SVG XML document.
  17. *
  18. * @package PhpMyAdmin
  19. * @name Relation_Stats_Svg
  20. * @see PMA_SVG::printElementLine
  21. */
  22. class RelationStatsSvg extends RelationStats
  23. {
  24. /**
  25. * The "PhpMyAdmin\Plugins\Schema\Svg\RelationStatsSvg" constructor
  26. *
  27. * @param object $diagram The SVG diagram
  28. * @param string $master_table The master table name
  29. * @param string $master_field The relation field in the master table
  30. * @param string $foreign_table The foreign table name
  31. * @param string $foreign_field The relation field in the foreign table
  32. */
  33. public function __construct(
  34. $diagram,
  35. $master_table,
  36. $master_field,
  37. $foreign_table,
  38. $foreign_field
  39. ) {
  40. $this->wTick = 10;
  41. parent::__construct(
  42. $diagram,
  43. $master_table,
  44. $master_field,
  45. $foreign_table,
  46. $foreign_field
  47. );
  48. }
  49. /**
  50. * draws relation links and arrows shows foreign key relations
  51. *
  52. * @param boolean $showColor Whether to use one color per relation or not
  53. *
  54. * @return void
  55. * @access public
  56. *
  57. * @see PMA_SVG
  58. */
  59. public function relationDraw($showColor)
  60. {
  61. if ($showColor) {
  62. $listOfColors = array(
  63. '#c00',
  64. '#bbb',
  65. '#333',
  66. '#cb0',
  67. '#0b0',
  68. '#0bf',
  69. '#b0b',
  70. );
  71. shuffle($listOfColors);
  72. $color = $listOfColors[0];
  73. } else {
  74. $color = '#333';
  75. }
  76. $this->diagram->printElementLine(
  77. 'line',
  78. $this->xSrc,
  79. $this->ySrc,
  80. $this->xSrc + $this->srcDir * $this->wTick,
  81. $this->ySrc,
  82. 'stroke:' . $color . ';stroke-width:1;'
  83. );
  84. $this->diagram->printElementLine(
  85. 'line',
  86. $this->xDest + $this->destDir * $this->wTick,
  87. $this->yDest,
  88. $this->xDest,
  89. $this->yDest,
  90. 'stroke:' . $color . ';stroke-width:1;'
  91. );
  92. $this->diagram->printElementLine(
  93. 'line',
  94. $this->xSrc + $this->srcDir * $this->wTick,
  95. $this->ySrc,
  96. $this->xDest + $this->destDir * $this->wTick,
  97. $this->yDest,
  98. 'stroke:' . $color . ';stroke-width:1;'
  99. );
  100. $root2 = 2 * sqrt(2);
  101. $this->diagram->printElementLine(
  102. 'line',
  103. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  104. $this->ySrc,
  105. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  106. $this->ySrc + $this->wTick / $root2,
  107. 'stroke:' . $color . ';stroke-width:2;'
  108. );
  109. $this->diagram->printElementLine(
  110. 'line',
  111. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  112. $this->ySrc,
  113. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  114. $this->ySrc - $this->wTick / $root2,
  115. 'stroke:' . $color . ';stroke-width:2;'
  116. );
  117. $this->diagram->printElementLine(
  118. 'line',
  119. $this->xDest + $this->destDir * $this->wTick / 2,
  120. $this->yDest,
  121. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  122. $this->yDest + $this->wTick / $root2,
  123. 'stroke:' . $color . ';stroke-width:2;'
  124. );
  125. $this->diagram->printElementLine(
  126. 'line',
  127. $this->xDest + $this->destDir * $this->wTick / 2,
  128. $this->yDest,
  129. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  130. $this->yDest - $this->wTick / $root2,
  131. 'stroke:' . $color . ';stroke-width:2;'
  132. );
  133. }
  134. }