Skip to content

Commit

Permalink
update: series pie refactor (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Jan 31, 2024
1 parent 51641ea commit 4b31e0c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
14 changes: 9 additions & 5 deletions charts/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type SingleSeries struct {
BarMinWidth string `json:"barMinWidth,omitempty"`
BarMaxWidth string `json:"barMaxWidth,omitempty"`

// Line | Bar
// Line | Bar | Pie
ColorBy string `json:"colorBy,omitempty"`
// Line | Bar
PolarIndex int `json:"polarIndex,omitempty"`
Expand All @@ -73,13 +73,15 @@ type SingleSeries struct {

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

// Pie
RoseType string `json:"roseType,omitempty"`
Center interface{} `json:"center,omitempty"`
Radius interface{} `json:"radius,omitempty"`
RoseType string `json:"roseType,omitempty"`
// Pie
Center interface{} `json:"center,omitempty"`
// Pie
Radius interface{} `json:"radius,omitempty"`

// Line | Scatter
SymbolSize interface{} `json:"symbolSize,omitempty"`
Expand Down Expand Up @@ -327,6 +329,8 @@ func WithKlineChartOpts(opt opts.KlineChart) SeriesOpts {
// WithPieChartOpts sets the PieChart option.
func WithPieChartOpts(opt opts.PieChart) SeriesOpts {
return func(s *SingleSeries) {
s.ColorBy = opt.ColorBy
s.CoordSystem = opt.CoordSystem
s.RoseType = opt.RoseType
s.Center = opt.Center
s.Radius = opt.Radius
Expand Down
28 changes: 0 additions & 28 deletions opts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,34 +353,6 @@ type ParallelData struct {
Value interface{} `json:"value,omitempty"`
}

// PieChart is the option set for a pie chart.
// https://echarts.apache.org/en/option.html#series-pie
type PieChart struct {
// Whether to show as Nightingale chart, which distinguishes data through radius. There are 2 optional modes:
// * 'radius' Use central angle to show the percentage of data, radius to show data size.
// * 'area' All the sectors will share the same central angle, the data size is shown only through radiuses.
RoseType string

// Center position of Pie chart, the first of which is the horizontal position, and the second is the vertical position.
// Percentage is supported. When set in percentage, the item is relative to the container width,
// and the second item to the height.
//
// Example:
//
// Set to absolute pixel values ->> center: [400, 300]
// Set to relative percent ->> center: ['50%', '50%']
Center interface{}

// Radius of Pie chart. Value can be:
// * number: Specify outside radius directly.
// * string: For example, '20%', means that the outside radius is 20% of the viewport
// size (the little one between width and height of the chart container).
//
// Array.<number|string>: The first item specifies the inside radius, and the
// second item specifies the outside radius. Each item follows the definitions above.
Radius interface{}
}

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

// PieChart is the option set for a pie chart.
// https://echarts.apache.org/en/option.html#series-pie
type PieChart 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

// Whether to show as Nightingale chart, which distinguishes data through radius. There are 2 optional modes:
// * 'radius' Use central angle to show the percentage of data, radius to show data size.
// * 'area' All the sectors will share the same central angle, the data size is shown only through radiuses.
RoseType string

// Center position of Pie chart, the first of which is the horizontal position, and the second is the vertical position.
// Percentage is supported. When set in percentage, the item is relative to the container width,
// and the second item to the height.
//
// Example:
//
// Set to absolute pixel values ->> center: [400, 300]
// Set to relative percent ->> center: ['50%', '50%']
Center interface{}

// Radius of Pie chart. Value can be:
// * number: Specify outside radius directly.
// * string: For example, '20%', means that the outside radius is 20% of the viewport
// size (the little one between width and height of the chart container).
//
// Array.<number|string>: The first item specifies the inside radius, and the
// second item specifies the outside radius. Each item follows the definitions above.
Radius interface{}
}

0 comments on commit 4b31e0c

Please sign in to comment.