forked from go-echarts/go-echarts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sankey.go
63 lines (53 loc) · 1.74 KB
/
sankey.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
60
61
62
63
package charts
import (
"io"
)
// Sankey represents a sankey chart.
type Sankey struct {
BaseOpts
Series
}
// SankeyLink represents relationship between two data nodes.
type SankeyLink struct {
// 边的源节点名称的字符串,也支持使用数字表示源节点的索引
Source interface{} `json:"source,omitempty"`
// 边的目标节点名称的字符串,也支持使用数字表示源节点的索引
Target interface{} `json:"target,omitempty"`
// 边的数值,可以在力引导布局中用于映射到边的长度
Value float32 `json:"value,omitempty"`
}
// SankeyNode represents a data node.
type SankeyNode struct {
// 数据项名称
Name string `json:"name,omitempty"`
// 数据项值
Value string `json:"value,omitempty"`
}
func (Sankey) chartType() string { return ChartType.Sankey }
// NewSankey creates a new sankey chart.
func NewSankey(routers ...RouterOpts) *Sankey {
chart := new(Sankey)
chart.initBaseOpts(routers...)
return chart
}
// Add adds new data sets.
func (c *Sankey) Add(name string, nodes []SankeyNode, links []SankeyLink, options ...seriesOptser) *Sankey {
series := singleSeries{Name: name, Type: ChartType.Sankey, Data: nodes, Links: links}
series.setSingleSeriesOpts(options...)
c.Series = append(c.Series, series)
return c
}
// SetGlobalOptions sets options for the Sankey instance.
func (c *Sankey) SetGlobalOptions(options ...globalOptser) *Sankey {
c.BaseOpts.setBaseGlobalOptions(options...)
return c
}
func (c *Sankey) validateOpts() {
c.validateAssets(c.AssetsHost)
}
// Render renders the chart and writes the output to given writers.
func (c *Sankey) Render(w ...io.Writer) error {
c.insertSeriesColors(c.appendColor)
c.validateOpts()
return renderToWriter(c, "chart", []string{}, w...)
}