102 lines
7.7 KiB
Go
102 lines
7.7 KiB
Go
// MIT License
|
|
|
|
// Copyright (c) 2022 Tree Xie
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
// copies or substantial portions of the Software.
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
// SOFTWARE.
|
|
|
|
package charts
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/wcharczuk/go-chart/v2"
|
|
)
|
|
|
|
func TestRadarChartRender(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
d, err := NewDraw(DrawOption{
|
|
Width: 250,
|
|
Height: 150,
|
|
})
|
|
assert.Nil(err)
|
|
|
|
f, _ := chart.GetDefaultFont()
|
|
err = radarChartRender(radarChartOption{
|
|
Font: f,
|
|
Indicators: []RadarIndicator{
|
|
{
|
|
Name: "Sales",
|
|
Max: 6500,
|
|
},
|
|
{
|
|
Name: "Administration",
|
|
Max: 16000,
|
|
},
|
|
{
|
|
Name: "Information Technology",
|
|
Max: 30000,
|
|
},
|
|
{
|
|
Name: "Customer Support",
|
|
Max: 38000,
|
|
},
|
|
{
|
|
Name: "Development",
|
|
Max: 52000,
|
|
},
|
|
{
|
|
Name: "Marketing",
|
|
Max: 25000,
|
|
},
|
|
},
|
|
SeriesList: SeriesList{
|
|
{
|
|
Type: ChartTypeRadar,
|
|
Data: NewSeriesDataFromValues([]float64{
|
|
4200,
|
|
3000,
|
|
20000,
|
|
35000,
|
|
50000,
|
|
18000,
|
|
}),
|
|
},
|
|
{
|
|
Type: ChartTypeRadar,
|
|
index: 1,
|
|
Data: NewSeriesDataFromValues([]float64{
|
|
5000,
|
|
14000,
|
|
28000,
|
|
26000,
|
|
42000,
|
|
21000,
|
|
}),
|
|
},
|
|
},
|
|
}, &basicRenderResult{
|
|
d: d,
|
|
})
|
|
assert.Nil(err)
|
|
data, err := d.Bytes()
|
|
assert.Nil(err)
|
|
assert.Equal("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"250\" height=\"150\">\\n<path d=\"M 125 63\nL 135 69\nL 135 80\nL 125 87\nL 115 81\nL 115 70\nL 125 63\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 51\nL 145 63\nL 145 86\nL 125 99\nL 105 87\nL 105 64\nL 125 51\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 39\nL 156 57\nL 156 92\nL 125 111\nL 94 93\nL 94 58\nL 125 39\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 27\nL 166 51\nL 166 98\nL 125 123\nL 84 99\nL 84 52\nL 125 27\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 15\nL 176 45\nL 176 104\nL 125 135\nL 74 105\nL 74 46\nL 125 15\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 75\nL 125 15\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 75\nL 176 45\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 75\nL 176 104\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 75\nL 125 135\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 75\nL 74 105\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 125 75\nL 74 46\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><text x=\"109\" y=\"8\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">Sales</text><text x=\"181\" y=\"50\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">Administration</text><text x=\"181\" y=\"109\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">Information Technology</text><text x=\"73\" y=\"152\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">Customer Support</text><text x=\"-7\" y=\"110\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">Development</text><text x=\"10\" y=\"51\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">Marketing</text><path d=\"M 125 37\nL 134 70\nL 159 94\nL 125 130\nL 76 103\nL 88 54\nL 125 37\" style=\"stroke-width:2;stroke:rgba(84,112,198,1.0);fill:none\"/><path d=\"M 125 37\nL 134 70\nL 159 94\nL 125 130\nL 76 103\nL 88 54\nL 125 37\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,0.1)\"/><circle cx=\"125\" cy=\"37\" 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=\"134\" cy=\"70\" 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=\"159\" cy=\"94\" 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=\"125\" cy=\"130\" 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=\"76\" cy=\"103\" 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=\"88\" cy=\"54\" 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 125 29\nL 170 49\nL 173 102\nL 125 116\nL 84 99\nL 82 50\nL 125 29\" style=\"stroke-width:2;stroke:rgba(145,204,117,1.0);fill:none\"/><path d=\"M 125 29\nL 170 49\nL 173 102\nL 125 116\nL 84 99\nL 82 50\nL 125 29\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,0.1)\"/><circle cx=\"125\" cy=\"29\" 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=\"170\" cy=\"49\" 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=\"173\" cy=\"102\" 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=\"125\" cy=\"116\" 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=\"84\" cy=\"99\" 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=\"82\" cy=\"50\" 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))
|
|
}
|