| 1 |
package charts |
| 2 |
|
| 3 |
import ( |
| 4 |
"log" |
| 5 |
|
| 6 |
"github.com/go-echarts/go-echarts/v2/datasets" |
| 7 |
"github.com/go-echarts/go-echarts/v2/opts" |
| 8 |
"github.com/go-echarts/go-echarts/v2/render" |
| 9 |
"github.com/go-echarts/go-echarts/v2/types" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
type Geo struct { |
| 14 |
BaseConfiguration |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
func (*Geo) Type() string { return types.ChartGeo } |
| 19 |
|
| 20 |
var geoFormatter = `function (params) { |
| 21 |
return params.name + ' : ' + params.value[2]; |
| 22 |
}` |
| 23 |
|
| 24 |
|
| 25 |
func NewGeo() *Geo { |
| 26 |
c := &Geo{} |
| 27 |
c.initBaseConfiguration() |
| 28 |
c.Renderer = render.NewChartRender(c, c.Validate) |
| 29 |
c.hasGeo = true |
| 30 |
return c |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
func (c *Geo) AddSeries(name, geoType string, data []opts.GeoData, options ...SeriesOpts) *Geo { |
| 39 |
series := SingleSeries{Name: name, Type: geoType, Data: data, CoordSystem: types.ChartGeo} |
| 40 |
series.ConfigureSeriesOpts(options...) |
| 41 |
c.MultiSeries = append(c.MultiSeries, series) |
| 42 |
return c |
| 43 |
} |
| 44 |
|
| 45 |
func (c *Geo) extendValue(region string, v float32) []float32 { |
| 46 |
res := make([]float32, 0) |
| 47 |
tv := datasets.Coordinates[region] |
| 48 |
if tv == [2]float32{0, 0} { |
| 49 |
log.Printf("goecharts: No coordinate is specified for %s\n", region) |
| 50 |
} else { |
| 51 |
res = append(tv[:], v) |
| 52 |
} |
| 53 |
return res |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
func (c *Geo) SetGlobalOptions(options ...GlobalOpts) *Geo { |
| 58 |
c.BaseConfiguration.setBaseGlobalOptions(options...) |
| 59 |
return c |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
func (c *Geo) Validate() { |
| 64 |
if c.Tooltip.Formatter == "" { |
| 65 |
c.Tooltip.Formatter = opts.FuncOpts(geoFormatter) |
| 66 |
} |
| 67 |
c.Assets.Validate(c.AssetsHost) |
| 68 |
} |