Skip to content

Commit

Permalink
update: series scatter refactor (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Feb 2, 2024
1 parent 89e6073 commit bc67754
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 43 deletions.
14 changes: 9 additions & 5 deletions charts/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type SingleSeries struct {
// Rectangular charts
// Line | Bar
Stack string `json:"stack,omitempty"`
// Line | Bar
// Line | Bar | Scatter
XAxisIndex int `json:"xAxisIndex,omitempty"`
// Line | Bar
// Line | Bar | Scatter
YAxisIndex int `json:"yAxisIndex,omitempty"`

// Bar
Expand Down Expand Up @@ -51,7 +51,7 @@ type SingleSeries struct {
BarMinWidth string `json:"barMinWidth,omitempty"`
BarMaxWidth string `json:"barMaxWidth,omitempty"`

// Line | Bar | Pie
// Line | Bar | Pie | Scatter
ColorBy string `json:"colorBy,omitempty"`
// Line | Bar
PolarIndex int `json:"polarIndex,omitempty"`
Expand All @@ -63,7 +63,7 @@ type SingleSeries struct {
ConnectNulls types.Bool `json:"connectNulls,omitempty"`
// Line
ShowSymbol types.Bool `json:"showSymbol,omitempty"`
// Line
// Line | Scatter
Symbol string `json:"symbol,omitempty"`
Color string `json:"color,omitempty"`

Expand All @@ -73,7 +73,7 @@ type SingleSeries struct {

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

// Pie
Expand Down Expand Up @@ -340,8 +340,12 @@ func WithPieChartOpts(opt opts.PieChart) SeriesOpts {
// WithScatterChartOpts sets the ScatterChart option.
func WithScatterChartOpts(opt opts.ScatterChart) SeriesOpts {
return func(s *SingleSeries) {
s.ColorBy = opt.ColorBy
s.CoordSystem = opt.CoordSystem
s.XAxisIndex = opt.XAxisIndex
s.YAxisIndex = opt.YAxisIndex
s.Symbol = opt.Symbol
s.SymbolSize = opt.SymbolSize
s.SymbolKeepAspect = opt.SymbolKeepAspect
}
}
Expand Down
38 changes: 0 additions & 38 deletions opts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,44 +414,6 @@ type SankeyNode struct {
ItemStyle *ItemStyle `json:"itemStyle,omitempty"`
}

// ScatterChart is the option set for a scatter chart.
// https://echarts.apache.org/en/option.html#series-scatter
type ScatterChart struct {
// Index of x axis to combine with, which is useful for multiple x axes in one chart.
XAxisIndex int

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

// SymbolKeepAspect is whether to keep aspect for symbols in the form of path://.
SymbolKeepAspect types.Bool
}

// ScatterData
// https://echarts.apache.org/en/option.html#series-scatter.data
type ScatterData struct {
// Name of data item.
Name string `json:"name,omitempty"`

// Value of a single data item.
Value interface{} `json:"value,omitempty"`

// Symbol
Symbol string `json:"symbol,omitempty"`

// SymbolSize
SymbolSize int `json:"symbolSize,omitempty"`

// SymbolRotate
SymbolRotate int `json:"symbolRotate,omitempty"`

// Index of x axis to combine with, which is useful for multiple x axes in one chart.
XAxisIndex int `json:"xAxisIndex,omitempty"`

// Index of y axis to combine with, which is useful for multiple y axes in one chart.
YAxisIndex int `json:"yAxisIndex,omitempty"`
}

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

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

// ScatterChart is the option set for a scatter chart.
// https://echarts.apache.org/en/option.html#series-scatter
type ScatterChart 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 x axis to combine with, which is useful for multiple y axes in one chart.
YAxisIndex int

// Icon types provided by ECharts includes
// 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none'
// Full documentation: https://echarts.apache.org/en/option.html#series-line.symbol
Symbol string

// symbol size. It can be set to single numbers like 10, or use an array to represent width and height. For example, [20, 10] means symbol width is 20, and height is10.
// Full documentation: https://echarts.apache.org/en/option.html#series-line.symbolSize
SymbolSize interface{}

// SymbolKeepAspect is whether to keep aspect for symbols in the form of path://.
SymbolKeepAspect types.Bool
}

// ScatterData
// https://echarts.apache.org/en/option.html#series-scatter.data
type ScatterData struct {
// Name of data item.
Name string `json:"name,omitempty"`

// Value of a single data item.
Value interface{} `json:"value,omitempty"`

// Symbol
Symbol string `json:"symbol,omitempty"`

// SymbolSize
SymbolSize int `json:"symbolSize,omitempty"`

// SymbolRotate
SymbolRotate int `json:"symbolRotate,omitempty"`

// Index of x axis to combine with, which is useful for multiple x axes in one chart.
XAxisIndex int `json:"xAxisIndex,omitempty"`

// Index of y axis to combine with, which is useful for multiple y axes in one chart.
YAxisIndex int `json:"yAxisIndex,omitempty"`
}

0 comments on commit bc67754

Please sign in to comment.