forked from go-echarts/go-echarts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.go
executable file
路46 lines (39 loc) 路 1.21 KB
/
graph.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
package charts
import (
"github.com/KiVirgil/go-echarts/v2/opts"
"github.com/KiVirgil/go-echarts/v2/types"
)
// Graph represents a graph chart.
type Graph struct {
BaseConfiguration
}
// Type returns the chart type.
func (Graph) Type() string { return types.ChartGraph }
// NewGraph creates a new graph chart.
func NewGraph() *Graph {
chart := new(Graph)
chart.initBaseConfiguration()
return chart
}
// AddSeries adds the new series.
func (c *Graph) AddSeries(name string, nodes []opts.GraphNode, links []opts.GraphLink, options ...SeriesOpts) *Graph {
series := SingleSeries{Name: name, Type: types.ChartGraph, Links: links, Data: nodes}
series.configureSeriesOpts(options...)
c.MultiSeries = append(c.MultiSeries, series)
return c
}
// SetGlobalOptions sets options for the Graph instance.
func (c *Graph) SetGlobalOptions(options ...GlobalOpts) *Graph {
c.BaseConfiguration.setBaseGlobalOptions(options...)
return c
}
// Validate validates the given configuration.
func (c *Graph) Validate() {
// If there is no layout setting, default layout is set to "force".
for i := 0; i < len(c.MultiSeries); i++ {
if c.MultiSeries[i].Layout == "" {
c.MultiSeries[i].Layout = "force"
}
}
c.Assets.Validate(c.AssetsHost)
}