Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: basic sunburst chart #158

Merged
merged 4 commits into from Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions charts/series.go
Expand Up @@ -52,12 +52,27 @@ type SingleSeries struct {
SizeRange []float32 `json:"sizeRange,omitempty"`
RotationRange []float32 `json:"rotationRange,omitempty"`

// Sunburst
NodeClick string `json:"nodeClick,omitempty"`
Sort string `json:"sort,omitempty"`
RenderLabelForZeroData bool `json:"renderLabelForZeroData"`
SelectedMode bool `json:"selectedMode"`
Animation bool `json:"animation"`
AnimationThreshold int `json:"animationThreshold,omitempty"`
AnimationDuration int `json:"animationDuration,omitempty"`
AnimationEasing string `json:"animationEasing,omitempty"`
AnimationDelay int `json:"animationDelay,omitempty"`
AnimationDurationUpdate int `json:"animationDurationUpdate,omitempty"`
AnimationEasingUpdate string `json:"animationEasingUpdate,omitempty"`
AnimationDelayUpdate int `json:"animationDelayUpdate,omitempty"`

// series data
Data interface{} `json:"data"`

// series options
*opts.ItemStyle `json:"itemStyle,omitempty"`
*opts.Label `json:"label,omitempty"`
*opts.LabelLine `json:"labelLine,omitempty"`
*opts.Emphasis `json:"emphasis,omitempty"`
*opts.MarkLines `json:"markLine,omitempty"`
*opts.MarkPoints `json:"markPoint,omitempty"`
Expand Down Expand Up @@ -124,6 +139,23 @@ func WithBarChartOpts(opt opts.BarChart) SeriesOpts {
}
}

func WithSunburstOpts(opt opts.SunburstChart) SeriesOpts {
return func(s *SingleSeries) {
s.NodeClick = opt.NodeClick
s.Sort = opt.Sort
s.RenderLabelForZeroData = opt.RenderLabelForZeroData
s.SelectedMode = opt.SelectedMode
s.Animation = opt.Animation
s.AnimationThreshold = opt.AnimationThreshold
s.AnimationDuration = opt.AnimationDuration
s.AnimationEasing = opt.AnimationEasing
s.AnimationDelay = opt.AnimationDelay
s.AnimationDurationUpdate = opt.AnimationDurationUpdate
s.AnimationEasingUpdate = opt.AnimationEasingUpdate
s.AnimationDelayUpdate = opt.AnimationDelayUpdate
}
}

