Debian Codegraph @

charts/graph.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 // Graph represents a graph chart.
10 type Graph struct {
11 BaseConfiguration
12 }
13
14 // Type returns the chart type.
15 func (*Graph) Type() string { return types.ChartGraph }
16
17 // NewGraph creates a new graph chart.
18 func NewGraph() *Graph {
19 chart := new(Graph)
20 chart.initBaseConfiguration()
21 chart.Renderer = render.NewChartRender(chart, chart.Validate)
22 return chart
23 }
24
25 // AddSeries adds the new series.
26 func (c *Graph) AddSeries(name string, nodes []opts.GraphNode, links []opts.GraphLink, options ...SeriesOpts) *Graph {
27 series := SingleSeries{Name: name, Type: types.ChartGraph, Links: links, Data: nodes}
28 series.ConfigureSeriesOpts(options...)
29 c.MultiSeries = append(c.MultiSeries, series)
30 return c
31 }
32
33 // SetGlobalOptions sets options for the Graph instance.
34 func (c *Graph) SetGlobalOptions(options ...GlobalOpts) *Graph {
35 c.BaseConfiguration.setBaseGlobalOptions(options...)
36 return c
37 }
38
39 // Validate validates the given configuration.
40 func (c *Graph) Validate() {
41 // If there is no layout setting, default layout is set to "force".
42 for i := 0; i < len(c.MultiSeries); i++ {
43 if c.MultiSeries[i].Layout == "" {
44 c.MultiSeries[i].Layout = "force"
45 }
46 }
47 c.Assets.Validate(c.AssetsHost)
48 }