added option for line chart bg fill opacity
This commit is contained in:
parent
830d4bdd21
commit
a767b3e1af
3 changed files with 10 additions and 1 deletions
|
|
@ -71,6 +71,8 @@ type ChartOption struct {
|
||||||
BarHeight int
|
BarHeight int
|
||||||
// Fill the area of line chart
|
// Fill the area of line chart
|
||||||
FillArea bool
|
FillArea bool
|
||||||
|
// background fill (alpha) opacity
|
||||||
|
Opacity uint8
|
||||||
// The child charts
|
// The child charts
|
||||||
Children []ChartOption
|
Children []ChartOption
|
||||||
// The value formatter
|
// The value formatter
|
||||||
|
|
|
||||||
|
|
@ -409,6 +409,7 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
|
||||||
SymbolShow: opt.SymbolShow,
|
SymbolShow: opt.SymbolShow,
|
||||||
StrokeWidth: opt.LineStrokeWidth,
|
StrokeWidth: opt.LineStrokeWidth,
|
||||||
FillArea: opt.FillArea,
|
FillArea: opt.FillArea,
|
||||||
|
Opacity: opt.Opacity,
|
||||||
}).render(renderResult, lineSeriesList)
|
}).render(renderResult, lineSeriesList)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,8 @@ type LineChartOption struct {
|
||||||
FillArea bool
|
FillArea bool
|
||||||
// background is filled
|
// background is filled
|
||||||
backgroundIsFilled bool
|
backgroundIsFilled bool
|
||||||
|
// background fill (alpha) opacity
|
||||||
|
Opacity uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lineChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
func (l *lineChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
||||||
|
|
@ -156,6 +158,10 @@ func (l *lineChart) render(result *defaultRenderResult, seriesList SeriesList) (
|
||||||
areaPoints := make([]Point, len(points))
|
areaPoints := make([]Point, len(points))
|
||||||
copy(areaPoints, points)
|
copy(areaPoints, points)
|
||||||
bottomY := yRange.getRestHeight(yRange.min)
|
bottomY := yRange.getRestHeight(yRange.min)
|
||||||
|
var opacity uint8 = 200
|
||||||
|
if opt.Opacity != 0 {
|
||||||
|
opacity = opt.Opacity
|
||||||
|
}
|
||||||
areaPoints = append(areaPoints, Point{
|
areaPoints = append(areaPoints, Point{
|
||||||
X: areaPoints[len(areaPoints)-1].X,
|
X: areaPoints[len(areaPoints)-1].X,
|
||||||
Y: bottomY,
|
Y: bottomY,
|
||||||
|
|
@ -164,7 +170,7 @@ func (l *lineChart) render(result *defaultRenderResult, seriesList SeriesList) (
|
||||||
Y: bottomY,
|
Y: bottomY,
|
||||||
}, areaPoints[0])
|
}, areaPoints[0])
|
||||||
seriesPainter.SetDrawingStyle(Style{
|
seriesPainter.SetDrawingStyle(Style{
|
||||||
FillColor: seriesColor.WithAlpha(200),
|
FillColor: seriesColor.WithAlpha(opacity),
|
||||||
})
|
})
|
||||||
seriesPainter.FillArea(areaPoints)
|
seriesPainter.FillArea(areaPoints)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue