-
Notifications
You must be signed in to change notification settings - Fork 547
/
map.go
57 lines (47 loc) 路 1.41 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package charts
import (
"github.com/go-echarts/go-echarts/datatypes"
"io"
"github.com/go-echarts/go-echarts/datasets"
)
// Map represents a map chart.
type Map struct {
BaseOpts
Series
mapType string
}
func (Map) chartType() string { return ChartType.Map }
// NewMap creates a new map chart.
func NewMap(mapType string, routers ...RouterOpts) *Map {
chart := new(Map)
chart.mapType = mapType
chart.initBaseOpts(routers...)
chart.JSAssets.Add("maps/" + datasets.MapFileNames[mapType] + ".js")
return chart
}
// Add adds new data sets.
func (c *Map) Add(name string, data map[string]float32, options ...SeriesOptser) *Map {
nvs := make([]datatypes.NameValueItem, 0)
for k, v := range data {
nvs = append(nvs, datatypes.NameValueItem{Name: k, Value: v})
}
series := singleSeries{Name: name, Type: ChartType.Map, MapType: c.mapType, Data: nvs}
series.setSingleSeriesOpts(options...)
c.Series = append(c.Series, series)
c.setColor(options...)
return c
}
// SetGlobalOptions sets options for the Map instance.
func (c *Map) SetGlobalOptions(options ...GlobalOptser) *Map {
c.BaseOpts.setBaseGlobalOptions(options...)
return c
}
func (c *Map) validateOpts() {
c.validateAssets(c.AssetsHost)
}
// Render renders the chart and writes the output to given writers.
func (c *Map) Render(w ...io.Writer) error {
c.insertSeriesColors(c.appendColor)
c.validateOpts()
return renderToWriter(c, "chart", []string{}, w...)
}