DrawGlyphBoxes draws red outlines around the plot's GlyphBoxes. This is intended for debugging.
(c draw.Canvas)
| 195 | // DrawGlyphBoxes draws red outlines around the plot's |
| 196 | // GlyphBoxes. This is intended for debugging. |
| 197 | func (p *Plot) DrawGlyphBoxes(c draw.Canvas) { |
| 198 | dac := p.DataCanvas(c) |
| 199 | sty := draw.LineStyle{ |
| 200 | Color: color.RGBA{R: 255, A: 255}, |
| 201 | Width: vg.Points(0.5), |
| 202 | } |
| 203 | |
| 204 | drawBox := func(c draw.Canvas, b GlyphBox) { |
| 205 | x := c.X(b.X) + b.Rectangle.Min.X |
| 206 | y := c.Y(b.Y) + b.Rectangle.Min.Y |
| 207 | c.StrokeLines(sty, []vg.Point{ |
| 208 | {X: x, Y: y}, |
| 209 | {X: x + b.Rectangle.Size().X, Y: y}, |
| 210 | {X: x + b.Rectangle.Size().X, Y: y + b.Rectangle.Size().Y}, |
| 211 | {X: x, Y: y + b.Rectangle.Size().Y}, |
| 212 | {X: x, Y: y}, |
| 213 | }) |
| 214 | } |
| 215 | |
| 216 | var title vg.Length |
| 217 | if p.Title.Text != "" { |
| 218 | rect := p.Title.TextStyle.Rectangle(p.Title.Text) |
| 219 | title += rect.Size().Y |
| 220 | title += p.Title.Padding |
| 221 | box := GlyphBox{ |
| 222 | Rectangle: rect.Add(vg.Point{ |
| 223 | X: c.Center().X, |
| 224 | Y: c.Max.Y, |
| 225 | }), |
| 226 | } |
| 227 | drawBox(c, box) |
| 228 | } |
| 229 | |
| 230 | for _, b := range p.GlyphBoxes(p) { |
| 231 | drawBox(dac, b) |
| 232 | } |
| 233 | |
| 234 | p.X.sanitizeRange() |
| 235 | p.Y.sanitizeRange() |
| 236 | |
| 237 | x := horizontalAxis{p.X} |
| 238 | y := verticalAxis{p.Y} |
| 239 | |
| 240 | ywidth := y.size() |
| 241 | xheight := x.size() |
| 242 | |
| 243 | cx := padX(p, draw.Crop(c, ywidth, 0, 0, 0)) |
| 244 | for _, b := range x.GlyphBoxes(p) { |
| 245 | drawBox(cx, b) |
| 246 | } |
| 247 | |
| 248 | cy := padY(p, draw.Crop(c, 0, 0, xheight, 0)) |
| 249 | cy.Max.Y -= title |
| 250 | for _, b := range y.GlyphBoxes(p) { |
| 251 | drawBox(cy, b) |
| 252 | } |
| 253 | } |
| 254 |