forked from go-echarts/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.go
97 lines (88 loc) 路 1.63 KB
/
tree.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package examples
import (
"io"
"os"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/components"
"github.com/go-echarts/go-echarts/v2/opts"
)
var TreeNodes = []*opts.TreeData{
{
Name: "Node1",
Children: []*opts.TreeData{
{
Name: "Chield1",
},
},
},
{
Name: "Node2",
Children: []*opts.TreeData{
{
Name: "Chield1",
},
{
Name: "Chield2",
},
{
Name: "Chield3",
},
},
},
{
Name: "Node3",
Collapsed: true,
Children: []*opts.TreeData{
{
Name: "Chield1",
},
{
Name: "Chield2",
},
{
Name: "Chield3",
},
},
},
}
var Tree = []opts.TreeData{
{
Name: "Root",
Children: TreeNodes,
},
}
func treeBase() *charts.Tree {
graph := charts.NewTree()
graph.SetGlobalOptions(
charts.WithInitializationOpts(opts.Initialization{Width: "100%", Height: "95vh"}),
charts.WithTitleOpts(opts.Title{Title: "basic tree example"}),
charts.WithTooltipOpts(opts.Tooltip{Show: false}),
)
graph.AddSeries("tree", Tree).
SetSeriesOptions(
charts.WithTreeOpts(
opts.TreeChart{
Layout: "orthogonal",
Orient: "LR",
InitialTreeDepth: -1,
Leaves: &opts.TreeLeaves{
Label: &opts.Label{Show: true, Position: "right", Color: "Black"},
},
},
),
charts.WithLabelOpts(opts.Label{Show: true, Position: "top", Color: "Black"}),
)
return graph
}
type TreeExamples struct{}
func (TreeExamples) Examples() {
page := components.NewPage()
page.AddCharts(
treeBase(),
)
f, err := os.Create("examples/html/tree.html")
if err != nil {
panic(err)
}
page.Render(io.MultiWriter(f))
}