refactor: add index to series

This commit is contained in:
vicanso 2022-02-03 08:45:55 +08:00
parent 5ccc497ad3
commit 445a781b04
2 changed files with 12 additions and 8 deletions

View file

@ -46,6 +46,7 @@ type Point struct {
}
type Series struct {
index int
Type string
Data []SeriesData
YAxisIndex int
@ -164,7 +165,6 @@ type basicRenderResult struct {
yRange *Range
d *Draw
titleBox chart.Box
seriesOffset int
}
func ChartRender(opt ChartOption) (*Draw, error) {
@ -174,7 +174,8 @@ func ChartRender(opt ChartOption) (*Draw, error) {
}
lineSeries := make([]Series, 0)
barSeries := make([]Series, 0)
for _, item := range opt.SeriesList {
for index, item := range opt.SeriesList {
item.index = index
switch item.Type {
case ChartTypeBar:
barSeries = append(barSeries, item)
@ -193,7 +194,6 @@ func ChartRender(opt ChartOption) (*Draw, error) {
if len(lineSeries) != 0 {
o := opt
o.SeriesList = lineSeries
result.seriesOffset = len(barSeries)
_, err = lineChartRender(o, result)
if err != nil {
return nil, err

View file

@ -51,7 +51,11 @@ func lineChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error)
Y: y,
X: xRange.getWidth(float64(j)),
})
seriesColor := theme.GetSeriesColor(i + result.seriesOffset)
index := series.index
if index == 0 {
index = i
}
seriesColor := theme.GetSeriesColor(index)
dotFillColor := drawing.ColorWhite
if theme.IsDark() {
dotFillColor = seriesColor