Rectangle returns the extent of the Legend.
(c draw.Canvas)
| 142 | |
| 143 | // Rectangle returns the extent of the Legend. |
| 144 | func (l *Legend) Rectangle(c draw.Canvas) vg.Rectangle { |
| 145 | var width, height vg.Length |
| 146 | sty := l.TextStyle |
| 147 | entryHeight := l.entryHeight() |
| 148 | for i, e := range l.entries { |
| 149 | width = vg.Length(math.Max(float64(width), float64(l.ThumbnailWidth+sty.Rectangle(" "+e.text).Max.X))) |
| 150 | height += entryHeight |
| 151 | if i != 0 { |
| 152 | height += l.Padding |
| 153 | } |
| 154 | } |
| 155 | var r vg.Rectangle |
| 156 | if l.Left { |
| 157 | r.Max.X = c.Max.X |
| 158 | r.Min.X = c.Max.X - width |
| 159 | } else { |
| 160 | r.Max.X = c.Min.X + width |
| 161 | r.Min.X = c.Min.X |
| 162 | } |
| 163 | if l.Top { |
| 164 | r.Max.Y = c.Max.Y |
| 165 | r.Min.Y = c.Max.Y - height |
| 166 | } else { |
| 167 | r.Max.Y = c.Min.Y + height |
| 168 | r.Min.Y = c.Min.Y |
| 169 | } |
| 170 | return r |
| 171 | } |
| 172 | |
| 173 | // entryHeight returns the height of the tallest legend |
| 174 | // entry text. |