diff cmd/isoareas/main.go @ 4556:04eba9dc917d iso-areas

Use colors from configuration instead of random rgb values.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 01 Oct 2019 17:37:54 +0200
parents 1c5c6ffab886
children 17cba8b447a6
line wrap: on
line diff
--- a/cmd/isoareas/main.go	Tue Oct 01 17:08:37 2019 +0200
+++ b/cmd/isoareas/main.go	Tue Oct 01 17:37:54 2019 +0200
@@ -31,6 +31,7 @@
 	svg "github.com/ajstarks/svgo"
 	"github.com/fogleman/contourmap"
 
+	"gemma.intevation.de/gemma/pkg/models"
 	"gemma.intevation.de/gemma/pkg/octree"
 )
 
@@ -99,6 +100,8 @@
 
 func dumpContoursSVG(
 	w io.Writer,
+	heights []float64,
+	colors models.ColorValues,
 	contours [][]contourmap.Contour,
 ) (err error) {
 
@@ -143,14 +146,12 @@
 	canvas := svg.New(out)
 	canvas.Start(width, height)
 
-	rnd := rand.New(rand.NewSource(42))
-
-	for _, c := range contours {
+	for j, c := range contours {
 
-		r := byte(rnd.Intn(256))
-		g := byte(rnd.Intn(256))
-		b := byte(rnd.Intn(256))
-		style := fmt.Sprintf("fill:#%02x%02x%02x", r, g, b)
+		h := heights[j]
+		col := colors.Clip(h)
+
+		style := fmt.Sprintf("fill:#%02x%02x%02x", col.R, col.G, col.B)
 
 		for _, r := range c {
 			x := make([]int, len(r))
@@ -284,10 +285,12 @@
 
 	flag.Parse()
 
-	heights, err := octree.ParseClassBreaks(classBreaks)
+	colors, err := models.ParseColorValues(classBreaks)
 	check(err)
+
+	heights := colors.Heights()
+
 	log.Printf("num classes: %d\n", len(heights))
-
 	start := time.Now()
 	xyz, err := loadXYZ(os.Stdin)
 	check(err)
@@ -423,7 +426,7 @@
 	wg.Wait()
 
 	log.Printf("Calculating contours took %v.\n", time.Since(start))
-	check(dumpContoursSVG(os.Stdout, contours))
+	check(dumpContoursSVG(os.Stdout, heights, colors, contours))
 
 	/*