Skip to content

Commit

Permalink
update: add options for Line chart and Candlestick chart (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: Koy ['kɔɪ] <koy@ko8e24.top>
  • Loading branch information
shmarlovsky and Koooooo-7 committed Apr 4, 2023
1 parent 55099bb commit 56edc0f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
34 changes: 31 additions & 3 deletions charts/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ type SingleSeries struct {
Draggable bool `json:"draggable,omitempty"`
FocusNodeAdjacency bool `json:"focusNodeAdjacency,omitempty"`

// KLine
BarWidth string `json:"barWidth,omitempty"`
BarMinWidth string `json:"barMinWidth,omitempty"`
BarMaxWidth string `json:"barMaxWidth,omitempty"`

// Line
Step interface{} `json:"step,omitempty"`
Smooth bool `json:"smooth"`
ConnectNulls bool `json:"connectNulls"`
ShowSymbol bool `json:"showSymbol"`
Symbol string `json:"symbol,omitempty"`
Color string `json:"color,omitempty"`

// Liquid
IsLiquidOutline bool `json:"outline,omitempty"`
Expand All @@ -52,7 +59,7 @@ type SingleSeries struct {
Radius interface{} `json:"radius,omitempty"`

// Scatter
SymbolSize float32 `json:"symbolSize,omitempty"`
SymbolSize interface{} `json:"symbolSize,omitempty"`

// Tree
Orient string `json:"orient,omitempty"`
Expand Down Expand Up @@ -228,10 +235,22 @@ func WithLineChartOpts(opt opts.LineChart) SeriesOpts {
s.Stack = opt.Stack
s.Smooth = opt.Smooth
s.ShowSymbol = opt.ShowSymbol
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
}
}

// WithLineChartOpts sets the LineChart option.
func WithKlineChartOpts(opt opts.KlineChart) SeriesOpts {
return func(s *SingleSeries) {
s.BarWidth = opt.BarWidth
s.BarMinWidth = opt.BarMinWidth
s.BarMaxWidth = opt.BarMaxWidth
}
}

Expand Down Expand Up @@ -343,7 +362,10 @@ func WithMarkLineNameCoordItemOpts(opt ...opts.MarkLineNameCoordItem) SeriesOpts
s.MarkLines = &opts.MarkLines{}
}
for _, o := range opt {
s.MarkLines.Data = append(s.MarkLines.Data, []MLNameCoord{{Name: o.Name, Coord: o.Coordinate0}, {Coord: o.Coordinate1}})
s.MarkLines.Data = append(
s.MarkLines.Data,
[]MLNameCoord{{Name: o.Name, Coord: o.Coordinate0}, {Coord: o.Coordinate1}},
)
}
}
}
Expand Down Expand Up @@ -407,7 +429,13 @@ func WithMarkAreaNameCoordItemOpts(opt ...opts.MarkAreaNameCoordItem) SeriesOpts
s.MarkAreas = &opts.MarkAreas{}
}
for _, o := range opt {
s.MarkAreas.Data = append(s.MarkAreas.Data, []MANameCoord{{Name: o.Name, ItemStyle: o.ItemStyle, Coord: o.Coordinate0}, {Coord: o.Coordinate1}})
s.MarkAreas.Data = append(
s.MarkAreas.Data,
[]MANameCoord{
{Name: o.Name, ItemStyle: o.ItemStyle, Coord: o.Coordinate0},
{Coord: o.Coordinate1},
},
)
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions opts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,31 @@ type LineChart struct {

// Whether to show symbol. It would be shown during tooltip hover.
ShowSymbol 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
}

// LineChart is the options set for a chandlestick chart.
// https://echarts.apache.org/en/option.html#series-candlestick
type KlineChart struct {
// Specify bar width. Absolute value (like 10) or percentage (like '20%', according to band width) can be used. Auto adapt by default.
BarWidth string

// Specify bar min width. Absolute value (like 10) or percentage (like '20%', according to band width) can be used. Auto adapt by default.
BarMinWidth string

// Specify bar max width. Absolute value (like 10) or percentage (like '20%', according to band width) can be used. Auto adapt by default.
BarMaxWidth string
}

// LineData
Expand Down
18 changes: 9 additions & 9 deletions opts/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ type AxisPointerLink struct {
YAxisName string `json:"yAxisName,omitempty"`
}

//Brush is an area-selecting component, with which user can select part of data from a chart to display in detail, or do calculations with them.
//https://echarts.apache.org/en/option.html#brush
// Brush is an area-selecting component, with which user can select part of data from a chart to display in detail, or do calculations with them.
// https://echarts.apache.org/en/option.html#brush
type Brush struct {

//XAxisIndex Assigns which of the xAxisIndex can use brush selecting.
Expand All @@ -397,8 +397,8 @@ type Brush struct {
OutOfBrush *BrushOutOfBrush `json:"outOfBrush,omitempty"`
}

//BrushOutOfBrush
//https://echarts.apache.org/en/option.html#brush.outOfBrush
// BrushOutOfBrush
// https://echarts.apache.org/en/option.html#brush.outOfBrush
type BrushOutOfBrush struct {
ColorAlpha float32 `json:"colorAlpha,omitempty"`
}
Expand Down Expand Up @@ -484,8 +484,8 @@ type ToolBoxFeatureSaveAsImage struct {
Title string `json:"title,omitempty"`
}

//ToolBoxFeatureBrush brush-selecting icon.
//https://echarts.apache.org/en/option.html#toolbox.feature.brush
// ToolBoxFeatureBrush brush-selecting icon.
// https://echarts.apache.org/en/option.html#toolbox.feature.brush
type ToolBoxFeatureBrush struct {

//Icons used, whose values are:
Expand Down Expand Up @@ -1453,9 +1453,9 @@ type Grid struct {
Height string `json:"height,omitempty"`
}

//Dataset brings convenience in data management separated with styles and enables data reuse by different series.
//More importantly, it enables data encoding from data to visual, which brings convenience in some scenarios.
//https://echarts.apache.org/en/option.html#dataset.id
// Dataset brings convenience in data management separated with styles and enables data reuse by different series.
// More importantly, it enables data encoding from data to visual, which brings convenience in some scenarios.
// https://echarts.apache.org/en/option.html#dataset.id
type Dataset struct {
//source
Source interface{} `json:"source"`
Expand Down

0 comments on commit 56edc0f

Please sign in to comment.