Change graph for vertical representation

Graphs are now drawn vertically, from top-to-bottom, which simplifies
the drawing algorithm in the case where commit titles, branch names and
tags have to be drawn.
This commit is contained in:
Alex Palaistras 2016-11-01 23:27:58 +00:00
parent e3e7a2cf30
commit 94daa65ecf
2 changed files with 14 additions and 13 deletions

19
grawkit
View File

@ -26,7 +26,7 @@ function t(str) {
# > Function `branch` renders pre-defined branch under a specific name to its # > Function `branch` renders pre-defined branch under a specific name to its
# > SVG representation. # > SVG representation.
function branch(name, _, buf, tmp, refs, i, bs, cs) { function branch(name, _, buf, tmp, refs, i, bspc, cspc) {
# Find index of branch. # Find index of branch.
for (n in branches) { for (n in branches) {
if (n == name) break if (n == name) break
@ -35,11 +35,11 @@ function branch(name, _, buf, tmp, refs, i, bs, cs) {
# Get commit refs. # Get commit refs.
split(branches[name], refs, ",") split(branches[name], refs, ",")
bs = i * style["branch/spacing"] bspc = i * style["branch/spacing"]
# Add path for branch. # Add path for branch.
tmp = "M" refs[1] * style["commit/spacing"] "," bs tmp = "M" bspc "," refs[1] * style["commit/spacing"]
tmp = tmp " L" (length(refs) - 1) * style["commit/spacing"] "," bs tmp = tmp " L" bspc "," (length(refs) - 1) * style["commit/spacing"]
# Print path. # Print path.
buf = sprintf(svg["g"], name) buf = sprintf(svg["g"], name)
@ -47,9 +47,9 @@ function branch(name, _, buf, tmp, refs, i, bs, cs) {
# Add commits on path. # Add commits on path.
for (c in refs) { for (c in refs) {
cs = refs[c] * style["commit/spacing"] cspc = refs[c] * style["commit/spacing"]
tmp = sprintf(svg["circle"], cs, bs, style["commit/radius"]) tmp = sprintf(svg["circle"], bspc, cspc, style["commit/radius"])
buf = buf "\n" tmp buf = buf "\n" tmp
} }
@ -72,7 +72,7 @@ BEGIN {
style["branch/stroke"] = "#333" style["branch/stroke"] = "#333"
style["branch/stroke-width"] = "10" style["branch/stroke-width"] = "10"
style["commit/spacing"] = "100" style["commit/spacing"] = "50"
style["commit/fill"] = "#fff" style["commit/fill"] = "#fff"
style["commit/stroke"] = style["branch/stroke"] style["commit/stroke"] = style["branch/stroke"]
style["commit/stroke-width"] = style["branch/stroke-width"] / 2 style["commit/stroke-width"] = style["branch/stroke-width"] / 2
@ -117,6 +117,7 @@ $0 ~ rule["commit"] {
state["HEAD"] = len["commits"] state["HEAD"] = len["commits"]
len["commits"] += 1 len["commits"] += 1
next
} }
# SVG Graph Generation # SVG Graph Generation
@ -126,8 +127,8 @@ $0 ~ rule["commit"] {
# #
END { END {
xy = style["branch/stroke-width"] * -1 xy = style["branch/stroke-width"] * -1
w = (style["commit/spacing"] * (len["commits"] - 1)) + (style["commit/stroke-width"] * 4) w = (style["branch/spacing"] * (len["branches"] - 1)) + (style["branch/stroke-width"] * 2)
h = (style["branch/spacing"] * (len["branches"] - 1)) + (style["branch/stroke-width"] * 2) h = (style["commit/spacing"] * (len["commits"] - 1)) + (style["commit/stroke-width"] * 4)
# Print SVG header. # Print SVG header.
printf svg["svg"], xy, xy, w, h printf svg["svg"], xy, xy, w, h

View File

@ -7,7 +7,7 @@ git commit
--> -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -10 220 20"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -10 20 120">
<style type="text/css"><![CDATA[ <style type="text/css"><![CDATA[
.branch { .branch {
fill: none; fill: none;
@ -21,9 +21,9 @@ git commit
} }
]]></style> ]]></style>
<g id="master"> <g id="master">
<path class="branch" d="M0,0 L200,0" /> <path class="branch" d="M0,0 L0,100" />
<circle class="commit" cx="0" cy="0" r="7.5" /> <circle class="commit" cx="0" cy="0" r="7.5" />
<circle class="commit" cx="100" cy="0" r="7.5" /> <circle class="commit" cx="0" cy="50" r="7.5" />
<circle class="commit" cx="200" cy="0" r="7.5" /> <circle class="commit" cx="0" cy="100" r="7.5" />
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 584 B

After

Width:  |  Height:  |  Size: 583 B