# HG changeset patch # User Sascha L. Teichmann # Date 1574163952 -3600 # Node ID 18d5461bec5de860e4bf0cea8b7a4e5cfa306a62 # Parent 8584197232ec86de097d058605af3991f35820f0 Fixed some golint issues. diff -r 8584197232ec -r 18d5461bec5d pkg/common/linear.go --- a/pkg/common/linear.go Mon Nov 18 16:38:28 2019 +0100 +++ b/pkg/common/linear.go Tue Nov 19 12:45:52 2019 +0100 @@ -10,6 +10,7 @@ // // Author(s): // * Sascha L. Teichmann + package common // Linear constructs a function which maps x1 to y1 and x2 to y2. diff -r 8584197232ec -r 18d5461bec5d pkg/models/colors.go --- a/pkg/models/colors.go Mon Nov 18 16:38:28 2019 +0100 +++ b/pkg/models/colors.go Tue Nov 19 12:45:52 2019 +0100 @@ -24,13 +24,18 @@ ) type ( + // ColorValue models a tuple of a floating point value and a color. ColorValue struct { Value float64 Color color.RGBA } + // ColorValues are a list of color values. + // Colors between the given ones are linear interpolated. ColorValues []ColorValue + // ClassBreak is a potential open interval of values associated + // with a color. ClassBreak struct { High float64 HasHigh bool @@ -40,6 +45,8 @@ } ) +// Color gives a HTML compatible string representation of the color +// of the class break. func (cb *ClassBreak) Color() string { return fmt.Sprintf("#%02x%02x%02x", cb.Col.R, @@ -48,6 +55,8 @@ ) } +// ClassBreaks converts a list of colors to a list of class breaks. +// The first an the last class break are open on the respective end. func (cc ColorValues) ClassBreaks() []ClassBreak { cbs := make([]ClassBreak, len(cc), len(cc)+1) @@ -71,6 +80,7 @@ return cbs } +// Heights extracts the values friom the color value pairs. func (cc ColorValues) Heights() []float64 { heights := make([]float64, len(cc)) for i := range cc { @@ -79,6 +89,9 @@ return heights } +// Clip does the same as Interpolate +// but if the value is out of bounds the value of the nearest border +// is returned. func (cc ColorValues) Clip(v float64) color.RGBA { if len(cc) == 0 { return color.RGBA{} @@ -93,6 +106,9 @@ return c } +// Interpolate interpolates the color linearly between the +// given values of the color values. +// If the value is out of bounds false is returned. func (cc ColorValues) Interpolate(v float64) (color.RGBA, bool) { if len(cc) == 0 || v < cc[0].Value || v > cc[len(cc)-1].Value { return color.RGBA{}, false @@ -148,6 +164,12 @@ return color.RGBA{}, false } +// ParseColorValues parses a string to a list of color values. +// The value/color pairs are separated by ','. +// A color/value pair is separated with ':'. +// f ':' is missing it is assumed that only the value is given. +// The missing color is interpolated from fore and aftermost +// value/colors pairs. func ParseColorValues(s string) (ColorValues, error) { var err error