M cmd/orgchart/main.go +0 -20
@@ 25,26 25,6 @@ import (
)
/**************************************************************************
- * Constants & global variables *
- **************************************************************************/
-const (
- boxW = 300
- gapW = 30
- marginW = 20
- gapH = 100
- marginH = 20
- textPX = 5
- textPY = 5
- textSize = 12
- _id = "person"
- _ref = "#person"
- _root_id = "root"
- _root_ref = "#root"
-)
-
-var boxH int
-
-/**************************************************************************
* Main *
**************************************************************************/
func main() {
M cmd/orgchart/main_test.go +3 -0
@@ 142,4 142,7 @@ D2,C2B3`
rs = rank(ps)
assert.Equal(t, 5, rs.width())
+ assert.Equal(t, 6, rs.height())
+ setBoxH(rs)
+ assert.Equal(t, 450, height(rs))
}
M cmd/orgchart/rank.go +1 -3
@@ 70,9 70,7 @@ func (rs Ranks) height() int {
default:
idx = len(rs) - 2
}
- high := len(rs) + (maxReports(rs[idx]) - 1)
- h := (high * boxH) + ((high - 1) * gapH) + (marginH * 2)
- return h
+ return len(rs) + (maxReports(rs[idx]) - 1)
}
func maxReports(r Rank) int {
M cmd/orgchart/svg.go +26 -5
@@ 6,8 6,27 @@ import (
"github.com/ajstarks/svgo"
)
+/**************************************************************************
+ * Constants & global variables *
+ **************************************************************************/
+const (
+ boxW = 300
+ gapW = 30
+ marginW = 20
+ gapH = 100
+ marginH = 20
+ textPX = 5
+ textPY = 5
+ textSize = 12
+ _id = "person"
+ _ref = "#person"
+ _root_id = "root"
+ _root_ref = "#root"
+)
+
var pageWidth int
var bgW int
+var boxH int
/**************************************************************************
* SVG generating code *
@@ 43,10 62,7 @@ func renderSVG(out io.Writer, rs Ranks,
c := svg.New(out)
bgW = boxW + gapW
pageWidth := rs.width() * bgW
- h := rs.height()
- if sup {
- h += boxH + gapH + (marginH * 2)
- }
+ h := height(rs)
c.Start(pageWidth, h)
c.Filter("blur")
c.FeGaussianBlur(svg.Filterspec{In: "SourceAlpha", Result: "blur"}, 5, 5)
@@ 127,7 143,7 @@ func drawOrg(canvas *svg.SVG, xoffset, y
func drawPerson(canvas *svg.SVG, x, y, ind int, person *Person, boxes map[string]Box, root, leaf bool) {
if !leaf {
- x += (width(person) - (boxW + (gapH / 2))) / 2
+ x += (width(person) - (boxW + (gapW / 2))) / 2
}
drawBox(canvas, x, y, person, root)
boxes[person.Name] = Box{X: x, Y: y, Leaf: leaf}
@@ 197,3 213,8 @@ func connect(c *svg.SVG, f, t Box) {
func width(p *Person) int {
return p.Width() * (boxW + gapW)
}
+
+func height(rs Ranks) int {
+ high := rs.height()
+ return (high * boxH) + ((high - 1) * (gapH / 2)) + marginH
+}
A => test.csv +14 -0
@@ 0,0 1,14 @@
+X,
+A,X
+B1,A
+B2,A
+B3,A
+C1B1,B1
+C2B1,B1
+C3B1,B1
+C1B2,B2
+C1B3,B3
+C2B3,B3
+C3B3,B3
+D1,C2B3
+D2,C2B3