Skip to content

Commit a7f12ea

Browse files
authored
Added padding to bounding rectangle (#304)
1 parent 063eaf0 commit a7f12ea

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

examples/heatmap/heatmap.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ func main() {
6262

6363
// Find bounding rectangle for points to get around the normalization done by the heatmap library
6464
r2Bounds := r2.RectFromPoints(points...)
65+
padding := float64(dotSize) / 2.0 // Calculating padding amount to avoid shrinkage by the heatmap library
6566
bounds := image.Rectangle{
66-
Min: image.Point{X: int(r2Bounds.X.Lo), Y: int(r2Bounds.Y.Lo)},
67-
Max: image.Point{X: int(r2Bounds.X.Hi), Y: int(r2Bounds.Y.Hi)},
67+
Min: image.Point{X: int(r2Bounds.X.Lo - padding), Y: int(r2Bounds.Y.Lo - padding)},
68+
Max: image.Point{X: int(r2Bounds.X.Hi + padding), Y: int(r2Bounds.Y.Hi + padding)},
6869
}
6970

7071
// Transform r2.Points into heatmap.DataPoints
@@ -86,11 +87,11 @@ func main() {
8687

8788
// Create output canvas and use map overview image as base
8889
img := image.NewRGBA(imgMap.Bounds())
89-
draw.Draw(img, imgMap.Bounds(), imgMap, image.ZP, draw.Over)
90+
draw.Draw(img, imgMap.Bounds(), imgMap, image.Point{}, draw.Over)
9091

9192
// Generate and draw heatmap overlay on top of the overview
9293
imgHeatmap := heatmap.Heatmap(image.Rect(0, 0, bounds.Dx(), bounds.Dy()), data, dotSize, opacity, schemes.AlphaFire)
93-
draw.Draw(img, bounds, imgHeatmap, image.ZP, draw.Over)
94+
draw.Draw(img, bounds, imgHeatmap, image.Point{}, draw.Over)
9495

9596
// Write to stdout
9697
err = jpeg.Encode(os.Stdout, img, &jpeg.Options{Quality: jpegQuality})

examples/heatmap/heatmap.jpg

-24 Bytes
Loading

0 commit comments

Comments
 (0)