@@ -295,15 +295,29 @@ func (a horizontalAxis) draw(c draw.Canvas) {
295295}
296296
297297// GlyphBoxes returns the GlyphBoxes for the tick labels.
298- func (a horizontalAxis ) GlyphBoxes (* Plot ) []GlyphBox {
299- var boxes []GlyphBox
300- for _ , t := range a .Tick .Marker .Ticks (a .Min , a .Max ) {
298+ func (a horizontalAxis ) GlyphBoxes (p * Plot ) []GlyphBox {
299+ var (
300+ boxes []GlyphBox
301+ yoff font.Length
302+ )
303+
304+ if a .Label .Text != "" {
305+ yoff += a .Label .TextStyle .Height (a .Label .Text )
306+ yoff += a .Label .Padding
307+ }
308+
309+ var (
310+ marks = a .Tick .Marker .Ticks (a .Min , a .Max )
311+ height = tickLabelHeight (a .Tick .Label , marks )
312+ descent = a .Tick .Label .FontExtents ().Descent
313+ )
314+ for _ , t := range marks {
301315 if t .IsMinor () {
302316 continue
303317 }
304318 box := GlyphBox {
305319 X : a .Norm (t .Value ),
306- Rectangle : a .Tick .Label .Rectangle (t .Label ),
320+ Rectangle : a .Tick .Label .Rectangle (t .Label ). Add (vg. Point { Y : yoff + height + descent }) ,
307321 }
308322 boxes = append (boxes , box )
309323 }
@@ -396,15 +410,37 @@ func (a verticalAxis) draw(c draw.Canvas) {
396410}
397411
398412// GlyphBoxes returns the GlyphBoxes for the tick labels
399- func (a verticalAxis ) GlyphBoxes (* Plot ) []GlyphBox {
400- var boxes []GlyphBox
401- for _ , t := range a .Tick .Marker .Ticks (a .Min , a .Max ) {
413+ func (a verticalAxis ) GlyphBoxes (p * Plot ) []GlyphBox {
414+ var (
415+ boxes []GlyphBox
416+ xoff font.Length
417+ )
418+
419+ if a .Label .Text != "" {
420+ sty := a .Label .TextStyle
421+ sty .Rotation += math .Pi / 2
422+
423+ xoff += a .Label .TextStyle .Height (a .Label .Text )
424+ xoff += a .Label .TextStyle .FontExtents ().Descent
425+ xoff += a .Label .Padding
426+ }
427+
428+ marks := a .Tick .Marker .Ticks (a .Min , a .Max )
429+ if w := tickLabelWidth (a .Tick .Label , marks ); len (marks ) > 0 && w > 0 {
430+ xoff += w
431+ }
432+
433+ var (
434+ ext = a .Tick .Label .FontExtents ()
435+ desc = ext .Height - ext .Ascent // descent + linegap
436+ )
437+ for _ , t := range marks {
402438 if t .IsMinor () {
403439 continue
404440 }
405441 box := GlyphBox {
406442 Y : a .Norm (t .Value ),
407- Rectangle : a .Tick .Label .Rectangle (t .Label ),
443+ Rectangle : a .Tick .Label .Rectangle (t .Label ). Add (vg. Point { X : xoff , Y : desc }) ,
408444 }
409445 boxes = append (boxes , box )
410446 }
0 commit comments