docs: update documents
This commit is contained in:
parent
92458aece2
commit
706896737b
18 changed files with 83 additions and 18 deletions
|
|
@ -32,6 +32,7 @@ type barChart struct {
|
|||
opt *BarChartOption
|
||||
}
|
||||
|
||||
// NewBarChart returns a bar chart renderer
|
||||
func NewBarChart(p *Painter, opt BarChartOption) *barChart {
|
||||
if opt.Theme == nil {
|
||||
opt.Theme = defaultTheme
|
||||
|
|
@ -43,6 +44,7 @@ func NewBarChart(p *Painter, opt BarChartOption) *barChart {
|
|||
}
|
||||
|
||||
type BarChartOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// The font size
|
||||
Font *truetype.Font
|
||||
|
|
@ -155,7 +157,7 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
|||
if distance == 0 {
|
||||
distance = 5
|
||||
}
|
||||
text := NewValueLabelFormater(seriesNames, series.Label.Formatter)(index, item.Value, -1)
|
||||
text := NewValueLabelFormatter(seriesNames, series.Label.Formatter)(index, item.Value, -1)
|
||||
labelStyle := Style{
|
||||
FontColor: theme.GetTextColor(),
|
||||
FontSize: labelFontSize,
|
||||
|
|
|
|||
|
|
@ -35,11 +35,14 @@ const defaultStrokeWidth = 2.0
|
|||
var defaultChartWidth = 600
|
||||
var defaultChartHeight = 400
|
||||
|
||||
// SetDefaultWidth sets default width of chart
|
||||
func SetDefaultWidth(width int) {
|
||||
if width > 0 {
|
||||
defaultChartWidth = width
|
||||
}
|
||||
}
|
||||
|
||||
// SetDefaultHeight sets default height of chart
|
||||
func SetDefaultHeight(height int) {
|
||||
if height > 0 {
|
||||
defaultChartHeight = height
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ type funnelChart struct {
|
|||
opt *FunnelChartOption
|
||||
}
|
||||
|
||||
// NewFunnelSeriesList returns a series list for funnel
|
||||
func NewFunnelSeriesList(values []float64) SeriesList {
|
||||
seriesList := make(SeriesList, len(values))
|
||||
for index, value := range values {
|
||||
|
|
@ -44,6 +45,7 @@ func NewFunnelSeriesList(values []float64) SeriesList {
|
|||
return seriesList
|
||||
}
|
||||
|
||||
// NewFunnelChart returns a funnel chart renderer
|
||||
func NewFunnelChart(p *Painter, opt FunnelChartOption) *funnelChart {
|
||||
if opt.Theme == nil {
|
||||
opt.Theme = defaultTheme
|
||||
|
|
@ -55,6 +57,7 @@ func NewFunnelChart(p *Painter, opt FunnelChartOption) *funnelChart {
|
|||
}
|
||||
|
||||
type FunnelChartOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// The font size
|
||||
Font *truetype.Font
|
||||
|
|
|
|||
9
grid.go
9
grid.go
|
|
@ -28,16 +28,25 @@ type gridPainter struct {
|
|||
}
|
||||
|
||||
type GridPainterOption struct {
|
||||
// The stroke width
|
||||
StrokeWidth float64
|
||||
// The stroke color
|
||||
StrokeColor Color
|
||||
// The column of grid
|
||||
Column int
|
||||
// The row of grid
|
||||
Row int
|
||||
// Ignore first row
|
||||
IgnoreFirstRow bool
|
||||
// Ignore last row
|
||||
IgnoreLastRow bool
|
||||
// Ignore first column
|
||||
IgnoreFirstColumn bool
|
||||
// Ignore last column
|
||||
IgnoreLastColumn bool
|
||||
}
|
||||
|
||||
// NewGridPainter returns new a grid renderer
|
||||
func NewGridPainter(p *Painter, opt GridPainterOption) *gridPainter {
|
||||
return &gridPainter{
|
||||
p: p,
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ type horizontalBarChart struct {
|
|||
}
|
||||
|
||||
type HorizontalBarChartOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// The font size
|
||||
Font *truetype.Font
|
||||
|
|
@ -50,6 +51,7 @@ type HorizontalBarChartOption struct {
|
|||
Legend LegendOption
|
||||
}
|
||||
|
||||
// NewHorizontalBarChart returns a horizontal bar chart renderer
|
||||
func NewHorizontalBarChart(p *Painter, opt HorizontalBarChartOption) *horizontalBarChart {
|
||||
if opt.Theme == nil {
|
||||
opt.Theme = defaultTheme
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ const IconRect = "rect"
|
|||
const IconLineDot = "lineDot"
|
||||
|
||||
type LegendOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// Text array of legend
|
||||
Data []string
|
||||
|
|
@ -60,6 +61,7 @@ type LegendOption struct {
|
|||
Show *bool
|
||||
}
|
||||
|
||||
// NewLegendOption returns a legend option
|
||||
func NewLegendOption(labels []string, left ...string) LegendOption {
|
||||
opt := LegendOption{
|
||||
Data: labels,
|
||||
|
|
@ -70,6 +72,7 @@ func NewLegendOption(labels []string, left ...string) LegendOption {
|
|||
return opt
|
||||
}
|
||||
|
||||
// IsEmpty checks legend is empty
|
||||
func (opt *LegendOption) IsEmpty() bool {
|
||||
isEmpty := true
|
||||
for _, v := range opt.Data {
|
||||
|
|
@ -81,6 +84,7 @@ func (opt *LegendOption) IsEmpty() bool {
|
|||
return isEmpty
|
||||
}
|
||||
|
||||
// NewLegendPainter returns a legend renderer
|
||||
func NewLegendPainter(p *Painter, opt LegendOption) *legendPainter {
|
||||
return &legendPainter{
|
||||
p: p,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ type lineChart struct {
|
|||
opt *LineChartOption
|
||||
}
|
||||
|
||||
// NewLineChart returns a line chart render
|
||||
func NewLineChart(p *Painter, opt LineChartOption) *lineChart {
|
||||
if opt.Theme == nil {
|
||||
opt.Theme = defaultTheme
|
||||
|
|
@ -43,6 +44,7 @@ func NewLineChart(p *Painter, opt LineChartOption) *lineChart {
|
|||
}
|
||||
|
||||
type LineChartOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// The font size
|
||||
Font *truetype.Font
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/wcharczuk/go-chart/v2"
|
||||
)
|
||||
|
||||
// NewMarkLine returns a series mark line
|
||||
func NewMarkLine(markLineTypes ...string) SeriesMarkLine {
|
||||
data := make([]SeriesMarkData, len(markLineTypes))
|
||||
for index, t := range markLineTypes {
|
||||
|
|
@ -48,6 +49,7 @@ func (m *markLinePainter) Add(opt markLineRenderOption) {
|
|||
m.options = append(m.options, opt)
|
||||
}
|
||||
|
||||
// NewMarkLinePainter returns a mark line renderer
|
||||
func NewMarkLinePainter(p *Painter) *markLinePainter {
|
||||
return &markLinePainter{
|
||||
p: p,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||
)
|
||||
|
||||
// NewMarkPoint returns a series mark point
|
||||
func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint {
|
||||
data := make([]SeriesMarkData, len(markPointTypes))
|
||||
for index, t := range markPointTypes {
|
||||
|
|
@ -55,6 +56,7 @@ type markPointRenderOption struct {
|
|||
Points []Point
|
||||
}
|
||||
|
||||
// NewMarkPointPainter returns a mark point renderer
|
||||
func NewMarkPointPainter(p *Painter) *markPointPainter {
|
||||
return &markPointPainter{
|
||||
p: p,
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ func PainterWidthHeightOption(width, height int) PainterOption {
|
|||
}
|
||||
}
|
||||
|
||||
// NewPainter creates a new painter
|
||||
// NewPainter creates a painter
|
||||
func NewPainter(opts PainterOptions, opt ...PainterOption) (*Painter, error) {
|
||||
if opts.Width <= 0 || opts.Height <= 0 {
|
||||
return nil, errors.New("width/height can not be nil")
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ type pieChart struct {
|
|||
}
|
||||
|
||||
type PieChartOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// The font size
|
||||
Font *truetype.Font
|
||||
|
|
@ -51,6 +52,7 @@ type PieChartOption struct {
|
|||
backgroundIsFilled bool
|
||||
}
|
||||
|
||||
// NewPieChart returns a pie chart renderer
|
||||
func NewPieChart(p *Painter, opt PieChartOption) *pieChart {
|
||||
if opt.Theme == nil {
|
||||
opt.Theme = defaultTheme
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ type RadarIndicator struct {
|
|||
}
|
||||
|
||||
type RadarChartOption struct {
|
||||
// The theme
|
||||
Theme ColorPalette
|
||||
// The font size
|
||||
Font *truetype.Font
|
||||
|
|
@ -62,6 +63,7 @@ type RadarChartOption struct {
|
|||
backgroundIsFilled bool
|
||||
}
|
||||
|
||||
// NewRadarIndicators returns a radar indicator list
|
||||
func NewRadarIndicators(names []string, values []float64) []RadarIndicator {
|
||||
if len(names) != len(values) {
|
||||
return nil
|
||||
|
|
@ -76,6 +78,7 @@ func NewRadarIndicators(names []string, values []float64) []RadarIndicator {
|
|||
return indicators
|
||||
}
|
||||
|
||||
// NewRadarChart returns a radar chart renderer
|
||||
func NewRadarChart(p *Painter, opt RadarChartOption) *radarChart {
|
||||
if opt.Theme == nil {
|
||||
opt.Theme = defaultTheme
|
||||
|
|
|
|||
10
range.go
10
range.go
|
|
@ -37,13 +37,19 @@ type axisRange struct {
|
|||
}
|
||||
|
||||
type AxisRangeOption struct {
|
||||
// The min value of axis
|
||||
Min float64
|
||||
// The max value of axis
|
||||
Max float64
|
||||
// The size of axis
|
||||
Size int
|
||||
// Boundary gap
|
||||
Boundary bool
|
||||
// The count of divide
|
||||
DivideCount int
|
||||
}
|
||||
|
||||
// NewRange returns a axis range
|
||||
func NewRange(opt AxisRangeOption) axisRange {
|
||||
max := opt.Max
|
||||
min := opt.Min
|
||||
|
|
@ -88,6 +94,7 @@ func NewRange(opt AxisRangeOption) axisRange {
|
|||
}
|
||||
}
|
||||
|
||||
// Values returns values of range
|
||||
func (r axisRange) Values() []string {
|
||||
offset := (r.max - r.min) / float64(r.divideCount)
|
||||
values := make([]string, 0)
|
||||
|
|
@ -108,10 +115,13 @@ func (r *axisRange) getRestHeight(value float64) int {
|
|||
return r.size - r.getHeight(value)
|
||||
}
|
||||
|
||||
// GetRange returns a range of index
|
||||
func (r *axisRange) GetRange(index int) (float64, float64) {
|
||||
unit := float64(r.size) / float64(r.divideCount)
|
||||
return unit * float64(index), unit * float64(index+1)
|
||||
}
|
||||
|
||||
// AutoDivide divides the axis
|
||||
func (r *axisRange) AutoDivide() []int {
|
||||
return autoDivide(r.size, r.divideCount)
|
||||
}
|
||||
|
|
|
|||
16
series.go
16
series.go
|
|
@ -36,6 +36,7 @@ type SeriesData struct {
|
|||
Style Style
|
||||
}
|
||||
|
||||
// NewSeriesListDataFromValues returns a series list
|
||||
func NewSeriesListDataFromValues(values [][]float64, chartType ...string) SeriesList {
|
||||
seriesList := make(SeriesList, len(values))
|
||||
for index, value := range values {
|
||||
|
|
@ -44,6 +45,7 @@ func NewSeriesListDataFromValues(values [][]float64, chartType ...string) Series
|
|||
return seriesList
|
||||
}
|
||||
|
||||
// NewSeriesFromValues returns a series
|
||||
func NewSeriesFromValues(values []float64, chartType ...string) Series {
|
||||
s := Series{
|
||||
Data: NewSeriesDataFromValues(values),
|
||||
|
|
@ -54,6 +56,7 @@ func NewSeriesFromValues(values []float64, chartType ...string) Series {
|
|||
return s
|
||||
}
|
||||
|
||||
// NewSeriesDataFromValues return a series data
|
||||
func NewSeriesDataFromValues(values []float64) []SeriesData {
|
||||
data := make([]SeriesData, len(values))
|
||||
for index, value := range values {
|
||||
|
|
@ -204,13 +207,19 @@ func NewPieSeriesList(values []float64, opts ...PieSeriesOption) SeriesList {
|
|||
}
|
||||
|
||||
type seriesSummary struct {
|
||||
// The index of max value
|
||||
MaxIndex int
|
||||
// The max value
|
||||
MaxValue float64
|
||||
// The index of min value
|
||||
MinIndex int
|
||||
// The min value
|
||||
MinValue float64
|
||||
// THe average value
|
||||
AverageValue float64
|
||||
}
|
||||
|
||||
// Summary get summary of series
|
||||
func (s *Series) Summary() seriesSummary {
|
||||
minIndex := -1
|
||||
maxIndex := -1
|
||||
|
|
@ -237,6 +246,7 @@ func (s *Series) Summary() seriesSummary {
|
|||
}
|
||||
}
|
||||
|
||||
// Names returns the names of series list
|
||||
func (sl SeriesList) Names() []string {
|
||||
names := make([]string, len(sl))
|
||||
for index, s := range sl {
|
||||
|
|
@ -245,8 +255,10 @@ func (sl SeriesList) Names() []string {
|
|||
return names
|
||||
}
|
||||
|
||||
// LabelFormatter label formatter
|
||||
type LabelFormatter func(index int, value float64, percent float64) string
|
||||
|
||||
// NewPieLabelFormatter returns a pie label formatter
|
||||
func NewPieLabelFormatter(seriesNames []string, layout string) LabelFormatter {
|
||||
if len(layout) == 0 {
|
||||
layout = "{b}: {d}"
|
||||
|
|
@ -254,13 +266,15 @@ func NewPieLabelFormatter(seriesNames []string, layout string) LabelFormatter {
|
|||
return NewLabelFormatter(seriesNames, layout)
|
||||
}
|
||||
|
||||
func NewValueLabelFormater(seriesNames []string, layout string) LabelFormatter {
|
||||
// NewValueLabelFormatter returns a value formatter
|
||||
func NewValueLabelFormatter(seriesNames []string, layout string) LabelFormatter {
|
||||
if len(layout) == 0 {
|
||||
layout = "{c}"
|
||||
}
|
||||
return NewLabelFormatter(seriesNames, layout)
|
||||
}
|
||||
|
||||
// NewLabelFormatter returns a label formaatter
|
||||
func NewLabelFormatter(seriesNames []string, layout string) LabelFormatter {
|
||||
return func(index int, value, percent float64) string {
|
||||
// 如果无percent的则设置为<0
|
||||
|
|
|
|||
1
theme.go
1
theme.go
|
|
@ -220,6 +220,7 @@ func init() {
|
|||
SetDefaultTheme(ThemeLight)
|
||||
}
|
||||
|
||||
// SetDefaultTheme sets default theme
|
||||
func SetDefaultTheme(name string) {
|
||||
defaultTheme = NewTheme(name)
|
||||
}
|
||||
|
|
|
|||
1
title.go
1
title.go
|
|
@ -84,6 +84,7 @@ type titlePainter struct {
|
|||
opt *TitleOption
|
||||
}
|
||||
|
||||
// NewTitlePainter returns a title renderer
|
||||
func NewTitlePainter(p *Painter, opt TitleOption) *titlePainter {
|
||||
return &titlePainter{
|
||||
p: p,
|
||||
|
|
|
|||
2
xaxis.go
2
xaxis.go
|
|
@ -53,6 +53,7 @@ type XAxisOption struct {
|
|||
|
||||
const defaultXAxisHeight = 30
|
||||
|
||||
// NewXAxisOption returns a x axis option
|
||||
func NewXAxisOption(data []string, boundaryGap ...*bool) XAxisOption {
|
||||
opt := XAxisOption{
|
||||
Data: data,
|
||||
|
|
@ -89,6 +90,7 @@ func (opt *XAxisOption) ToAxisOption() AxisOption {
|
|||
return axisOpt
|
||||
}
|
||||
|
||||
// NewBottomXAxis returns a bottom x axis renderer
|
||||
func NewBottomXAxis(p *Painter, opt XAxisOption) *axisPainter {
|
||||
return NewAxisPainter(p, opt.ToAxisOption())
|
||||
}
|
||||
|
|
|
|||
3
yaxis.go
3
yaxis.go
|
|
@ -50,6 +50,7 @@ type YAxisOption struct {
|
|||
isCategoryAxis bool
|
||||
}
|
||||
|
||||
// NewYAxisOptions returns a y axis option
|
||||
func NewYAxisOptions(data []string, others ...[]string) []YAxisOption {
|
||||
arr := [][]string{
|
||||
data,
|
||||
|
|
@ -95,6 +96,7 @@ func (opt *YAxisOption) ToAxisOption() AxisOption {
|
|||
return axisOpt
|
||||
}
|
||||
|
||||
// NewLeftYAxis returns a left y axis renderer
|
||||
func NewLeftYAxis(p *Painter, opt YAxisOption) *axisPainter {
|
||||
p = p.Child(PainterPaddingOption(Box{
|
||||
Bottom: defaultXAxisHeight,
|
||||
|
|
@ -102,6 +104,7 @@ func NewLeftYAxis(p *Painter, opt YAxisOption) *axisPainter {
|
|||
return NewAxisPainter(p, opt.ToAxisOption())
|
||||
}
|
||||
|
||||
// NewRightYAxis returns a right y axis renderer
|
||||
func NewRightYAxis(p *Painter, opt YAxisOption) *axisPainter {
|
||||
p = p.Child(PainterPaddingOption(Box{
|
||||
Bottom: defaultXAxisHeight,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue