# HG changeset patch # User Sean E. Russell # Date 1428502853 14400 # Wed Apr 08 10:20:53 2015 -0400 # Node ID 57653bec5584b4aea58376414a50a6e8c800ec1f # Parent e6a8de1412e78fca4d28a843bef74312f9275269 Highlight root people diff --git a/cmd/orgchart/main.go b/cmd/orgchart/main.go --- a/cmd/orgchart/main.go +++ b/cmd/orgchart/main.go @@ -1,7 +1,6 @@ package main // TODO: Report-to (e.g., show anchor person's superior) -// TODO: Highlight filtered person boxes // TODO: Support for ordering // TODO: Max-depth (e.g., show only X levels below anchor person) // TODO: Dotted lines @@ -20,16 +19,18 @@ * Constants & global variables * **************************************************************************/ const ( - boxW = 190 - gapW = 30 - marginW = 20 - gapH = 100 - marginH = 20 - textPX = 5 - textPY = 5 - textSize = 12 - _id = "person" - _ref = "#person" + boxW = 190 + 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 diff --git a/cmd/orgchart/svg.go b/cmd/orgchart/svg.go --- a/cmd/orgchart/svg.go +++ b/cmd/orgchart/svg.go @@ -42,13 +42,16 @@ c.Gid(_id) c.Rect(0, 0, boxW, boxH, "fill: inherit; stroke: black; stroke-width: 1;") c.Gend() + c.Gid(_root_id) + c.Rect(0, 0, boxW, boxH, "fill: inherit; stroke: black; stroke-width: 3;") + c.Gend() c.DefEnd() defer c.End() b := make(map[string]Box) xoff := marginW for _, p := range rs[0] { - drawOrg(c, xoff, marginH/2, p, b, false) + drawOrg(c, xoff, marginH/2, p, b, true, false) xoff += p.Width() } for _, r := range rs { @@ -56,8 +59,8 @@ } } -func drawOrg(canvas *svg.SVG, xoffset, yoffset int, p *Person, boxes map[string]Box, leaf bool) { - drawPerson(canvas, xoffset, yoffset, p.Index(), p, boxes, leaf) +func drawOrg(canvas *svg.SVG, xoffset, yoffset int, p *Person, boxes map[string]Box, root, leaf bool) { + drawPerson(canvas, xoffset, yoffset, p.Index(), p, boxes, root, leaf) if len(p.Reports) > 0 { isLeaf := true for _, report := range p.Reports { @@ -65,7 +68,7 @@ } yoffset += boxH + (gapH / 2) for _, q := range p.Reports { - drawOrg(canvas, xoffset, yoffset, q, boxes, isLeaf) + drawOrg(canvas, xoffset, yoffset, q, boxes, false, isLeaf) if isLeaf { yoffset += boxH + (gapH / 2) } else { @@ -75,21 +78,25 @@ } } -func drawPerson(canvas *svg.SVG, x, y, ind int, person *Person, boxes map[string]Box, leaf bool) { +func drawPerson(canvas *svg.SVG, x, y, ind int, person *Person, boxes map[string]Box, root, leaf bool) { if !leaf { x += (person.Width() - (boxW + (gapH / 2))) / 2 } - drawBox(canvas, x, y, person) + drawBox(canvas, x, y, person, root) boxes[person.Name] = Box{X: x, Y: y, Leaf: leaf} } -func drawBox(c *svg.SVG, x, y int, p *Person) { - c.Use(x+2, y+3, _ref, `filter="url(#blur)"`) +func drawBox(c *svg.SVG, x, y int, p *Person, root bool) { + ref := _ref + if root { + ref = _root_ref + } + c.Use(x+2, y+3, ref, `filter="url(#blur)"`) fill := "fill: white" if p.Contractor { fill = "fill: yellow" } - c.Use(x, y, _ref, fill) + c.Use(x, y, ref, fill) toff := x + (boxW / 2) toffY := y + textSize + textPY if p.Title != "" {