Mercurial > gemma
annotate pkg/models/colors.go @ 5591:0011f50cf216 surveysperbottleneckid
Removed no longer used alternative api for surveys/ endpoint.
As bottlenecks in the summary for SR imports are now identified by
their id and no longer by the (not guarantied to be unique!) name,
there is no longer the need to request survey data by the name+date
tuple (which isn't reliable anyway). So the workaround was now
reversed.
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Wed, 06 Apr 2022 13:30:29 +0200 |
parents | 18d5461bec5d |
children |
rev | line source |
---|---|
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 // * Markus Kottländer <markus.kottlaender@intevation.de> |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package models |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "fmt" |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "image/color" |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "math" |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "sort" |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "strconv" |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "strings" |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 ) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 type ( |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
27 // ColorValue models a tuple of a floating point value and a color. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ColorValue struct { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 Value float64 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 Color color.RGBA |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
33 // ColorValues are a list of color values. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
34 // Colors between the given ones are linear interpolated. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 ColorValues []ColorValue |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
37 // ClassBreak is a potential open interval of values associated |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
38 // with a color. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 ClassBreak struct { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 High float64 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 HasHigh bool |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Low float64 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 HasLow bool |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 Col color.RGBA |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 ) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
48 // Color gives a HTML compatible string representation of the color |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
49 // of the class break. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 func (cb *ClassBreak) Color() string { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 return fmt.Sprintf("#%02x%02x%02x", |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 cb.Col.R, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 cb.Col.G, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 cb.Col.B, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 ) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
58 // ClassBreaks converts a list of colors to a list of class breaks. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
59 // The first an the last class break are open on the respective end. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 func (cc ColorValues) ClassBreaks() []ClassBreak { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 cbs := make([]ClassBreak, len(cc), len(cc)+1) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 for i := range cc { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 if i > 0 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 cbs[i].Low = cc[i-1].Value |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 cbs[i].HasLow = true |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 cbs[i].High = cc[i].Value |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 cbs[i].HasHigh = true |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 cbs[i].Col = cc[i].Color |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 if len(cc) > 0 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 cbs = append(cbs, ClassBreak{ |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 Col: cc[len(cc)-1].Color, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 Low: cc[len(cc)-1].Value, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 HasLow: true, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 return cbs |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
83 // Heights extracts the values friom the color value pairs. |
4556
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
84 func (cc ColorValues) Heights() []float64 { |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
85 heights := make([]float64, len(cc)) |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
86 for i := range cc { |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
87 heights[i] = cc[i].Value |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
88 } |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
89 return heights |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
90 } |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
91 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
92 // Clip does the same as Interpolate |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
93 // but if the value is out of bounds the value of the nearest border |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
94 // is returned. |
4556
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
95 func (cc ColorValues) Clip(v float64) color.RGBA { |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
96 if len(cc) == 0 { |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
97 return color.RGBA{} |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
98 } |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
99 if v < cc[0].Value { |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
100 return cc[0].Color |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
101 } |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
102 if v > cc[len(cc)-1].Value { |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
103 return cc[len(cc)-1].Color |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
104 } |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
105 c, _ := cc.Interpolate(v) |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
106 return c |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
107 } |
04eba9dc917d
Use colors from configuration instead of random rgb values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3897
diff
changeset
|
108 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
109 // Interpolate interpolates the color linearly between the |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
110 // given values of the color values. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
111 // If the value is out of bounds false is returned. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 func (cc ColorValues) Interpolate(v float64) (color.RGBA, bool) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 if len(cc) == 0 || v < cc[0].Value || v > cc[len(cc)-1].Value { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 return color.RGBA{}, false |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 if len(cc) == 1 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 return cc[0].Color, cc[0].Value == v |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 for i := 0; i < len(cc)-1; i++ { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 v1 := cc[i].Value |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 v2 := cc[i+1].Value |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 if v1 <= v && v <= v2 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 // f(v1) = 0 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 // f(v2) = 1 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 // 0 = m*v1 + c <=> c = -m*v1 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 // 1 = m*v2 + c |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 // (1 - 0) = m*(v2 - v1) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 // m = 1/(v2 - v1) for v2 != v1 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 if v1 == v2 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 return color.RGBA{ |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 R: uint8((uint16(cc[i].Color.R) + uint16(cc[i+1].Color.R)) / 2), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 G: uint8((uint16(cc[i].Color.G) + uint16(cc[i+1].Color.G)) / 2), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 B: uint8((uint16(cc[i].Color.B) + uint16(cc[i+1].Color.B)) / 2), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 A: 0xff, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 }, true |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 m := 1 / (v2 - v1) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 c := -m * v1 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 s := v*m + c |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 interpolate := func(a, b uint8) uint8 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 v := math.Round(float64(a) + (float64(b)-float64(a))*s) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 if v < 0 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 return 0 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 if v > 255 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 return 255 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 return uint8(v) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 return color.RGBA{ |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 R: interpolate(cc[i].Color.R, cc[i+1].Color.R), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 G: interpolate(cc[i].Color.G, cc[i+1].Color.G), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 B: interpolate(cc[i].Color.B, cc[i+1].Color.B), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 A: 0xff, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 }, true |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 return color.RGBA{}, false |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 |
4850
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
167 // ParseColorValues parses a string to a list of color values. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
168 // The value/color pairs are separated by ','. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
169 // A color/value pair is separated with ':'. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
170 // f ':' is missing it is assumed that only the value is given. |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
171 // The missing color is interpolated from fore and aftermost |
18d5461bec5d
Fixed some golint issues.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4556
diff
changeset
|
172 // value/colors pairs. |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 func ParseColorValues(s string) (ColorValues, error) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 var err error |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 parseFloat := func(s string) float64 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 var v float64 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 if err == nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 v, err = strconv.ParseFloat(s, 64) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 return v |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 parseColor := func(s string) color.RGBA { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 if err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 return color.RGBA{} |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 s = strings.Map(func(r rune) rune { |
3897
859210ee6440
Cosmetics: Don't lower the runes in the color strings used in class break definitions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
190 if ('0' <= r && r <= '9') || |
859210ee6440
Cosmetics: Don't lower the runes in the color strings used in class break definitions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
191 ('a' <= r && r <= 'f') || |
859210ee6440
Cosmetics: Don't lower the runes in the color strings used in class break definitions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
192 ('A' <= r && r <= 'F') { |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 return r |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 return -1 |
3897
859210ee6440
Cosmetics: Don't lower the runes in the color strings used in class break definitions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
196 }, s) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 var v int64 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 v, err = strconv.ParseInt(s, 16, 64) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 return color.RGBA{ |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 R: uint8(v >> 16), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 G: uint8(v >> 8), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 B: uint8(v >> 0), |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 A: 0xff, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 lines := strings.Split(s, ",") |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 // first pass: find defined colors |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 var defined ColorValues |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 for _, line := range lines { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 // ignore the lines w/o a color. |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 if !strings.ContainsRune(line, ':') { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 continue |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 parts := strings.SplitN(line, ":", 2) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 if len(parts) < 2 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 continue |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 value := parseFloat(parts[0]) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 color := parseColor(parts[1]) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 defined = append(defined, ColorValue{ |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 Value: value, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 Color: color, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 if err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 return nil, err |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 sort.Slice(defined, func(i, j int) bool { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 return defined[i].Value < defined[j].Value |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 // second pass: interpolate the rest |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 var final ColorValues |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 for _, line := range lines { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 if idx := strings.IndexRune(line, ':'); idx >= 0 { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 line = line[:idx] |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 value := parseFloat(line) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 if color, ok := defined.Interpolate(value); ok { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 final = append(final, ColorValue{ |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 Value: value, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 Color: color, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 return final, err |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 } |