Adds the ability to draw an XY scatter plot. (#27)
* works more or less * updating comment * removing debugging printf * adding output * tweaks * missed a couple series validations * testing auto coloring * updated output.png * color tests etc. * sanity check tests. * should not use unkeyed fields anyway.
This commit is contained in:
parent
17b28beae8
commit
b713ff85cc
22 changed files with 511 additions and 72 deletions
|
|
@ -46,12 +46,20 @@ func ColorFromHex(hex string) Color {
|
|||
return c
|
||||
}
|
||||
|
||||
// ColorFromAlphaMixedRGBA returns the system alpha mixed rgba values.
|
||||
func ColorFromAlphaMixedRGBA(r, g, b, a uint32) Color {
|
||||
fa := float64(a) / 255.0
|
||||
var c Color
|
||||
c.R = uint8(float64(r) / fa)
|
||||
c.G = uint8(float64(g) / fa)
|
||||
c.B = uint8(float64(b) / fa)
|
||||
c.A = uint8(a | (a >> 8))
|
||||
return c
|
||||
}
|
||||
|
||||
// Color is our internal color type because color.Color is bullshit.
|
||||
type Color struct {
|
||||
R uint8
|
||||
G uint8
|
||||
B uint8
|
||||
A uint8
|
||||
R, G, B, A uint8
|
||||
}
|
||||
|
||||
// RGBA returns the color as a pre-alpha mixed color set.
|
||||
|
|
@ -88,6 +96,24 @@ func (c Color) WithAlpha(a uint8) Color {
|
|||
}
|
||||
}
|
||||
|
||||
// Equals returns true if the color equals another.
|
||||
func (c Color) Equals(other Color) bool {
|
||||
return c.R == other.R &&
|
||||
c.G == other.G &&
|
||||
c.B == other.B &&
|
||||
c.A == other.A
|
||||
}
|
||||
|
||||
// AverageWith averages two colors.
|
||||
func (c Color) AverageWith(other Color) Color {
|
||||
return Color{
|
||||
R: (c.R + other.R) >> 1,
|
||||
G: (c.G + other.G) >> 1,
|
||||
B: (c.B + other.B) >> 1,
|
||||
A: c.A,
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a css string representation of the color.
|
||||
func (c Color) String() string {
|
||||
fa := float64(c.A) / float64(255)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue