feat: support line chart render function
This commit is contained in:
parent
b394e1b49f
commit
c4045cfbbe
11 changed files with 1012 additions and 46 deletions
88
xaxis.go
Normal file
88
xaxis.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// MIT License
|
||||
|
||||
// Copyright (c) 2022 Tree Xie
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
package charts
|
||||
|
||||
import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
)
|
||||
|
||||
type XAxisOption struct {
|
||||
// The font of x axis
|
||||
Font *truetype.Font
|
||||
// The boundary gap on both sides of a coordinate axis.
|
||||
// Nil or *true means the center part of two axis ticks
|
||||
BoundaryGap *bool
|
||||
// The data value of x axis
|
||||
Data []string
|
||||
// The theme of chart
|
||||
Theme ColorPalette
|
||||
// The font size of x axis label
|
||||
FontSize float64
|
||||
// Hidden x axis
|
||||
Hidden bool
|
||||
// Number of segments that the axis is split into. Note that this number serves only as a recommendation.
|
||||
SplitNumber int
|
||||
// The position of axis, it can be 'top' or 'bottom'
|
||||
Position string
|
||||
// The line color of axis
|
||||
StrokeColor Color
|
||||
// The color of label
|
||||
FontColor Color
|
||||
}
|
||||
|
||||
const defaultXAxisHeight = 30
|
||||
|
||||
func NewXAxisOption(data []string, boundaryGap ...*bool) XAxisOption {
|
||||
opt := XAxisOption{
|
||||
Data: data,
|
||||
}
|
||||
if len(boundaryGap) != 0 {
|
||||
opt.BoundaryGap = boundaryGap[0]
|
||||
}
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *XAxisOption) ToAxisPainterOption() AxisPainterOption {
|
||||
position := PositionBottom
|
||||
if opt.Position == PositionTop {
|
||||
position = PositionTop
|
||||
}
|
||||
return AxisPainterOption{
|
||||
Theme: opt.Theme,
|
||||
Data: opt.Data,
|
||||
BoundaryGap: opt.BoundaryGap,
|
||||
Position: position,
|
||||
SplitNumber: opt.SplitNumber,
|
||||
StrokeColor: opt.StrokeColor,
|
||||
FontSize: opt.FontSize,
|
||||
Font: opt.Font,
|
||||
FontColor: opt.FontColor,
|
||||
}
|
||||
}
|
||||
|
||||
func NewBottomXAxis(p *Painter, opt XAxisOption) *axisPainter {
|
||||
p = p.Child(PainterPaddingOption(Box{
|
||||
Top: p.Height() - defaultXAxisHeight,
|
||||
}))
|
||||
return NewAxisPainter(p, opt.ToAxisPainterOption())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue