Skip to content

Commit

Permalink
feat/tree: add tree chart type
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreZiviani committed Feb 12, 2021
1 parent bf525d1 commit fe7c36a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
35 changes: 35 additions & 0 deletions charts/tree.go
@@ -0,0 +1,35 @@
package charts

import (
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/go-echarts/go-echarts/v2/render"
"github.com/go-echarts/go-echarts/v2/types"
)

// Tree represents a Tree chart.
type Tree struct {
RectChart
}

// Type returns the chart type.
func (Tree) Type() string { return types.Tree }

// NewTree creates a new Tree chart instance.
func NewTree() *Tree {
c := &Tree{}
c.initBaseConfiguration()
c.Renderer = render.NewChartRender(c, c.Validate)
return c
}

func (c *Tree) AddSeries(name string, data []opts.TreeData, options ...SeriesOpts) *Tree {
series := SingleSeries{Name: name, Type: types.Tree, Data: data}
series.configureSeriesOpts(options...)
c.MultiSeries = append(c.MultiSeries, series)
return c
}

// Validate validates the given configuration.
func (c *Tree) Validate() {
c.Assets.Validate(c.AssetsHost)
}
10 changes: 10 additions & 0 deletions opts/charts.go
Expand Up @@ -516,3 +516,13 @@ type Chart3DData struct {
// The style setting of the text label in a single bar.
Label *Label `json:"label,omitempty"`
}

type TreeData struct {
// Name of the data item.
Name string `json:"name,omitempty"`

// Value of the data item.
Value int `json:"value,omitempty"`

Children []*TreeData `json:"children,omitempty"`
}
1 change: 1 addition & 0 deletions types/charts.go
Expand Up @@ -26,4 +26,5 @@ const (
ChartSurface3D = "surface"
ChartThemeRiver = "themeRiver"
ChartWordCloud = "wordCloud"
Tree = "tree"
)

0 comments on commit fe7c36a

Please sign in to comment.