forked from go-echarts/go-echarts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordcloud.go
executable file
路59 lines (49 loc) 路 1.57 KB
/
wordcloud.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
58
59
package charts
import (
"github.com/KiVirgil/go-echarts/v2/opts"
"github.com/KiVirgil/go-echarts/v2/render"
"github.com/KiVirgil/go-echarts/v2/types"
)
// WordCloud represents a word cloud chart.
type WordCloud struct {
BaseConfiguration
}
// Type returns the chart type.
func (WordCloud) Type() string { return types.ChartWordCloud }
var wcTextColor = `function () {
return 'rgb(' + [
Math.round(Math.random() * 160),
Math.round(Math.random() * 160),
Math.round(Math.random() * 160)].join(',') + ')';
}`
// NewWordCloud creates a new word cloud chart.
func NewWordCloud() *WordCloud {
c := &WordCloud{}
c.initBaseConfiguration()
c.Renderer = render.NewChartRender(c, c.Validate)
c.JSAssets.Add("echarts-wordcloud.min.js")
return c
}
// AddSeries adds new data sets.
func (c *WordCloud) AddSeries(name string, data []opts.WordCloudData, options ...SeriesOpts) *WordCloud {
series := SingleSeries{Name: name, Type: types.ChartWordCloud, Data: data}
series.configureSeriesOpts(options...)
// set default random color for WordCloud chart
if series.TextStyle == nil {
series.TextStyle = &opts.TextStyle{Normal: &opts.TextStyle{}}
}
if series.TextStyle.Normal.Color == "" {
series.TextStyle.Normal.Color = opts.FuncOpts(wcTextColor)
}
c.MultiSeries = append(c.MultiSeries, series)
return c
}
// SetGlobalOptions sets options for the WordCloud instance.
func (c *WordCloud) SetGlobalOptions(options ...GlobalOpts) *WordCloud {
c.BaseConfiguration.setBaseGlobalOptions(options...)
return c
}
// Validate
func (c *WordCloud) Validate() {
c.Assets.Validate(c.AssetsHost)
}