Debian Codegraph @

charts/wordcloud.go

raw symbols SCIP
1 package charts
2
3 import (
4 "github.com/go-echarts/go-echarts/v2/opts"
5 "github.com/go-echarts/go-echarts/v2/render"
6 "github.com/go-echarts/go-echarts/v2/types"
7 )
8
9 // WordCloud represents a word cloud chart.
10 type WordCloud struct {
11 BaseConfiguration
12 }
13
14 // Type returns the chart type.
15 func (*WordCloud) Type() string { return types.ChartWordCloud }
16
17 var wcTextColor = `function () {
18 return 'rgb(' + [
19 Math.round(Math.random() * 160),
20 Math.round(Math.random() * 160),
21 Math.round(Math.random() * 160)].join(',') + ')';
22 }`
23
24 // NewWordCloud creates a new word cloud chart.
25 func NewWordCloud() *WordCloud {
26 c := &WordCloud{}
27 c.initBaseConfiguration()
28 c.Renderer = render.NewChartRender(c, c.Validate)
29 c.JSAssets.Add(opts.CompatibleEchartsJS)
30 c.JSAssets.Add("echarts-wordcloud.min.js")
31 return c
32 }
33
34 // AddSeries adds new data sets.
35 func (c *WordCloud) AddSeries(name string, data []opts.WordCloudData, options ...SeriesOpts) *WordCloud {
36 series := SingleSeries{Name: name, Type: types.ChartWordCloud, Data: data}
37 series.ConfigureSeriesOpts(options...)
38
39 // set default random color for WordCloud chart
40 if series.TextStyle == nil {
41 series.TextStyle = &opts.TextStyle{Normal: &opts.TextStyle{}}
42 }
43 if series.TextStyle.Normal.Color == "" {
44 series.TextStyle.Normal.Color = string(opts.FuncOpts(wcTextColor))
45 }
46
47 c.MultiSeries = append(c.MultiSeries, series)
48 return c
49 }
50
51 // SetGlobalOptions sets options for the WordCloud instance.
52 func (c *WordCloud) SetGlobalOptions(options ...GlobalOpts) *WordCloud {
53 c.BaseConfiguration.setBaseGlobalOptions(options...)
54 return c
55 }
56
57 // Validate validates the given configuration.
58 func (c *WordCloud) Validate() {
59 c.Assets.Validate(c.AssetsHost)
60 }