Skip to content

Commit 656b57c

Browse files
re-added renderLabel function
1 parent fc5e811 commit 656b57c

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

cmd/nexrad-render/main.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"time"
1717

1818
"github.com/llgcode/draw2d"
19-
//"golang.org/x/image/math/fixed"
2019

21-
//"golang.org/x/image/colornames"
22-
//"golang.org/x/image/font"
23-
//"golang.org/x/image/math/fixed"
20+
"golang.org/x/image/math/fixed"
21+
22+
"golang.org/x/image/colornames"
23+
"golang.org/x/image/font"
2424

2525
"github.com/bwiggs/go-nexrad/archive2"
2626
"github.com/cheggaaa/pb/v3"
@@ -29,7 +29,7 @@ import (
2929
"github.com/llgcode/draw2d/draw2dsvg"
3030
"github.com/sirupsen/logrus"
3131
"github.com/spf13/cobra"
32-
//"golang.org/x/image/font/inconsolata"
32+
"golang.org/x/image/font/inconsolata"
3333
)
3434

3535
var cmd = &cobra.Command{
@@ -282,9 +282,13 @@ func render(out string, radials []*archive2.Message31, label string) {
282282

283283
// fmt.Println(valueDist)
284284

285-
//if renderLabel {
286-
// addLabel(canvas, int(width-495.0), int(height-10.0), label)
287-
//}
285+
if renderLabel {
286+
if vectorize == "png" {
287+
addLabel(PNGcanvas, int(width-495.0), int(height-10.0), label)
288+
} else if vectorize == "svg" {
289+
logrus.Warn("Labels cannot be drawn on an SVG image, ignoring -L flag")
290+
}
291+
}
288292

289293
// Save to file
290294
if vectorize == "png" {
@@ -294,17 +298,17 @@ func render(out string, radials []*archive2.Message31, label string) {
294298
}
295299
}
296300

297-
//func addLabel(img *draw2dsvg.Svg, x, y int, label string) {
298-
// point := fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)}
299-
//
300-
// d := &font.Drawer{
301-
// Dst: img,
302-
// Src: image.NewUniform(colornames.Gray),
303-
// Face: inconsolata.Bold8x16,
304-
// Dot: point,
305-
// }
306-
// d.DrawString(label)
307-
//}
301+
func addLabel(img *image.RGBA, x, y int, label string) {
302+
point := fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)}
303+
304+
d := &font.Drawer{
305+
Dst: img,
306+
Src: image.NewUniform(colornames.Gray),
307+
Face: inconsolata.Bold8x16,
308+
Dot: point,
309+
}
310+
d.DrawString(label)
311+
}
308312

309313
// scaleInt scales a number form one range to another range
310314
func scaleInt(value, oldMax, oldMin, newMax, newMin int32) int32 {

0 commit comments

Comments
 (0)