Position lines

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@268 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-27 06:24:59 +00:00
parent 438ca058ef
commit 7c22767dd5

View file

@ -5,12 +5,12 @@ $table_pos = array();
$table_pos_js = array();
preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~', $_COOKIE["schema"], $matches, PREG_SET_ORDER); //! ':' in table name
foreach ($matches as $i => $match) {
$table_pos[$match[1]] = "$match[2]em; left: $match[3]";
$table_pos[$match[1]] = array($match[2], $match[3]);
$table_pos_js[] = "\n\t'" . addcslashes($match[1], "\r\n'\\") . "': [ $match[2], $match[3] ]";
}
$top = 0;
$left = -14;
$base_left = -.9;
$schema = array();
$referenced = array();
$result = $mysql->query("SHOW TABLE STATUS");
@ -25,17 +25,22 @@ while ($row = $result->fetch_assoc()) {
$field["pos"] = $pos;
$schema[$row["Name"]]["fields"][$name] = $field;
}
$schema[$row["Name"]]["pos"] = ($table_pos[$row["Name"]] ? $table_pos[$row["Name"]] : $top);
$schema[$row["Name"]]["pos"] = ($table_pos[$row["Name"]] ? $table_pos[$row["Name"]] : array($top, 0));
if ($row["Engine"] == "InnoDB") {
foreach (foreign_keys($row["Name"]) as $val) {
if (!$val["db"]) {
$schema[$row["Name"]]["references"][$val["table"]][$left] = array_combine($val["source"], $val["target"]);
$referenced[$val["table"]][$left] = $val["target"];
$left -= 2;
if ($table_pos[$row["Name"]][1] || $table_pos[$row["Name"]][1]) {
$left = min($table_pos[$row["Name"]][1], $table_pos[$val["table"]][1]) - .9;
} else {
$left = $base_left;
$base_left -= .1;
}
$schema[$row["Name"]]["references"][$val["table"]][10000 * $left] = array_combine($val["source"], $val["target"]);
$referenced[$val["table"]][10000 * $left] = $val["target"];
}
}
}
$top = max($top, $schema[$row["Name"]]["pos"] + 2.5 + $pos);
$top = max($top, $schema[$row["Name"]]["pos"][0] + 2.5 + $pos);
}
$result->free();
@ -46,7 +51,7 @@ var table_pos = {<?php echo implode(",", $table_pos_js) . "\n"; ?>};
function mousedown(el, event) {
that = el;
em = document.getElementById('breadcrumb').offsetHeight / 1.25;
em = document.getElementById('schema').offsetHeight / <?php echo $top; ?>;
x = event.clientX - el.offsetLeft;
y = event.clientY - el.offsetTop;
}
@ -75,7 +80,7 @@ function mouseup(event) {
<div id="schema" style="height: <?php echo $top; ?>em;" onmousemove="mousemove(event);" onmouseup="mouseup(event);">
<?php
foreach ($schema as $name => $table) {
echo "<div class='table' style='top: $table[pos]em;' onmousedown='mousedown(this, event);'>";
echo "<div class='table' style='top: " . $table["pos"][0] . "em; left: " . $table["pos"][1] . "em;' onmousedown='mousedown(this, event);'>";
echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($name) . '"><strong>' . htmlspecialchars($name) . "</strong></a><br />\n";
foreach ($table["fields"] as $field) {
$val = htmlspecialchars($field["field"]);
@ -92,14 +97,16 @@ foreach ($schema as $name => $table) {
}
foreach ((array) $table["references"] as $target_name => $refs) {
foreach ($refs as $left => $columns) {
$left = $left / 10000 - $table_pos[$name][1];
foreach ($columns as $source => $target) {
echo "<div class='references' style='left: " . ($left+1) . "px; top: " . $table["fields"][$source]["pos"] . "em; padding-top: .5em;'><div style='border-top: 1px solid Black; width: " . (-$left-2) . "px;'></div></div>\n";
echo "<div class='references' style='left: $left" . "em; top: " . $table["fields"][$source]["pos"] . "em; padding-top: .5em;'><div style='border-top: 1px solid Black; width: " . (-$left) . "em;'></div></div>\n";
}
}
}
foreach ((array) $referenced[$name] as $left => $columns) {
$left = $left / 10000 - $table_pos[$name][1];
foreach ($columns as $target) {
echo "<div class='references' style='left: " . ($left+1) . "px; top: " . $table["fields"][$target]["pos"] . "em; width: " . (-$left-2) . "px; height: 1.25em; background: url(arrow.gif) no-repeat right center;'><div style='height: .5em; border-bottom: 1px solid Black; width: " . (-$left-14) . "px;'></div></div>\n";
echo "<div class='references' style='left: $left" . "em; top: " . $table["fields"][$target]["pos"] . "em; width: " . (-$left) . "em; height: 1.25em; background: url(arrow.gif) no-repeat right center;'><div style='height: .5em; border-bottom: 1px solid Black; width: " . (-$left) . "em;'></div></div>\n";
}
}
echo "</div>\n";
@ -107,15 +114,16 @@ foreach ($schema as $name => $table) {
foreach ($schema as $name => $table) {
foreach ((array) $table["references"] as $target_name => $refs) {
foreach ($refs as $left => $ref) {
$left /= 10000;
$min_pos = $top;
$max_pos = -10;
foreach ($ref as $source => $target) {
$pos1 = $table["pos"] + $table["fields"][$source]["pos"];
$pos2 = $schema[$target_name]["pos"] + $schema[$target_name]["fields"][$target]["pos"];
$pos1 = $table["pos"][0] + $table["fields"][$source]["pos"];
$pos2 = $schema[$target_name]["pos"][0] + $schema[$target_name]["fields"][$target]["pos"];
$min_pos = min($min_pos, $pos1, $pos2);
$max_pos = max($max_pos, $pos1, $pos2);
}
echo "<div class='references' style='left: $left" . "px; top: $min_pos" . "em; padding: .5em 0;' /><div style='border-right: 1px solid Black; height: " . ($max_pos - $min_pos) . "em;'></div></div>\n";
echo "<div class='references' style='left: $left" . "em; top: $min_pos" . "em; padding: .5em 0;' /><div style='border-right: 1px solid Black; height: " . ($max_pos - $min_pos) . "em;'></div></div>\n";
}
}
}