Allow the dot file's graph beginning to be customized
Hi,
It would be great if we could customize the GRAPH_BEGINNING.
I have a SQLite database that we are trying to generate a diagram automatically for our documentation. eralchemy works great, but the final layout uses some default dot settings that may not play well if different DB schemas.
I believe this could provide workarounds for #41 and #39.
Here's what I get when I run eralchemy with our current schema.

By changing the graph beginning manually (and I am now in the progress of monkey-patching eralchemy), I get a landscape output, and can also control the space between nodes/edges in the graph. The result then is:

@kinow Can you please share what you exactly did to get that nice horizontal diagram?
...Can you please share what you exactly did to get that nice horizontal diagram?
I'm interested in this too, but until someone works up a viable pull request for this, you can do the following crappy ad hoc solution: modify the global value GRAPH_BEGINNING which can be found in the project's eralchemy/eralchemy/cst.py file.
What to do:
Hard way:
You can do this programmatically if you want to dirty your hands with building eralchemy's Abstract Syntax Tree (AST) at runtime. This would see you build the AST, then modify the rvalue of the GRAPH_BEGINNING member, then overwrite the cst.py file with the updated AST.
Easy way:
But if you just want a quick and easy solution, you can just navigate to the file manually and make the modifications in a text editor ;).
Here's an explanation for the easy approach:
GRAPH_BEGINNING sets up instructions that pygraphviz uses in configuring the graph image. As such it specifies properties like rankdir. You will want to modify the value assigned to rankdir to be TB in order to get output like what is seen in the final image from OP.
Here's the literal example:
contents of ~/eralchemy/cst.py
# -*- coding: utf-8 -*-
"""
All the constants used in the module.
"""
TABLE = '"{}" [label=<<FONT FACE="Helvetica"><TABLE BORDER="0" CELLBORDER="1"' \
' CELLPADDING="4" CELLSPACING="0">{}{}</TABLE></FONT>>];'
START_CELL = '<TR><TD ALIGN="LEFT"><FONT>'
FONT_TAGS = '<FONT>{}</FONT>'
# Used for each row in the table.
ROW_TAGS = '<TR><TD{}>{}</TD></TR>'
# commenting out original value of GRAPH_BEGINNING
# GRAPH_BEGINNING = (' graph {\n'
# ' graph [rankdir=LR];\n' # notice that rankdir=LR is the `eralchemy` default
# ' node [label=\"\\N\",\n'
# ' shape=plaintext\n'
# ' ];\n'
# ' edge [color=gray50,\n'
# ' minlen=2,\n'
# ' style=dashed\n'
# ' ];\n'
# )
# And changing it so we get a GraphViz's top-to-bottom ranking of components.
# NOTE: GraphViz is ignorent of what our tables actually are,
# from the GraphViz perspective, our tables are simply nodes.
#
# The "rank" of a node is determined by the order the nodes are added.
# This means that if we have 2 related tables, and we want one to appear
# beneath the other, we have to add the "lower rank" table after we've
# added the "higher rank" table.
#
# possible valid values for rankdir are:
# TB, BT, LR, RL
# which correspond to:
# Top-to-Bottom, Bottom-to-Top, Left-to-Right, Right-to-Left
GRAPH_BEGINNING = (' graph {\n'
' graph [rankdir=TB];\n' # and here we are changing it to be rankdir=TB
' node [label=\"\\N\",\n'
' shape=plaintext\n'
' ];\n'
' edge [color=gray50,\n'
' minlen=2,\n'
' style=dashed\n'
' ];\n'
)