TestLabelsWithGlyphBoxes tests the position of the glyphbox around a block of text, checking whether we correctly take into account the descent+ascent of a glyph.
(t *testing.T)
| 25 | // a block of text, checking whether we correctly take into account |
| 26 | // the descent+ascent of a glyph. |
| 27 | func TestLabelsWithGlyphBoxes(t *testing.T) { |
| 28 | cmpimg.CheckPlot( |
| 29 | func() { |
| 30 | const fontSize = 24 |
| 31 | |
| 32 | p := plot.New() |
| 33 | p.Title.Text = "Labels" |
| 34 | p.X.Min = -1 |
| 35 | p.X.Max = +1 |
| 36 | p.Y.Min = -1 |
| 37 | p.Y.Max = +1 |
| 38 | |
| 39 | const ( |
| 40 | left = 0.00 |
| 41 | middle = 0.02 |
| 42 | right = 0.04 |
| 43 | ) |
| 44 | |
| 45 | labels, err := plotter.NewLabels(plotter.XYLabels{ |
| 46 | XYs: []plotter.XY{ |
| 47 | {X: -0.8 + left, Y: -0.5}, // Aq + y-align bottom |
| 48 | {X: -0.6 + middle, Y: -0.5}, // Aq + y-align center |
| 49 | {X: -0.4 + right, Y: -0.5}, // Aq + y-align top |
| 50 | |
| 51 | {X: -0.8 + left, Y: +0.5}, // ditto for Aq\nAq |
| 52 | {X: -0.6 + middle, Y: +0.5}, |
| 53 | {X: -0.4 + right, Y: +0.5}, |
| 54 | |
| 55 | {X: +0.0 + left, Y: +0}, // ditto for Bg\nBg\nBg |
| 56 | {X: +0.2 + middle, Y: +0}, |
| 57 | {X: +0.4 + right, Y: +0}, |
| 58 | }, |
| 59 | Labels: []string{ |
| 60 | "Aq", "Aq", "Aq", |
| 61 | "Aq\nAq", "Aq\nAq", "Aq\nAq", |
| 62 | |
| 63 | "Bg\nBg\nBg", |
| 64 | "Bg\nBg\nBg", |
| 65 | "Bg\nBg\nBg", |
| 66 | }, |
| 67 | }) |
| 68 | if err != nil { |
| 69 | t.Fatalf("could not creates labels plotter: %+v", err) |
| 70 | } |
| 71 | for i := range labels.TextStyle { |
| 72 | sty := &labels.TextStyle[i] |
| 73 | sty.Font.Size = vg.Length(fontSize) |
| 74 | } |
| 75 | labels.TextStyle[0].YAlign = draw.YBottom |
| 76 | labels.TextStyle[1].YAlign = draw.YCenter |
| 77 | labels.TextStyle[2].YAlign = draw.YTop |
| 78 | |
| 79 | labels.TextStyle[3].YAlign = draw.YBottom |
| 80 | labels.TextStyle[4].YAlign = draw.YCenter |
| 81 | labels.TextStyle[5].YAlign = draw.YTop |
| 82 | |
| 83 | labels.TextStyle[6].YAlign = draw.YBottom |
| 84 | labels.TextStyle[7].YAlign = draw.YCenter |
nothing calls this directly
no test coverage detected