Skip to content

Commit

Permalink
update: series bar refactor (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Jan 30, 2024
1 parent fe4f352 commit 51641ea
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 49 deletions.
33 changes: 19 additions & 14 deletions charts/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ type SingleSeries struct {
Type string `json:"type,omitempty"`

// Rectangular charts
// Line
// Line | Bar
Stack string `json:"stack,omitempty"`
// Line
// Line | Bar
XAxisIndex int `json:"xAxisIndex,omitempty"`
// Line
// Line | Bar
YAxisIndex int `json:"yAxisIndex,omitempty"`

// Bar
BarGap string `json:"barGap,omitempty"`
BarCategoryGap string `json:"barCategoryGap,omitempty"`
BarGap string `json:"barGap,omitempty"`
// Bar
BarCategoryGap string `json:"barCategoryGap,omitempty"`
// Bar
ShowBackground types.Bool `json:"showBackground,omitempty"`
RoundCap types.Bool `json:"roundCap,omitempty"`
// Bar
RoundCap types.Bool `json:"roundCap,omitempty"`

// Bar3D
Shading string `json:"shading,omitempty"`
Expand All @@ -48,9 +51,9 @@ type SingleSeries struct {
BarMinWidth string `json:"barMinWidth,omitempty"`
BarMaxWidth string `json:"barMaxWidth,omitempty"`

// Line
// Line | Bar
ColorBy string `json:"colorBy,omitempty"`
// Line
// Line | Bar
PolarIndex int `json:"polarIndex,omitempty"`
// Line
Step interface{} `json:"step,omitempty"`
Expand All @@ -70,7 +73,7 @@ type SingleSeries struct {

// Map
MapType string `json:"map,omitempty"`
// Map | Line
// Map | Line | Bar
CoordSystem string `json:"coordinateSystem,omitempty"`

// Pie
Expand Down Expand Up @@ -238,14 +241,16 @@ func WithCircularStyleOpts(opt opts.CircularStyle) SeriesOpts {
// WithBarChartOpts sets the BarChart option.
func WithBarChartOpts(opt opts.BarChart) SeriesOpts {
return func(s *SingleSeries) {
s.Stack = opt.Stack
s.BarGap = opt.BarGap
s.BarCategoryGap = opt.BarCategoryGap
s.ColorBy = opt.ColorBy
s.CoordSystem = opt.CoordSystem
s.XAxisIndex = opt.XAxisIndex
s.YAxisIndex = opt.YAxisIndex
s.ShowBackground = opt.ShowBackground
s.PolarIndex = opt.PolarIndex
s.RoundCap = opt.RoundCap
s.CoordSystem = opt.CoordSystem
s.ShowBackground = opt.ShowBackground
s.Stack = opt.Stack
s.BarGap = opt.BarGap
s.BarCategoryGap = opt.BarCategoryGap
}
}

Expand Down
35 changes: 0 additions & 35 deletions opts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,6 @@ package opts

import "github.com/go-echarts/go-echarts/v2/types"

// BarChart
// https://echarts.apache.org/en/option.html#series-bar
type BarChart struct {
Type string
// Name of stack. On the same category axis, the series with the
// same stack name would be put on top of each other.
Stack string

// The gap between bars between different series, is a percent value like '30%',
// which means 30% of the bar width.
// Set barGap as '-100%' can overlap bars that belong to different series,
// which is useful when putting a series of bar as background.
// In a single coordinate system, this attribute is shared by multiple 'bar' series.
// This attribute should be set on the last 'bar' series in the coordinate system,
// then it will be adopted by all 'bar' series in the coordinate system.
BarGap string

// The bar gap of a single series, defaults to be 20% of the category gap,
// can be set as a fixed value.
// In a single coordinate system, this attribute is shared by multiple 'bar' series.
// This attribute should be set on the last 'bar' series in the coordinate system,
// then it will be adopted by all 'bar' series in the coordinate system.
BarCategoryGap string

// Index of x axis to combine with, which is useful for multiple x axes in one chart.
XAxisIndex int

// Index of y axis to combine with, which is useful for multiple y axes in one chart.
YAxisIndex int

ShowBackground types.Bool
RoundCap types.Bool
CoordSystem string
}

// SunburstChart
// https://echarts.apache.org/en/option.html#series-sunburst
type SunburstChart struct {
Expand Down
54 changes: 54 additions & 0 deletions opts/series_bar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package opts

import "github.com/go-echarts/go-echarts/v2/types"

// BarChart
// https://echarts.apache.org/en/option.html#series-bar
type BarChart struct {
// ColorBy The policy to take color from option.color. Valid values:
// 'series': assigns the colors in the palette by series, so that all data in the same series are in the same color;
// 'data': assigns colors in the palette according to data items, with each data item using a different color.
ColorBy string

// CoordinateSystem The coordinate used in the series, whose options are:
//'cartesian2d' Use a two-dimensional rectangular coordinate (also known as Cartesian coordinate), with xAxisIndex and
// yAxisIndex to assign the corresponding axis component.
//
// 'polar' Use polar coordinates, with polarIndex to assign the corresponding polar coordinate component.
CoordSystem string

// Index of x axis to combine with, which is useful for multiple x axes in one chart.
XAxisIndex int

// Index of y axis to combine with, which is useful for multiple y axes in one chart.
YAxisIndex int

// Index of polar coordinate to combine with, which is useful for multiple polar axes in one chart.
PolarIndex int

// Whether to add round caps at the end of the bar sectors. Valid only for bar series on polar coordinates.
RoundCap types.Bool

// Whether to show background behind each bar. Use backgroundStyle to set background style.
ShowBackground types.Bool

// Name of stack. On the same category axis, the series with the
// same stack name would be put on top of each other.
Stack string

// The gap between bars between different series, is a percent value like '30%',
// which means 30% of the bar width.
// Set barGap as '-100%' can overlap bars that belong to different series,
// which is useful when putting a series of bar as background.
// In a single coordinate system, this attribute is shared by multiple 'bar' series.
// This attribute should be set on the last 'bar' series in the coordinate system,
// then it will be adopted by all 'bar' series in the coordinate system.
BarGap string

// The bar gap of a single series, defaults to be 20% of the category gap,
// can be set as a fixed value.
// In a single coordinate system, this attribute is shared by multiple 'bar' series.
// This attribute should be set on the last 'bar' series in the coordinate system,
// then it will be adopted by all 'bar' series in the coordinate system.
BarCategoryGap string
}

0 comments on commit 51641ea

Please sign in to comment.