func (self *LineChart) drawSeries(x, y, w, h float64, ctx vg.Context) { // Boundries baseline := y + h _, max, count := self.Model.Limits() horIncr := w / (count - 1) vratio := (h - 1) / max for _, s := range self.Model.Series() { c1 := CloneColor(s.Color) c1.A = 150 ctx.StrokeColor(c1) ctx.StrokeWidth(s.StrokeWidth) ctx.BeginPath() for i, f := range s.Data { if i == 0 { ctx.MoveTo(x+float64(i)*horIncr, baseline-(f*vratio)) } else { ctx.LineTo(x+float64(i)*horIncr, baseline-(f*vratio)) } } ctx.Stroke() if self.Fill { ctx.BeginPath() // ctx.MoveTo(x, baseline) c2 := CloneColor(s.Color) c2.A = 200 ctx.FillColor(c2) for i, f := range s.Data { if i == 0 { ctx.MoveTo(x+float64(i)*horIncr, baseline-(f*vratio)) } ctx.LineTo(x+float64(i)*horIncr, baseline-(f*vratio)) if i == len(s.Data)-1 { ctx.LineTo(x+float64(i)*horIncr, baseline) ctx.LineTo(x, baseline) ctx.MoveTo(x, baseline-(s.Data[0]*vratio)) break } } ctx.Fill() } } }
func (self *Text) Draw(ctx vg.Context) { x, y, w, h := self.Bounds() self.lastContext = &ctx ctx.Scissor(x, y, w, h) ctx.BeginPath() ctx.RoundedRect(x, y, w, h, self.CornerRadius) ctx.FillColor(self.Background) ctx.Fill() ctx.FillColor(self.Foreground) self.forEachDrawnToken(x, y, w, h, func(i int, x, y, lineHeight float64, bounds *ui.Rectangle, ctx *vg.Context) { ctx.Text(x, y, self.tokens[i]) }, ) // for i := 0; i < len(self.selections); i++ { // s := self.selections[i] // } ctx.ResetScissor() }
// draw draws the title and returns the height. func (self *Title) draw(x, y, w, h float64, ctx vg.Context) float64 { th := 0.0 name := self.Model.Title() if len(name) > 0 { th = self.FontSize + 16 // ctx.BeginPath() // ctx.StrokeColor(color.RGBA{0, 50, 100, 25}) // ctx.StrokeWidth(1) // ctx.LineCap(vg.ROUND) // ctx.LineJoin(vg.ROUND) // ctx.MoveTo(x, y+th) // ctx.LineTo(x+1.5, y+th) // ctx.LineTo(x+w+1.5, y+th) // ctx.Stroke() ctx.FillColor(color.RGBA{255, 251, 251, 255}) ctx.TextAlign(vg.ALIGN_LEFT | vg.ALIGN_MIDDLE) ctx.SetFontSize(self.FontSize + 3) ctx.FindFont(vg.FONT_DEFAULT) ctx.WrappedText(x+10, y+self.FontSize, w, name) } return th }