| 1 |
package chart |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/wcharczuk/go-chart/v2/testutil" |
| 7 |
) |
| 8 |
|
| 9 |
func TestYAxisGetTicks(t *testing.T) { |
| 10 |
|
| 11 |
|
| 12 |
r, err := PNG(1024, 1024) |
| 13 |
testutil.AssertNil(t, err) |
| 14 |
|
| 15 |
f, err := GetDefaultFont() |
| 16 |
testutil.AssertNil(t, err) |
| 17 |
|
| 18 |
ya := YAxis{} |
| 19 |
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} |
| 20 |
styleDefaults := Style{ |
| 21 |
Font: f, |
| 22 |
FontSize: 10.0, |
| 23 |
} |
| 24 |
vf := FloatValueFormatter |
| 25 |
ticks := ya.GetTicks(r, yr, styleDefaults, vf) |
| 26 |
testutil.AssertLen(t, ticks, 32) |
| 27 |
} |
| 28 |
|
| 29 |
func TestYAxisGetTicksWithUserDefaults(t *testing.T) { |
| 30 |
|
| 31 |
|
| 32 |
r, err := PNG(1024, 1024) |
| 33 |
testutil.AssertNil(t, err) |
| 34 |
|
| 35 |
f, err := GetDefaultFont() |
| 36 |
testutil.AssertNil(t, err) |
| 37 |
|
| 38 |
ya := YAxis{ |
| 39 |
Ticks: []Tick{{Value: 1.0, Label: "1.0"}}, |
| 40 |
} |
| 41 |
yr := &ContinuousRange{Min: 10, Max: 100, Domain: 1024} |
| 42 |
styleDefaults := Style{ |
| 43 |
Font: f, |
| 44 |
FontSize: 10.0, |
| 45 |
} |
| 46 |
vf := FloatValueFormatter |
| 47 |
ticks := ya.GetTicks(r, yr, styleDefaults, vf) |
| 48 |
testutil.AssertLen(t, ticks, 1) |
| 49 |
} |
| 50 |
|
| 51 |
func TestYAxisMeasure(t *testing.T) { |
| 52 |
|
| 53 |
|
| 54 |
f, err := GetDefaultFont() |
| 55 |
testutil.AssertNil(t, err) |
| 56 |
style := Style{ |
| 57 |
Font: f, |
| 58 |
FontSize: 10.0, |
| 59 |
} |
| 60 |
r, err := PNG(100, 100) |
| 61 |
testutil.AssertNil(t, err) |
| 62 |
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} |
| 63 |
ya := YAxis{} |
| 64 |
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) |
| 65 |
testutil.AssertEqual(t, 32, yab.Width()) |
| 66 |
testutil.AssertEqual(t, 110, yab.Height()) |
| 67 |
} |
| 68 |
|
| 69 |
func TestYAxisSecondaryMeasure(t *testing.T) { |
| 70 |
|
| 71 |
|
| 72 |
f, err := GetDefaultFont() |
| 73 |
testutil.AssertNil(t, err) |
| 74 |
style := Style{ |
| 75 |
Font: f, |
| 76 |
FontSize: 10.0, |
| 77 |
} |
| 78 |
r, err := PNG(100, 100) |
| 79 |
testutil.AssertNil(t, err) |
| 80 |
ticks := []Tick{{Value: 1.0, Label: "1.0"}, {Value: 2.0, Label: "2.0"}, {Value: 3.0, Label: "3.0"}} |
| 81 |
ya := YAxis{AxisType: YAxisSecondary} |
| 82 |
yab := ya.Measure(r, NewBox(0, 0, 100, 100), &ContinuousRange{Min: 1.0, Max: 3.0, Domain: 100}, style, ticks) |
| 83 |
testutil.AssertEqual(t, 32, yab.Width()) |
| 84 |
testutil.AssertEqual(t, 110, yab.Height()) |
| 85 |
} |