Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plotter/barchart.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package plotter

import (
"errors"
"fmt"
"image/color"
"math"

Expand Down Expand Up @@ -120,6 +121,10 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) {
valMin := trVal(bottom)
valMax := trVal(bottom + ht)

// value point
topx := catMin
topy := valMax

var pts []vg.Point
var poly []vg.Point
if !b.Horizontal {
Expand All @@ -138,6 +143,9 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) {
{valMax, catMin},
}
poly = c.ClipPolygonX(pts)

topx = valMax
topy = catMin
}
c.FillPolygon(b.Color, poly)

Expand All @@ -150,6 +158,11 @@ func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) {
outline = c.ClipLinesX(pts)
}
c.StrokeLines(b.LineStyle, outline...)
// show the value of each bar on top of it
strvalue := fmt.Sprintln(ht)
ft, _ := vg.MakeFont(plot.DefaultFont, 10)
c.FillText(draw.TextStyle{Color: color.Black, Font: ft}, vg.Point{X: topx, Y: topy}, strvalue)

}
}

Expand Down