Skip to content

Commit

Permalink
update: series line refactor (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Jan 30, 2024
1 parent 0456a5e commit 7eac831
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 58 deletions.
39 changes: 25 additions & 14 deletions charts/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,22 @@ type SingleSeries struct {
BarMaxWidth string `json:"barMaxWidth,omitempty"`

// Line
Step interface{} `json:"step,omitempty"`
Smooth types.Bool `json:"smooth,omitempty"`
ConnectNulls types.Bool `json:"connectNulls,omitempty"`
ShowSymbol types.Bool `json:"showSymbol,omitempty"`
Symbol string `json:"symbol,omitempty"`
Color string `json:"color,omitempty"`
ColorBy string `json:"colorBy,omitempty"`
// Line
CoordinateSystem string `json:"coordinateSystem,omitempty"`
// Line
PolarIndex int `json:"polarIndex,omitempty"`
// Line
Step interface{} `json:"step,omitempty"`
// Line
Smooth types.Bool `json:"smooth,omitempty"`
// Line
ConnectNulls types.Bool `json:"connectNulls,omitempty"`
// Line
ShowSymbol types.Bool `json:"showSymbol,omitempty"`
// Line
Symbol string `json:"symbol,omitempty"`
Color string `json:"color,omitempty"`

// Liquid
IsLiquidOutline types.Bool `json:"outline,omitempty"`
Expand Down Expand Up @@ -281,18 +291,19 @@ func WithHeatMapChartOpts(opt opts.HeatMapChart) SeriesOpts {
// WithLineChartOpts sets the LineChart option.
func WithLineChartOpts(opt opts.LineChart) SeriesOpts {
return func(s *SingleSeries) {
s.ColorBy = opt.ColorBy
s.CoordinateSystem = opt.CoordinateSystem
s.XAxisIndex = opt.XAxisIndex
s.YAxisIndex = opt.YAxisIndex
s.Stack = opt.Stack
s.Smooth = opt.Smooth
s.ShowSymbol = opt.ShowSymbol
s.PolarIndex = opt.PolarIndex
s.Symbol = opt.Symbol
s.SymbolSize = opt.SymbolSize
s.Step = opt.Step
s.XAxisIndex = opt.XAxisIndex
s.YAxisIndex = opt.YAxisIndex
s.ConnectNulls = opt.ConnectNulls
s.Color = opt.Color
s.SymbolKeepAspect = opt.SymbolKeepAspect
s.ShowSymbol = opt.ShowSymbol
s.Stack = opt.Stack
s.Smooth = opt.Smooth
s.ConnectNulls = opt.ConnectNulls
s.Step = opt.Step
}
}

Expand Down
44 changes: 0 additions & 44 deletions opts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,50 +305,6 @@ type KlineData struct {
Value interface{} `json:"value,omitempty"`
}

// LineChart is the options set for a line chart.
// https://echarts.apache.org/en/option.html#series-line
type LineChart struct {
// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other.
// The effect of the below example could be seen through stack switching of toolbox on the top right corner:
Stack string

// Whether to show as smooth curve.
// If is typed in types.Boolean, then it means whether to enable smoothing. If is
// typed in number, valued from 0 to 1, then it means smoothness. A smaller value makes it less smooth.
Smooth types.Bool

// Whether to show as a step line. It can be true, false. Or 'start', 'middle', 'end'.
// Which will configure the turn point of step line.
Step interface{}

// 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

// Whether to connect the line across null points.
ConnectNulls types.Bool

// Whether to show symbol. It would be shown during tooltip hover.
ShowSymbol types.Bool

// 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{}

// color for Line series. it affects Line series including symbols, unlike LineStyle.Color
Color string

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

// LineChart is the options set for a chandlestick chart.
// https://echarts.apache.org/en/option.html#series-candlestick
type KlineChart struct {
Expand Down
59 changes: 59 additions & 0 deletions opts/series_line.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package opts

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

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

// 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

// Whether to show symbol. It would be shown during tooltip hover.
ShowSymbol types.Bool

// If stack the value. On the same category axis, the series with the same stack name would be put on top of each other.
// The effect of the below example could be seen through stack switching of toolbox on the top right corner:
Stack string

// Whether to show as smooth curve.
// If is typed in types.Boolean, then it means whether to enable smoothing. If is
// typed in number, valued from 0 to 1, then it means smoothness. A smaller value makes it less smooth.
Smooth types.Bool

// Whether to connect the line across null points.
ConnectNulls types.Bool

// Whether to show as a step line. It can be true, false. Or 'start', 'middle', 'end'.
// Which will configure the turn point of step line.
Step interface{}
}

0 comments on commit 7eac831

Please sign in to comment.