feat: support customize title

This commit is contained in:
vicanso 2022-01-01 20:11:51 +08:00
parent 06c326bdc3
commit 25e9984ad8
8 changed files with 167 additions and 7 deletions

View file

@ -76,3 +76,38 @@ func TestNewLegendCustomize(t *testing.T) {
assert.Equal(tt.svg, buf.String())
}
}
func TestConvertPercent(t *testing.T) {
assert := assert.New(t)
assert.Equal(-1.0, convertPercent("12"))
assert.Equal(0.12, convertPercent("12%"))
}
func TestGetLegendLeft(t *testing.T) {
assert := assert.New(t)
assert.Equal(150, getLegendLeft(500, 200, LegendOption{}))
assert.Equal(0, getLegendLeft(500, 200, LegendOption{
Left: "left",
}))
assert.Equal(100, getLegendLeft(500, 200, LegendOption{
Left: "20%",
}))
assert.Equal(20, getLegendLeft(500, 200, LegendOption{
Left: "20",
}))
assert.Equal(300, getLegendLeft(500, 200, LegendOption{
Right: "right",
}))
assert.Equal(200, getLegendLeft(500, 200, LegendOption{
Right: "20%",
}))
assert.Equal(280, getLegendLeft(500, 200, LegendOption{
Right: "20",
}))
}