removing point, adding tests.
This commit is contained in:
parent
1c3473f674
commit
bacb0023b5
3 changed files with 48 additions and 41 deletions
21
box_test.go
21
box_test.go
|
@ -85,3 +85,24 @@ func TestBoxFit(t *testing.T) {
|
|||
assert.Equal(a.Bottom, fac.Bottom)
|
||||
assert.True(math.Abs(c.Aspect()-fac.Aspect()) < 0.02)
|
||||
}
|
||||
|
||||
func TestBoxOuterConstrain(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
box := Box{0, 0, 100, 100}
|
||||
canvas := Box{5, 5, 95, 95}
|
||||
taller := Box{-10, 5, 50, 50}
|
||||
|
||||
c := canvas.OuterConstrain(box, taller)
|
||||
assert.Equal(15, c.Top, c.String())
|
||||
assert.Equal(5, c.Left, c.String())
|
||||
assert.Equal(95, c.Right, c.String())
|
||||
assert.Equal(95, c.Bottom, c.String())
|
||||
|
||||
wider := Box{5, 5, 110, 50}
|
||||
d := canvas.OuterConstrain(box, wider)
|
||||
assert.Equal(5, d.Top, d.String())
|
||||
assert.Equal(5, d.Left, d.String())
|
||||
assert.Equal(85, d.Right, d.String())
|
||||
assert.Equal(95, d.Bottom, d.String())
|
||||
}
|
||||
|
|
27
grid_line_test.go
Normal file
27
grid_line_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package chart
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/blendlabs/go-assert"
|
||||
)
|
||||
|
||||
func TestGenerateGridLines(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
ticks := []Tick{
|
||||
Tick{Value: 1.0, Label: "1.0"},
|
||||
Tick{Value: 2.0, Label: "2.0"},
|
||||
Tick{Value: 3.0, Label: "3.0"},
|
||||
Tick{Value: 4.0, Label: "4.0"},
|
||||
}
|
||||
|
||||
gl := GenerateGridLines(ticks, true)
|
||||
assert.Len(gl, 4)
|
||||
assert.Equal(1.0, gl[0].Value)
|
||||
assert.Equal(2.0, gl[1].Value)
|
||||
assert.Equal(3.0, gl[2].Value)
|
||||
assert.Equal(4.0, gl[3].Value)
|
||||
|
||||
assert.True(gl[0].IsVertical)
|
||||
}
|
41
point.go
41
point.go
|
@ -1,41 +0,0 @@
|
|||
package chart
|
||||
|
||||
// Points are an array of points.
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Point represents a x,y coordinate.
|
||||
type Point struct {
|
||||
X float64
|
||||
Y float64
|
||||
}
|
||||
|
||||
// Points represents a group of points.
|
||||
type Points []Point
|
||||
|
||||
// String returns a string representation of the points.
|
||||
func (p Points) String() string {
|
||||
var values []string
|
||||
for _, v := range p {
|
||||
values = append(values, fmt.Sprintf("%d,%d", int(v.X), int(v.Y)))
|
||||
}
|
||||
return strings.Join(values, "\n")
|
||||
}
|
||||
|
||||
// Len returns the length of the points set.
|
||||
func (p Points) Len() int {
|
||||
return len(p)
|
||||
}
|
||||
|
||||
// Swap swaps two elments.
|
||||
func (p Points) Swap(i, j int) {
|
||||
p[i], p[j] = p[j], p[i]
|
||||
}
|
||||
|
||||
// Less returns if the X value of one element is less than another.
|
||||
// This is the default sort for charts where you plot by x values in order.
|
||||
func (p Points) Less(i, j int) bool {
|
||||
return p[i].X < p[j].X
|
||||
}
|
Loading…
Reference in a new issue