Skip to content

Commit

Permalink
Now lets viewer determine whether to see one or two degrees of separa…
Browse files Browse the repository at this point in the history
…tion on table details
  • Loading branch information
johncurrier committed May 15, 2005
1 parent e685e0a commit 5d01800
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/net/sourceforge/schemaspy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ else if (maxThreads == 0)
System.out.print('.');
Table table = (Table)iter.next();
out = new LineWriter(new FileWriter(new File(outputDir, "tables/" + table.getName() + ".html")), 24 * 1024);
hasImplied |= tableFormatter.write(db, table, outputDir, out);
hasImplied |= tableFormatter.write(db, table, outputDir, 1, out).wroteImplied();
out.close();
}

Expand Down
37 changes: 22 additions & 15 deletions src/net/sourceforge/schemaspy/view/DotFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ public class DotFormatter {
* @throws IOException
* @return boolean <code>true</code> if implied relationships were written
*/
public boolean writeRelationships(Table table, boolean includeImplied, LineWriter out) throws IOException {
public WriteStats writeRelationships(Table table, boolean includeImplied, boolean twoDegreesOfSeparation, LineWriter out) throws IOException {
Set tablesWritten = new HashSet();
WriteStats stats = new WriteStats();
boolean[] wroteImplied = new boolean[1];

DotTableFormatter formatter = new DotTableFormatter();

writeDotHeader(includeImplied ? "allRelationshipsGraph" : "realRelationshipsGraph", out);
writeDotHeader(includeImplied ? "allRelationshipsGraph" : (twoDegreesOfSeparation ? "realRelationshipsGraph" : "focusedRelationshipsGraph"), out);

Set relatedTables = getImmediateRelatives(table, includeImplied, wroteImplied);

formatter.writeNode(table, "", true, true, true, out);
Set relationships = formatter.getRelationships(table, includeImplied);
tablesWritten.add(table);
stats.wroteTable(table);

// write immediate relatives first
Iterator iter = relatedTables.iterator();
Expand All @@ -47,22 +49,26 @@ public boolean writeRelationships(Table table, boolean includeImplied, LineWrite
continue; // already written

formatter.writeNode(relatedTable, "", true, false, false, out);
stats.wroteTable(relatedTable);
relationships.addAll(formatter.getRelationships(relatedTable, table, includeImplied));
}

// next write 'cousins' (2nd degree of separation)
iter = relatedTables.iterator();
while (iter.hasNext()) {
Table relatedTable = (Table)iter.next();
Set cousins = getImmediateRelatives(relatedTable, includeImplied, wroteImplied);

Iterator cousinsIter = cousins.iterator();
while (cousinsIter.hasNext()) {
Table cousin = (Table)cousinsIter.next();
if (!tablesWritten.add(cousin))
continue; // already written
relationships.addAll(formatter.getRelationships(cousin, relatedTable, includeImplied));
formatter.writeNode(cousin, "", false, false, false, out);
if (twoDegreesOfSeparation) {
iter = relatedTables.iterator();
while (iter.hasNext()) {
Table relatedTable = (Table)iter.next();
Set cousins = getImmediateRelatives(relatedTable, includeImplied, wroteImplied);

Iterator cousinsIter = cousins.iterator();
while (cousinsIter.hasNext()) {
Table cousin = (Table)cousinsIter.next();
if (!tablesWritten.add(cousin))
continue; // already written
relationships.addAll(formatter.getRelationships(cousin, relatedTable, includeImplied));
formatter.writeNode(cousin, "", false, false, false, out);
stats.wroteTable(cousin);
}
}
}

Expand All @@ -71,7 +77,8 @@ public boolean writeRelationships(Table table, boolean includeImplied, LineWrite
out.writeln(iter.next().toString());

out.writeln("}");
return wroteImplied[0];
stats.setWroteImplied(wroteImplied[0]);
return stats;
}

/**
Expand Down
44 changes: 34 additions & 10 deletions src/net/sourceforge/schemaspy/view/HtmlGraphFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,50 @@
public class HtmlGraphFormatter extends HtmlFormatter {
private static boolean printedNoDotWarning = false;

public boolean write(Table table, File graphDir, boolean hasImpliedRelationships, LineWriter html) {
public boolean write(Table table, File graphDir, WriteStats stats, LineWriter html) {
File dotFile = new File(graphDir, table.getName() + ".dot");
File allDotFile = new File(graphDir, table.getName() + "_all_.dot");
File graphFile = new File(graphDir, table.getName() + ".png");
File allDotFile = new File(graphDir, table.getName() + "_all_.dot");
File allGraphFile = new File(graphDir, table.getName() + "_all_.png");
File focusedDotFile = new File(graphDir, table.getName() + "_focused_.dot");
File focusedGraphFile = new File(graphDir, table.getName() + "_focused_.png");

try {
if (!DotRunner.generateGraph(dotFile, graphFile))
return false;

html.write("<br/><b title='Tables/views within two degrees of separation from ");
html.write(table.getName());
html.write("'>Close relationships:</b><br/>");

html.writeln(" <a name='graph'><img src=\"../graphs/" + graphFile.getName() + "\" usemap=\"#realRelationshipsGraph\" id='relationships' border=\"0\" alt=\"\"></a>");
html.write("'>Close relationships</b>");
if (stats.wroteFocused()) {
html.writeln("<span class='degrees' id='degrees'>");
html.write("&nbsp;&nbsp;within <input type='radio' name='degrees' id='oneDegree' onclick=\"");
html.write("if (!this.checked)");
html.write(" selectGraph('../graphs/" + graphFile.getName() + "', '#realRelationshipsGraph'); ");
html.write("else");
html.write(" selectGraph('../graphs/" + focusedGraphFile.getName() + "', '#focusedRelationshipsGraph');");
html.writeln("\" checked>one");
html.write(" <input type='radio' name='degrees' id='twoDegrees' onclick=\"");
html.write("if (this.checked)");
html.write(" selectGraph('../graphs/" + graphFile.getName() + "', '#realRelationshipsGraph'); ");
html.write("else");
html.write(" selectGraph('../graphs/" + focusedGraphFile.getName() + "', '#focusedRelationshipsGraph');");
html.writeln("\">two degrees of separation");
html.writeln("</span><b>:</b>");
}
String map = stats.wroteFocused() ? "#focusedRelationshipsGraph" : "#realRelationshipsGraph";
if (stats.wroteFocused())
graphFile = focusedGraphFile;
html.writeln(" <a name='graph'><img src='../graphs/" + graphFile.getName() + "' usemap='" + map + "' id='relationships' border='0' alt='' align='left'></a>");
DotRunner.writeMap(dotFile, html);
if (hasImpliedRelationships) {
if (stats.wroteImplied()) {
DotRunner.generateGraph(allDotFile, allGraphFile);
DotRunner.writeMap(allDotFile, html);
}
if (stats.wroteFocused()) {
DotRunner.generateGraph(focusedDotFile, focusedGraphFile);
DotRunner.writeMap(focusedDotFile, html);
}
} catch (IOException noDot) {
printNoDotWarning();
return false;
Expand All @@ -53,7 +77,7 @@ public boolean write(Database db, File graphDir, String dotBaseFilespec, boolean
return false;

writeRelationshipsHeader(db, graphFile, allGraphFile, "Relationships Graph", hasImpliedRelationships, html);
html.writeln(" <a name='graph'><img src=\"graphs/summary/" + graphFile.getName() + "\" usemap=\"#realRelationshipsGraph\" id='relationships' border=\"0\" alt=\"\"></a>");
html.writeln(" <a name='graph'><img src='graphs/summary/" + graphFile.getName() + "' usemap='#realRelationshipsGraph' id='relationships' border='0' alt=''></a>");
DotRunner.writeMap(dotFile, html);

if (hasImpliedRelationships) {
Expand Down Expand Up @@ -103,7 +127,7 @@ public boolean writeOrphans(Database db, List orphanTables, File graphDir, LineW
return false;
}

html.write(" <img src=\"graphs/summary/" + graphFile.getName() + "\" usemap=\"#" + table + "\" border=\"0\" alt=\"\" align=\"top\"");
html.write(" <img src='graphs/summary/" + graphFile.getName() + "' usemap='#" + table + "' border='0' alt='' align='top'");
if (orphansWithImpliedRelationships.contains(table))
html.write(" class='impliedNotOrphan'");
html.writeln(">");
Expand All @@ -128,7 +152,7 @@ public boolean writeOrphans(Database db, List orphanTables, File graphDir, LineW
private void writeRelationshipsHeader(Database db, File graphFile, File allGraphFile, String title, boolean hasImpliedRelationships, LineWriter html) throws IOException {
writeHeader(db, null, title, html);
html.writeln("<table width='100%'><tr><td class='tableHolder' align='left' valign='top'>");
html.writeln("<br/><a href='index.html'>Tables</a>");
html.writeln("<br/><a href='index.html'>Back to Tables</a>");
if (hasImpliedRelationships) {
html.writeln("<p/><form action=''>");
html.write(" <input type='checkbox' id='graphType' onclick=\"if (!this.checked) selectGraph('graphs/summary/" + graphFile.getName() + "', '#realRelationshipsGraph'); else selectGraph('graphs/summary/" + allGraphFile.getName() + "', '#allRelationshipsGraph');\">");
Expand All @@ -144,7 +168,7 @@ private void writeRelationshipsHeader(Database db, File graphFile, File allGraph
private void writeOrphansHeader(Database db, String title, boolean hasImpliedRelationships, LineWriter html) throws IOException {
writeHeader(db, null, title, html);
html.writeln("<table width='100%'><tr><td class='tableHolder' align='left' valign='top'>");
html.writeln("<br/><a href='index.html'>Tables</a>");
html.writeln("<br/><a href='index.html'>Back to Tables</a>");
if (hasImpliedRelationships) {
html.writeln("<p/><form action=''>");
html.writeln(" <input type=checkbox onclick=\"toggle(" + StyleSheet.getOffsetOf(".impliedNotOrphan") + ");\" id=removeImpliedOrphans>");
Expand Down
30 changes: 24 additions & 6 deletions src/net/sourceforge/schemaspy/view/JavaScriptFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ public void write(LineWriter out) throws IOException {
out.writeln(" cb.checked=true;");
out.writeln(" cb.click();");
out.writeln(" }");
out.writeln(" }");
out.writeln(" var graphType = document.getElementById('graphType');");
out.writeln(" if (graphType) {");
out.writeln(" if (graphType.checked) {");
out.writeln(" graphType.checked=false;");
out.writeln(" graphType.click();");
out.writeln(" cb = options.graphType;");
out.writeln(" if (cb.checked) {");
out.writeln(" cb.checked=false;");
out.writeln(" cb.click();");
out.writeln(" }");
out.writeln(" }");
out.writeln(" var removeImpliedOrphans = document.getElementById('removeImpliedOrphans');");
Expand All @@ -55,6 +53,26 @@ public void write(LineWriter out) throws IOException {
out.writeln(" removeImpliedOrphans.click();");
out.writeln(" }");
out.writeln(" }");
out.writeln(" syncDegrees();");
out.writeln("}");
out.writeln("");
out.writeln("function syncDegrees() {");
out.writeln(" var rules = document.styleSheets[0].cssRules;");
out.writeln(" if (rules == null) rules = document.styleSheets[0].rules;");
out.writeln(" var degreesStyle = rules[" + StyleSheet.getOffsetOf(".degrees")+ "].style;");
out.writeln(" if (degreesStyle.display != 'none') {");
out.writeln(" var degrees = document.getElementById('degrees');");
out.writeln(" var oneDegree = document.getElementById('oneDegree');");
out.writeln(" var twoDegrees = document.getElementById('twoDegrees');");
out.writeln(" var useMap = document.getElementById('relationships').useMap;");
out.writeln(" if (oneDegree.checked && useMap != '#focusedRelationshipsGraph') {");
out.writeln(" oneDegree.checked=false;");
out.writeln(" oneDegree.click();");
out.writeln(" } else if (twoDegrees.checked && useMap != '#realRelationshipsGraph') {");
out.writeln(" twoDegrees.checked=false;");
out.writeln(" twoDegrees.click();");
out.writeln(" }");
out.writeln(" }");
out.writeln("}");
}
}
3 changes: 3 additions & 0 deletions src/schemaSpy.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ table {
.impliedNotOrphan {
}

.degrees {
}

a:link {
color: #489148;
}
Expand Down

0 comments on commit 5d01800

Please sign in to comment.