// WithGraphChartOpts
func WithGraphChartOpts(opt opts.GraphChart) SeriesOpts {
return func(s *SingleSeries) {
Expand Down
35 changes: 35 additions & 0 deletions charts/sunburst.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"
)

// Sunburst represents a sunburst chart.
type Sunburst struct {
RectChart
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

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

// Validate validates the given configuration.
func (c *Sunburst) Validate() {
c.Assets.Validate(c.AssetsHost)
}
22 changes: 22 additions & 0 deletions opts/charts.go
Expand Up @@ -30,6 +30,21 @@ type BarChart struct {
YAxisIndex int
}

type SunburstChart struct {
NodeClick string `json:"nodeClick,omitempty"`
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
Sort string `json:"sort,omitempty"`
RenderLabelForZeroData bool `json:"renderLabelForZeroData"`
SelectedMode bool `json:"selectedMode"`
Animation bool `json:"animation"`
AnimationThreshold int `json:"animationThreshold,omitempty"`
AnimationDuration int `json:"animationDuration,omitempty"`
AnimationEasing string `json:"animationEasing,omitempty"`
AnimationDelay int `json:"animationDelay,omitempty"`
AnimationDurationUpdate int `json:"animationDurationUpdate,omitempty"`
AnimationEasingUpdate string `json:"animationEasingUpdate,omitempty"`
AnimationDelayUpdate int `json:"animationDelayUpdate,omitempty"`
}

// BarData
// https://echarts.apache.org/en/option.html#series-bar.data
type BarData struct {
Expand Down Expand Up @@ -511,3 +526,10 @@ type Chart3DData struct {
// The style setting of the text label in a single bar.
Label *Label `json:"label,omitempty"`
}

// SunBurstData data
type SunBurstData struct {
Name string `json:"name,omitempty"`
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
Value float64 `json:"value,omitempty"`
Children []*SunBurstData `json:"children,omitempty"`
}
25 changes: 18 additions & 7 deletions opts/global.go
Expand Up @@ -456,6 +456,13 @@ type AxisLabel struct {
// Set this to false to prevent the axis label from appearing.
Show bool `json:"show,omitempty"`

// Interval of Axis label, which is available in category axis.
// It uses a strategy that labels do not overlap by default.
// You may set it to be 0 to display all labels compulsively.
// If it is set to be 1, it means that labels are shown once after one label.
// And if it is set to be 2, it means labels are shown once after two labels, and so on.
Interval string `json:"interval,omitempty"`

// Set this to true so the axis labels face the inside direction.
Inside bool `json:"inside,omitempty"`

Expand All @@ -466,13 +473,6 @@ type AxisLabel struct {
// The margin between the axis label and the axis line.
Margin float64 `json:"margin,omitempty"`

// Interval of Axis label, which is available in category axis.
// It uses a strategy that labels do not overlap by default.
// You may set it to be 0 to display all labels compulsively.
// If it is set to be 1, it means that labels are shown once after one label.
// And if it is set to be 2, it means labels are shown once after two labels, and so on.
Interval string `json:"interval,omitempty"`

// Formatter of axis label, which supports string template and callback function.
//
// Example:
Expand All @@ -494,6 +494,9 @@ type AxisLabel struct {
//}
Formatter string `json:"formatter,omitempty"`

ShowMinLabel bool `json:"showMinLabel"`
ShowMaxLabel bool `json:"showMaxLabel"`

// Color of axis label is set to be axisLine.lineStyle.color by default. Callback function is supported,
// in the following format:
//
Expand All @@ -506,6 +509,14 @@ type AxisLabel struct {
// }
// }
Color string `json:"color,omitempty"`

FontStyle string `json:"fontStyle,omitempty"`
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
FontWeight string `json:"fontWeight,omitempty"`
FontFamily string `json:"fontFamily,omitempty"`
FontSize string `json:"fontSize,omitempty"`
Align string `json:"align,omitempty"`
VerticalAlign string `json:"verticalAlign,omitempty"`
LineHeight string `json:"lineHeight,omitempty"`
}

// XAxis is the option set for X axis.
Expand Down
11 changes: 10 additions & 1 deletion opts/series.go
Expand Up @@ -6,7 +6,7 @@ import "fmt"
// https://echarts.apache.org/en/option.html#series-line.label
type Label struct {
// Whether to show label.
Show bool `json:"show,omitempty"`
Show bool `json:"show"`

// Color is the text color.
// If set as "auto", the color will assigned as visual color, such as series color.
Expand Down Expand Up @@ -48,6 +48,15 @@ type Label struct {
Formatter string `json:"formatter,omitempty"`
}

type LabelLine struct {
Show bool `json:"show"`
ShowAbove bool `json:"showAbove"`
Length2 float64 `json:"length2,omitempty"`
Smooth bool `json:"smooth"`
MinTurnAngle float64 `json:"minTurnAngle,omitempty"`
LineStyle
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
}

// Emphasis is the style when it is highlighted, like being hovered by mouse, or highlighted via legend connect.
type Emphasis struct {
// the emphasis style of label
Expand Down
1 change: 1 addition & 0 deletions types/charts.go
Expand Up @@ -26,4 +26,5 @@ const (
ChartSurface3D = "surface"
ChartThemeRiver = "themeRiver"
ChartWordCloud = "wordCloud"
Sunburst = "sunburst"
susiwen8 marked this conversation as resolved.
Show resolved Hide resolved
)