RelationStatsPdf.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains Relation_Stats_Pdf 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 PDF document.
  19. *
  20. * @name Relation_Stats_Pdf
  21. * @package PhpMyAdmin
  22. * @see PMA_Schema_PDF::SetDrawColor, PMA_Schema_PDF::setLineWidthScale,
  23. * PMA_Schema_PDF::lineScale
  24. */
  25. class Relation_Stats_Pdf extends RelationStats
  26. {
  27. /**
  28. * The "Relation_Stats_Pdf" constructor
  29. *
  30. * @param object $diagram The PDF diagram
  31. * @param string $master_table The master table name
  32. * @param string $master_field The relation field in the master table
  33. * @param string $foreign_table The foreign table name
  34. * @param string $foreign_field The relation field in the foreign table
  35. */
  36. public function __construct(
  37. $diagram, $master_table, $master_field, $foreign_table,
  38. $foreign_field
  39. ) {
  40. $this->wTick = 5;
  41. parent::__construct(
  42. $diagram, $master_table, $master_field, $foreign_table, $foreign_field
  43. );
  44. }
  45. /**
  46. * draws relation links and arrows shows foreign key relations
  47. *
  48. * @param boolean $showColor Whether to use one color per relation or not
  49. * @param integer $i The id of the link to draw
  50. *
  51. * @access public
  52. *
  53. * @return void
  54. *
  55. * @see PMA_Schema_PDF
  56. */
  57. public function relationDraw($showColor, $i)
  58. {
  59. if ($showColor) {
  60. $d = $i % 6;
  61. $j = ($i - $d) / 6;
  62. $j = $j % 4;
  63. $j++;
  64. $case = array(
  65. array(1, 0, 0),
  66. array(0, 1, 0),
  67. array(0, 0, 1),
  68. array(1, 1, 0),
  69. array(1, 0, 1),
  70. array(0, 1, 1)
  71. );
  72. list ($a, $b, $c) = $case[$d];
  73. $e = (1 - ($j - 1) / 6);
  74. $this->diagram->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e);
  75. } else {
  76. $this->diagram->SetDrawColor(0);
  77. }
  78. $this->diagram->setLineWidthScale(0.2);
  79. $this->diagram->lineScale(
  80. $this->xSrc,
  81. $this->ySrc,
  82. $this->xSrc + $this->srcDir * $this->wTick,
  83. $this->ySrc
  84. );
  85. $this->diagram->lineScale(
  86. $this->xDest + $this->destDir * $this->wTick,
  87. $this->yDest,
  88. $this->xDest,
  89. $this->yDest
  90. );
  91. $this->diagram->setLineWidthScale(0.1);
  92. $this->diagram->lineScale(
  93. $this->xSrc + $this->srcDir * $this->wTick,
  94. $this->ySrc,
  95. $this->xDest + $this->destDir * $this->wTick,
  96. $this->yDest
  97. );
  98. /*
  99. * Draws arrows ->
  100. */
  101. $root2 = 2 * sqrt(2);
  102. $this->diagram->lineScale(
  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. );
  108. $this->diagram->lineScale(
  109. $this->xSrc + $this->srcDir * $this->wTick * 0.75,
  110. $this->ySrc,
  111. $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
  112. $this->ySrc - $this->wTick / $root2
  113. );
  114. $this->diagram->lineScale(
  115. $this->xDest + $this->destDir * $this->wTick / 2,
  116. $this->yDest,
  117. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  118. $this->yDest + $this->wTick / $root2
  119. );
  120. $this->diagram->lineScale(
  121. $this->xDest + $this->destDir * $this->wTick / 2,
  122. $this->yDest,
  123. $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
  124. $this->yDest - $this->wTick / $root2
  125. );
  126. $this->diagram->SetDrawColor(0);
  127. }
  128. }