diff options
| author | Matt Torok | 2014-02-12 01:10:49 -0800 |
|---|---|---|
| committer | Mike McQuaid | 2014-02-12 11:40:40 +0000 |
| commit | 624b0aab285cf34b7906451a57e49ca4d90ddf47 (patch) | |
| tree | e4047074f9fc1b0ea3bdda0cae17147b528bda6f /Library | |
| parent | 505936cfa317ae283a0ad1660503ba9ebc74773c (diff) | |
| download | homebrew-624b0aab285cf34b7906451a57e49ca4d90ddf47.tar.bz2 | |
brew-graph: improve formatting.
This commit adds additional formatting options to the graph. Most noticeable is a top-to-bottom layout (rather than the previous left-to-right), and nicer fonts on everything.
More subtly, the ranking mechanism has been updated so that the "Safe to Remove" cluster is always at the highest rank (fixing a bug where non-leaf nodes could have been placed next to it,) and added better margins and padding. The rank separation was also decreased for a more compact graph.
Under the hood, the GraphViz output code was updated to support attributes with a list of sub-attributes (for example, 'graph [fontsize="11", fontname="Helvetica"]') and to not put quotes around HTML-like labels in clusters.
Closes #26651.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library')
| -rwxr-xr-x | Library/Contributions/cmd/brew-graph | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/Library/Contributions/cmd/brew-graph b/Library/Contributions/cmd/brew-graph index d45c69797..07b3464b4 100755 --- a/Library/Contributions/cmd/brew-graph +++ b/Library/Contributions/cmd/brew-graph @@ -159,9 +159,17 @@ class Cluster(NodeContainer, ClusterContainer): def to_dot(self, out): out.outln("subgraph %s {" % self.cluster_id()) with out.indented(): - out.outln('label = "%s"' % self.label) + # If the label is an HTML-like string (starts and end with '<' and '>', respectively), + # don't put quotes around it (or GraphViz won't recognize it.) + if self.label[0] == '<' and self.label[-1] == '>': + out.outln('label = %s;' % self.label) + else: + out.outln('label = "%s"' % self.label) for k in self.attrib: - out.outln('%s = "%s"' % (k, self.attrib[k])) + if isinstance(self.attrib[k], dict): + out.outln('%s %s;' % (k, format_attribs(self.attrib[k]))) + else: + out.outln('%s = "%s";' % (k, self.attrib[k])) for cluster in self.clusters: cluster.to_dot(out) @@ -258,7 +266,11 @@ class Graph(NodeContainer, EdgeContainer, ClusterContainer): with self.o.indented(): self.o.outln('label = "%s"' % self.label) for k in self.attrib: - self.o.outln('%s = "%s"' % (k, self.attrib[k])) + # If the value of the attrib is a dictionary, write it out in special array form + if isinstance(self.attrib[k], dict): + self.o.outln('%s %s;' % (k, format_attribs(self.attrib[k]))) + else: + self.o.outln('%s = "%s";' % (k, self.attrib[k])) self.nodes_to_dot(self.o) @@ -302,11 +314,20 @@ def main(): deps = deps.split(" ") depgraph.append((name, deps)) - hb = Graph("Homebrew Dependencies", attrib={'labelloc':'t', 'rankdir':'LR', 'ranksep':'5'}) + # We need newrank = True to make sure clusters respect rank = "source". Otherwise, we may get + # random nodes next to "Safe to Remove" cluster, despite them not being a part of that cluster. + hb = Graph("Homebrew Dependencies", attrib={ + 'labelloc':'t', 'rankdir': 'TB' , 'ranksep':'3', 'newrank': True, + 'graph': {'fontname': 'Futura-Medium', 'fontsize': 48}, + 'node': {'fontname': 'HelveticaNeue', 'fontsize': 14} + }) # Independent formulas (those that are not dependended on by any other formula) get placed in # their own subgraph so we can align them together on the left. if show == 'installed': - sub = hb.cluster("independent", "Safe to Remove", attrib={'rank': 'min', 'style': 'filled', 'fillcolor': '#F0F0F0', 'color': 'invis'}) + # We use a HTML-like label to give the label a little bit of padding at the top + sub = hb.cluster("independent", "<<font point-size=\"15\"><br/></font>Safe to Remove>", + attrib={'rank': 'source', 'style': 'filled', 'fillcolor': '#F0F0F0', 'color': 'invis', + 'margin': '25,1', 'graph': {'fontname': 'Helvetica-LightOblique', 'fontsize': 24}}) else: sub = hb |
