refactor: add index to series
This commit is contained in:
parent
5ccc497ad3
commit
445a781b04
2 changed files with 12 additions and 8 deletions
14
chart.go
14
chart.go
|
|
@ -46,6 +46,7 @@ type Point struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Series struct {
|
type Series struct {
|
||||||
|
index int
|
||||||
Type string
|
Type string
|
||||||
Data []SeriesData
|
Data []SeriesData
|
||||||
YAxisIndex int
|
YAxisIndex int
|
||||||
|
|
@ -160,11 +161,10 @@ func (r Range) Values() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type basicRenderResult struct {
|
type basicRenderResult struct {
|
||||||
xRange *Range
|
xRange *Range
|
||||||
yRange *Range
|
yRange *Range
|
||||||
d *Draw
|
d *Draw
|
||||||
titleBox chart.Box
|
titleBox chart.Box
|
||||||
seriesOffset int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChartRender(opt ChartOption) (*Draw, error) {
|
func ChartRender(opt ChartOption) (*Draw, error) {
|
||||||
|
|
@ -174,7 +174,8 @@ func ChartRender(opt ChartOption) (*Draw, error) {
|
||||||
}
|
}
|
||||||
lineSeries := make([]Series, 0)
|
lineSeries := make([]Series, 0)
|
||||||
barSeries := make([]Series, 0)
|
barSeries := make([]Series, 0)
|
||||||
for _, item := range opt.SeriesList {
|
for index, item := range opt.SeriesList {
|
||||||
|
item.index = index
|
||||||
switch item.Type {
|
switch item.Type {
|
||||||
case ChartTypeBar:
|
case ChartTypeBar:
|
||||||
barSeries = append(barSeries, item)
|
barSeries = append(barSeries, item)
|
||||||
|
|
@ -193,7 +194,6 @@ func ChartRender(opt ChartOption) (*Draw, error) {
|
||||||
if len(lineSeries) != 0 {
|
if len(lineSeries) != 0 {
|
||||||
o := opt
|
o := opt
|
||||||
o.SeriesList = lineSeries
|
o.SeriesList = lineSeries
|
||||||
result.seriesOffset = len(barSeries)
|
|
||||||
_, err = lineChartRender(o, result)
|
_, err = lineChartRender(o, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,11 @@ func lineChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error)
|
||||||
Y: y,
|
Y: y,
|
||||||
X: xRange.getWidth(float64(j)),
|
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
|
dotFillColor := drawing.ColorWhite
|
||||||
if theme.IsDark() {
|
if theme.IsDark() {
|
||||||
dotFillColor = seriesColor
|
dotFillColor = seriesColor
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue