RelationStatsSvg.class.php 3.9 KB

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