Mercurial > gemma
comparison pkg/geoserver/templates_test.go @ 3828:885eb90255ff sld-colors
Cleanup templating of styles [WIP].
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 03 Jul 2019 18:26:41 +0200 |
parents | 4b1184fa0326 |
children | 464a6a6e05e6 |
comparison
equal
deleted
inserted
replaced
3827:6028326b88d6 | 3828:885eb90255ff |
---|---|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | 12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
13 | 13 |
14 package geoserver | 14 package geoserver |
15 | 15 |
16 import ( | 16 import ( |
17 "fmt" | |
18 "strings" | 17 "strings" |
19 "testing" | 18 "testing" |
20 "text/template" | 19 "text/template" |
21 | 20 |
22 "github.com/sergi/go-diff/diffmatchpatch" | 21 "github.com/sergi/go-diff/diffmatchpatch" |
164 <ogc:Literal>0.0</ogc:Literal> | 163 <ogc:Literal>0.0</ogc:Literal> |
165 <ogc:PropertyName>height</ogc:PropertyName> | 164 <ogc:PropertyName>height</ogc:PropertyName> |
166 </ogc:Function> | 165 </ogc:Function> |
167 {{- range . }} | 166 {{- range . }} |
168 {{ if .HasHigh -}} | 167 {{ if .HasHigh -}} |
169 <ogc:Literal>{{ printf "%.1f" .High}}</ogc:Literal><ogc:Literal>{{ printf "%.1f" .High}}</ogc:Literal> | 168 <ogc:Literal>{{ printf "%.1f" .High}}</ogc:Literal><ogc:Literal>{{ printf "%.1f" .High}}</ogc:Literal> |
170 {{- else if .HasLow -}} | 169 {{- else if .HasLow -}} |
171 <ogc:Literal>{{ printf "%.1f" .Low}}</ogc:Literal><ogc:Literal>{{ printf "%.1f" .Low}}</ogc:Literal> | 170 <ogc:Literal>{{ printf "%.1f" .Low}}</ogc:Literal><ogc:Literal>{{ printf "%.1f" .Low}}</ogc:Literal> |
172 {{- end }} | 171 {{- end }} |
173 {{- end }} | 172 {{- end }} |
174 </ogc:Function> | 173 </ogc:Function> |
175 </se:Label> | 174 </se:Label> |
176 <se:LabelPlacement> | 175 <se:LabelPlacement> |
177 <se:LinePlacement> | 176 <se:LinePlacement> |
896 </StyledLayerDescriptor> | 895 </StyledLayerDescriptor> |
897 ` | 896 ` |
898 | 897 |
899 const classBreaksConfig = `1:#ff00dd,1.5,1.7,1.9,2.1,2.3,2.5:#f25f20,2.7,2.9,3.1,3.3,3.5,4:#8ad51a,4.5,5,5.5,6,6.5,7,7.5:#1414ff` | 898 const classBreaksConfig = `1:#ff00dd,1.5,1.7,1.9,2.1,2.3,2.5:#f25f20,2.7,2.9,3.1,3.3,3.5,4:#8ad51a,4.5,5,5.5,6,6.5,7,7.5:#1414ff` |
900 | 899 |
901 type classBreaks struct { | |
902 High float64 | |
903 HasHigh bool | |
904 Low float64 | |
905 HasLow bool | |
906 Color string | |
907 } | |
908 | |
909 func TestTemplate(t *testing.T) { | 900 func TestTemplate(t *testing.T) { |
910 | 901 |
911 ccs, err := parseColorClasses(classBreaksConfig) | 902 ccs, err := parseColorClasses(classBreaksConfig) |
912 if err != nil { | 903 if err != nil { |
913 t.Fatalf("parsing color config failed: %v", err) | 904 t.Fatalf("parsing color config failed: %v", err) |
921 ccs[i].color.G, | 912 ccs[i].color.G, |
922 ccs[i].color.B) | 913 ccs[i].color.B) |
923 } | 914 } |
924 */ | 915 */ |
925 | 916 |
926 cbs := make([]classBreaks, len(ccs)) | 917 cbs := ccs.toClassBreaks() |
927 for i := range ccs { | |
928 if i > 0 { | |
929 cbs[i].Low = ccs[i-1].value | |
930 cbs[i].HasLow = true | |
931 } | |
932 if i < len(ccs)-1 { | |
933 cbs[i].High = ccs[i].value | |
934 cbs[i].HasHigh = true | |
935 } | |
936 cbs[i].Color = fmt.Sprintf("#%02x%02x%02x", | |
937 ccs[i].color.R, | |
938 ccs[i].color.G, | |
939 ccs[i].color.B) | |
940 } | |
941 | 918 |
942 tmpl, err := template.New("test").Parse(sldTmplTxt) | 919 tmpl, err := template.New("test").Parse(sldTmplTxt) |
943 if err != nil { | 920 if err != nil { |
944 t.Fatalf("parsing template failed: %v", err) | 921 t.Fatalf("parsing template failed: %v", err) |
945 } | 922 } |