diff --git a/charts/series.go b/charts/series.go index 2a2d5908..8250d71c 100644 --- a/charts/series.go +++ b/charts/series.go @@ -54,12 +54,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"` @@ -130,6 +145,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) { diff --git a/charts/sunburst.go b/charts/sunburst.go new file mode 100644 index 00000000..9f92dd6e --- /dev/null +++ b/charts/sunburst.go @@ -0,0 +1,42 @@ +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 { + BaseConfiguration +} + +// Type returns the chart type. +func (Sunburst) Type() string { return types.ChartSunburst } + +// NewSunburst creates a new sunburst chart instance. +func NewSunburst() *Sunburst { + c := &Sunburst{} + c.initBaseConfiguration() + c.Renderer = render.NewChartRender(c, c.Validate) + return c +} + +// AddSeries adds new data sets. +func (c *Sunburst) AddSeries(name string, data []opts.SunBurstData, options ...SeriesOpts) *Sunburst { + series := SingleSeries{Name: name, Type: types.ChartSunburst, Data: data} + series.configureSeriesOpts(options...) + c.MultiSeries = append(c.MultiSeries, series) + return c +} + +// SetGlobalOptions sets options for the Pie instance. +func (c *Sunburst) SetGlobalOptions(options ...GlobalOpts) *Sunburst { + c.BaseConfiguration.setBaseGlobalOptions(options...) + return c +} + +// Validate validates the given configuration. +func (c *Sunburst) Validate() { + c.Assets.Validate(c.AssetsHost) +} diff --git a/opts/charts.go b/opts/charts.go index 769a6440..d24bc03d 100644 --- a/opts/charts.go +++ b/opts/charts.go @@ -35,6 +35,35 @@ type BarChart struct { CoordSystem string } +// SunburstChart +// https://echarts.apache.org/en/option.html#series-sunburst +type SunburstChart struct { + // The action of clicking a sector + NodeClick string `json:"nodeClick,omitempty"` + // Sorting method that sectors use based on value + Sort string `json:"sort,omitempty"` + // If there is no name, whether need to render it. + RenderLabelForZeroData bool `json:"renderLabelForZeroData"` + // Selected mode + SelectedMode bool `json:"selectedMode"` + // Whether to enable animation. + Animation bool `json:"animation"` + // Whether to set graphic number threshold to animation + AnimationThreshold int `json:"animationThreshold,omitempty"` + // Duration of the first animation + AnimationDuration int `json:"animationDuration,omitempty"` + // Easing method used for the first animation + AnimationEasing string `json:"animationEasing,omitempty"` + // Delay before updating the first animation + AnimationDelay int `json:"animationDelay,omitempty"` + // Time for animation to complete + AnimationDurationUpdate int `json:"animationDurationUpdate,omitempty"` + // Easing method used for animation. + AnimationEasingUpdate string `json:"animationEasingUpdate,omitempty"` + // Delay before updating animation + AnimationDelayUpdate int `json:"animationDelayUpdate,omitempty"` +} + // BarData // https://echarts.apache.org/en/option.html#series-bar.data type BarData struct { @@ -516,3 +545,13 @@ 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 of data item. + Name string `json:"name,omitempty"` + // Value of data item. + Value float64 `json:"value,omitempty"` + // sub item of data item + Children []*SunBurstData `json:"children,omitempty"` +} diff --git a/opts/global.go b/opts/global.go index 2c712818..314821ef 100644 --- a/opts/global.go +++ b/opts/global.go @@ -477,6 +477,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"` @@ -487,13 +494,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: @@ -515,6 +515,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: // @@ -527,6 +530,21 @@ type AxisLabel struct { // } // } Color string `json:"color,omitempty"` + + // axis label font style + FontStyle string `json:"fontStyle,omitempty"` + // axis label font weight + FontWeight string `json:"fontWeight,omitempty"` + // axis label font family + FontFamily string `json:"fontFamily,omitempty"` + // axis label font size + FontSize string `json:"fontSize,omitempty"` + // Horizontal alignment of axis label + Align string `json:"align,omitempty"` + // Vertical alignment of axis label + VerticalAlign string `json:"verticalAlign,omitempty"` + // Line height of the axis label + LineHeight string `json:"lineHeight,omitempty"` } // XAxis is the option set for X axis. diff --git a/opts/series.go b/opts/series.go index 220e2e93..25c33d7d 100644 --- a/opts/series.go +++ b/opts/series.go @@ -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. @@ -48,6 +48,22 @@ type Label struct { Formatter string `json:"formatter,omitempty"` } +// LabelLine Configuration of label guide line. +type LabelLine struct { + // Whether to show the label guide line. + Show bool `json:"show"` + // Whether to show the label guide line above the corresponding element. + ShowAbove bool `json:"showAbove"` + // The length of the second segment of guide line. + Length2 float64 `json:"length2,omitempty"` + // smoothness of guide line. + Smooth bool `json:"smooth"` + // Minimum turn angle between two segments of guide line + MinTurnAngle float64 `json:"minTurnAngle,omitempty"` + // The style of label line + LineStyle *LineStyle `json:"lineStyle,omitempty"` +} + // 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 diff --git a/types/charts.go b/types/charts.go index e8f2b481..1a46264d 100644 --- a/types/charts.go +++ b/types/charts.go @@ -26,4 +26,5 @@ const ( ChartSurface3D = "surface" ChartThemeRiver = "themeRiver" ChartWordCloud = "wordCloud" + ChartSunburst = "sunburst" )