Draw draws a plot to a draw.Canvas. Plotters are drawn in the order in which they were added to the plot. Plotters that implement the GlyphBoxer interface will have their GlyphBoxes taken into account when padding the plot so that none of their glyphs are clipped.
(c draw.Canvas)
| 143 | // taken into account when padding the plot so that |
| 144 | // none of their glyphs are clipped. |
| 145 | func (p *Plot) Draw(c draw.Canvas) { |
| 146 | if p.BackgroundColor != nil { |
| 147 | c.SetColor(p.BackgroundColor) |
| 148 | c.Fill(c.Rectangle.Path()) |
| 149 | } |
| 150 | |
| 151 | if p.Title.Text != "" { |
| 152 | descent := p.Title.TextStyle.FontExtents().Descent |
| 153 | c.FillText(p.Title.TextStyle, vg.Point{X: c.Center().X, Y: c.Max.Y + descent}, p.Title.Text) |
| 154 | |
| 155 | rect := p.Title.TextStyle.Rectangle(p.Title.Text) |
| 156 | c.Max.Y -= rect.Size().Y |
| 157 | c.Max.Y -= p.Title.Padding |
| 158 | } |
| 159 | |
| 160 | p.X.sanitizeRange() |
| 161 | x := horizontalAxis{p.X} |
| 162 | p.Y.sanitizeRange() |
| 163 | y := verticalAxis{p.Y} |
| 164 | |
| 165 | ywidth := y.size() |
| 166 | |
| 167 | xheight := x.size() |
| 168 | x.draw(padX(p, draw.Crop(c, ywidth, 0, 0, 0))) |
| 169 | y.draw(padY(p, draw.Crop(c, 0, 0, xheight, 0))) |
| 170 | |
| 171 | dataC := padY(p, padX(p, draw.Crop(c, ywidth, 0, xheight, 0))) |
| 172 | for _, data := range p.plotters { |
| 173 | data.Plot(dataC, p) |
| 174 | } |
| 175 | |
| 176 | p.Legend.Draw(draw.Crop(c, ywidth, 0, xheight, 0)) |
| 177 | } |
| 178 | |
| 179 | // DataCanvas returns a new draw.Canvas that |
| 180 | // is the subset of the given draw area into which |
no test coverage detected