...

Source file src/gonum.org/v1/plot/plotter/glyphbox.go

Documentation: gonum.org/v1/plot/plotter

     1  // Copyright ©2015 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package plotter
     6  
     7  import (
     8  	"image/color"
     9  
    10  	"gonum.org/v1/plot"
    11  	"gonum.org/v1/plot/vg"
    12  	"gonum.org/v1/plot/vg/draw"
    13  )
    14  
    15  // GlyphBoxes implements the Plotter interface, drawing
    16  // all of the glyph boxes of the plot.  This is intended for
    17  // debugging.
    18  type GlyphBoxes struct {
    19  	draw.LineStyle
    20  }
    21  
    22  func NewGlyphBoxes() *GlyphBoxes {
    23  	g := new(GlyphBoxes)
    24  	g.Color = color.RGBA{R: 255, A: 255}
    25  	g.Width = vg.Points(0.25)
    26  	return g
    27  }
    28  
    29  func (g GlyphBoxes) Plot(c draw.Canvas, plt *plot.Plot) {
    30  	for _, b := range plt.GlyphBoxes(plt) {
    31  		x := c.X(b.X) + b.Rectangle.Min.X
    32  		y := c.Y(b.Y) + b.Rectangle.Min.Y
    33  		c.StrokeLines(g.LineStyle, []vg.Point{
    34  			{X: x, Y: y},
    35  			{X: x + b.Rectangle.Size().X, Y: y},
    36  			{X: x + b.Rectangle.Size().X, Y: y + b.Rectangle.Size().Y},
    37  			{X: x, Y: y + b.Rectangle.Size().Y},
    38  			{X: x, Y: y},
    39  		})
    40  	}
    41  }
    42  

View as plain text