Debian Codegraph @

charts/map.go

raw symbols SCIP
1 package charts
2
3 import (
4 "github.com/go-echarts/go-echarts/v2/datasets"
5 "github.com/go-echarts/go-echarts/v2/opts"
6 "github.com/go-echarts/go-echarts/v2/render"
7 "github.com/go-echarts/go-echarts/v2/types"
8 )
9
10 // Map represents a map chart.
11 type Map struct {
12 BaseConfiguration
13
14 mapType string
15 }
16
17 // Type returns the chart type.
18 func (*Map) Type() string { return types.ChartMap }
19
20 // NewMap creates a new map chart.
21 func NewMap() *Map {
22 c := &Map{}
23 c.initBaseConfiguration()
24 c.Renderer = render.NewChartRender(c, c.Validate)
25 return c
26 }
27
28 // RegisterMapType registers the given mapType.
29 func (c *Map) RegisterMapType(mapType string) {
30 c.mapType = mapType
31 mapFile, preset := datasets.PresetMapFileNames[mapType]
32 if preset {
33 c.JSAssets.Add("maps/" + mapFile + ".js")
34 }
35 }
36
37 // AddSeries adds new data sets.
38 func (c *Map) AddSeries(name string, data []opts.MapData, options ...SeriesOpts) *Map {
39 series := SingleSeries{Name: name, Type: types.ChartMap, MapType: c.mapType, Data: data}
40 series.ConfigureSeriesOpts(options...)
41 c.MultiSeries = append(c.MultiSeries, series)
42 return c
43 }
44
45 // SetGlobalOptions sets options for the Map instance.
46 func (c *Map) SetGlobalOptions(options ...GlobalOpts) *Map {
47 c.BaseConfiguration.setBaseGlobalOptions(options...)
48 return c
49 }
50
51 // Validate validates the given configuration.
52 func (c *Map) Validate() {
53 c.Assets.Validate(c.AssetsHost)
54 }