test: fix test
This commit is contained in:
parent
9763d48eef
commit
7ea306b7f4
4 changed files with 12 additions and 7 deletions
|
|
@ -76,7 +76,7 @@ type EChartsSeriesData struct {
|
||||||
}
|
}
|
||||||
type _EChartsSeriesData EChartsSeriesData
|
type _EChartsSeriesData EChartsSeriesData
|
||||||
|
|
||||||
var numericRep = regexp.MustCompile("^[-+]?[0-9]+(?:\\.[0-9]+)?$")
|
var numericRep = regexp.MustCompile(`^[-+]?[0-9]+(?:\\.[0-9]+)?$`)
|
||||||
|
|
||||||
func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error {
|
func (es *EChartsSeriesData) UnmarshalJSON(data []byte) error {
|
||||||
data = bytes.TrimSpace(data)
|
data = bytes.TrimSpace(data)
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,8 @@ func TestEChartsPadding(t *testing.T) {
|
||||||
|
|
||||||
ep := EChartsPadding{}
|
ep := EChartsPadding{}
|
||||||
|
|
||||||
ep.UnmarshalJSON([]byte(`10`))
|
err := ep.UnmarshalJSON([]byte(`10`))
|
||||||
|
assert.Nil(err)
|
||||||
assert.Equal(EChartsPadding{
|
assert.Equal(EChartsPadding{
|
||||||
Box: chart.Box{
|
Box: chart.Box{
|
||||||
Top: 10,
|
Top: 10,
|
||||||
|
|
@ -176,7 +177,8 @@ func TestEChartsPadding(t *testing.T) {
|
||||||
}, ep)
|
}, ep)
|
||||||
|
|
||||||
ep = EChartsPadding{}
|
ep = EChartsPadding{}
|
||||||
ep.UnmarshalJSON([]byte(`[10, 20]`))
|
err = ep.UnmarshalJSON([]byte(`[10, 20]`))
|
||||||
|
assert.Nil(err)
|
||||||
assert.Equal(EChartsPadding{
|
assert.Equal(EChartsPadding{
|
||||||
Box: chart.Box{
|
Box: chart.Box{
|
||||||
Top: 10,
|
Top: 10,
|
||||||
|
|
@ -187,7 +189,8 @@ func TestEChartsPadding(t *testing.T) {
|
||||||
}, ep)
|
}, ep)
|
||||||
|
|
||||||
ep = EChartsPadding{}
|
ep = EChartsPadding{}
|
||||||
ep.UnmarshalJSON([]byte(`[10, 20, 30]`))
|
err = ep.UnmarshalJSON([]byte(`[10, 20, 30]`))
|
||||||
|
assert.Nil(err)
|
||||||
assert.Equal(EChartsPadding{
|
assert.Equal(EChartsPadding{
|
||||||
Box: chart.Box{
|
Box: chart.Box{
|
||||||
Top: 10,
|
Top: 10,
|
||||||
|
|
@ -198,7 +201,8 @@ func TestEChartsPadding(t *testing.T) {
|
||||||
}, ep)
|
}, ep)
|
||||||
|
|
||||||
ep = EChartsPadding{}
|
ep = EChartsPadding{}
|
||||||
ep.UnmarshalJSON([]byte(`[10, 20, 30, 40]`))
|
err = ep.UnmarshalJSON([]byte(`[10, 20, 30, 40]`))
|
||||||
|
assert.Nil(err)
|
||||||
assert.Equal(EChartsPadding{
|
assert.Equal(EChartsPadding{
|
||||||
Box: chart.Box{
|
Box: chart.Box{
|
||||||
Top: 10,
|
Top: 10,
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -4,13 +4,13 @@ go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/wcharczuk/go-chart/v2 v2.1.0
|
github.com/wcharczuk/go-chart/v2 v2.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
|
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func TestLineChartRender(t *testing.T) {
|
||||||
d: d,
|
d: d,
|
||||||
}
|
}
|
||||||
f, _ := chart.GetDefaultFont()
|
f, _ := chart.GetDefaultFont()
|
||||||
lineChartRender(lineChartOption{
|
_, err = lineChartRender(lineChartOption{
|
||||||
Font: f,
|
Font: f,
|
||||||
SeriesList: SeriesList{
|
SeriesList: SeriesList{
|
||||||
{
|
{
|
||||||
|
|
@ -90,6 +90,7 @@ func TestLineChartRender(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}, &result)
|
}, &result)
|
||||||
|
assert.Nil(err)
|
||||||
data, err := d.Bytes()
|
data, err := d.Bytes()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Equal("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"400\" height=\"300\">\\n<circle cx=\"40\" cy=\"130\" r=\"3\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 45 130\nL 382 130\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path d=\"M 382 125\nL 398 130\nL 382 135\nL 387 130\nL 382 125\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><text x=\"400\" y=\"134\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">56.66</text><text x=\"83\" y=\"235\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,255,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">20</text><text x=\"183\" y=\"115\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,255,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">60</text><text x=\"283\" y=\"25\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,255,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">90</text><path d=\"M 90 240\nL 190 120\nL 290 30\" style=\"stroke-width:2;stroke:rgba(84,112,198,1.0);fill:none\"/><circle cx=\"90\" cy=\"240\" r=\"2\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"190\" cy=\"120\" r=\"2\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"290\" cy=\"30\" r=\"2\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"M 90 180\nL 190 120\nL 290 90\" style=\"stroke-width:2;stroke:rgba(145,204,117,1.0);fill:none\"/><circle cx=\"90\" cy=\"180\" r=\"2\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"190\" cy=\"120\" r=\"2\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"290\" cy=\"90\" r=\"2\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/></svg>", string(data))
|
assert.Equal("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"400\" height=\"300\">\\n<circle cx=\"40\" cy=\"130\" r=\"3\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path stroke-dasharray=\"4.0, 2.0\" d=\"M 45 130\nL 382 130\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path d=\"M 382 125\nL 398 130\nL 382 135\nL 387 130\nL 382 125\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><text x=\"400\" y=\"134\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">56.66</text><text x=\"83\" y=\"235\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,255,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">20</text><text x=\"183\" y=\"115\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,255,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">60</text><text x=\"283\" y=\"25\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,255,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">90</text><path d=\"M 90 240\nL 190 120\nL 290 30\" style=\"stroke-width:2;stroke:rgba(84,112,198,1.0);fill:none\"/><circle cx=\"90\" cy=\"240\" r=\"2\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"190\" cy=\"120\" r=\"2\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"290\" cy=\"30\" r=\"2\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(84,112,198,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"M 90 180\nL 190 120\nL 290 90\" style=\"stroke-width:2;stroke:rgba(145,204,117,1.0);fill:none\"/><circle cx=\"90\" cy=\"180\" r=\"2\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"190\" cy=\"120\" r=\"2\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><circle cx=\"290\" cy=\"90\" r=\"2\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(145,204,117,1.0);fill:rgba(255,255,255,1.0)\"/></svg>", string(data))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue