Plot implements the plot.Plotter interface.
(c draw.Canvas, plt *plot.Plot)
| 97 | |
| 98 | // Plot implements the plot.Plotter interface. |
| 99 | func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) { |
| 100 | trCat, trVal := plt.Transforms(&c) |
| 101 | if b.Horizontal { |
| 102 | trCat, trVal = trVal, trCat |
| 103 | } |
| 104 | |
| 105 | for i, ht := range b.Values { |
| 106 | catVal := b.XMin + float64(i) |
| 107 | catMin := trCat(float64(catVal)) |
| 108 | if !b.Horizontal { |
| 109 | if !c.ContainsX(catMin) { |
| 110 | continue |
| 111 | } |
| 112 | } else { |
| 113 | if !c.ContainsY(catMin) { |
| 114 | continue |
| 115 | } |
| 116 | } |
| 117 | catMin = catMin - b.Width/2 + b.Offset |
| 118 | catMax := catMin + b.Width |
| 119 | bottom := b.stackedOn.BarHeight(i) |
| 120 | valMin := trVal(bottom) |
| 121 | valMax := trVal(bottom + ht) |
| 122 | |
| 123 | var pts []vg.Point |
| 124 | var poly []vg.Point |
| 125 | if !b.Horizontal { |
| 126 | pts = []vg.Point{ |
| 127 | {X: catMin, Y: valMin}, |
| 128 | {X: catMin, Y: valMax}, |
| 129 | {X: catMax, Y: valMax}, |
| 130 | {X: catMax, Y: valMin}, |
| 131 | } |
| 132 | poly = c.ClipPolygonY(pts) |
| 133 | } else { |
| 134 | pts = []vg.Point{ |
| 135 | {X: valMin, Y: catMin}, |
| 136 | {X: valMin, Y: catMax}, |
| 137 | {X: valMax, Y: catMax}, |
| 138 | {X: valMax, Y: catMin}, |
| 139 | } |
| 140 | poly = c.ClipPolygonX(pts) |
| 141 | } |
| 142 | c.FillPolygon(b.Color, poly) |
| 143 | |
| 144 | var outline [][]vg.Point |
| 145 | if !b.Horizontal { |
| 146 | pts = append(pts, vg.Point{X: catMin, Y: valMin}) |
| 147 | outline = c.ClipLinesY(pts) |
| 148 | } else { |
| 149 | pts = append(pts, vg.Point{X: valMin, Y: catMin}) |
| 150 | outline = c.ClipLinesX(pts) |
| 151 | } |
| 152 | c.StrokeLines(b.LineStyle, outline...) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // DataRange implements the plot.DataRanger interface. |
nothing calls this directly
no test coverage detected