RelationStatsSvg.php 4.2 KB

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